learning_ai_notes/.pnpmfile.cjs
saravanakumardb1 b2d824c8c6 fix(workspace): canonicalize common-plat path to ../learning_ai_common_plat
Restores green build after the May 12 Docker/UI regression.

Root cause: pnpm-workspace.yaml referenced a sibling path
(../learning_ai/learning_ai_common_plat/...) that did not exist on
dev/CI hosts. .pnpmfile.cjs fell back to ../learning_ai_common_plat for
some packages but missed others, so @bytelyst/ui was pulled from a
stale Gitea 0.1.0 tarball with zero exports (breaking web typecheck +
26 tests) and @bytelyst/monitoring was never linked into node_modules
(breaking backend typecheck + 2 test suites).

Changes:
- pnpm-workspace.yaml now references ../learning_ai_common_plat/packages/* directly
- .pnpmfile.cjs swaps DEFAULT/LEGACY common-plat roots so the canonical
  path is the default and the older nested path is the fallback
- scripts/docker-prep.sh, scripts/local-smoke.sh, scripts/release-guard-audit.sh
  follow the same canonical-first / legacy-fallback pattern
- .github/workflows/ci.yml symlinks directly to ../learning_ai_common_plat
- pnpm-lock.yaml regenerated with @bytelyst/ui@0.1.9 and
  @bytelyst/monitoring@0.1.5 linked to the local common-plat checkout

Verified:
- pnpm run verify: backend 373/373, web 96/96, mobile 97/97
- pnpm run audit:release-guards: passes
- backend, web, mobile lint all exit 0 (advisory warnings retained)
2026-05-22 15:08:30 -07:00

96 lines
2.7 KiB
JavaScript

const fs = require('node:fs');
const path = require('node:path');
const PACKAGE_SCOPE = '@bytelyst/';
const PACKAGE_SOURCE = process.env.BYTELYST_PACKAGE_SOURCE || 'common-plat';
const DEFAULT_COMMON_PLAT_ROOT = path.resolve(__dirname, '..', 'learning_ai_common_plat');
const LEGACY_COMMON_PLAT_ROOT = path.resolve(__dirname, '..', 'learning_ai', 'learning_ai_common_plat');
const COMMON_PLAT_ROOT =
process.env.BYTELYST_COMMON_PLAT_ROOT ||
(fs.existsSync(DEFAULT_COMMON_PLAT_ROOT) ? DEFAULT_COMMON_PLAT_ROOT : LEGACY_COMMON_PLAT_ROOT);
const COMMON_PLAT_PACKAGES_ROOT = path.join(COMMON_PLAT_ROOT, 'packages');
const VERSION_CACHE = new Map();
let loggedSource = false;
function packageDirFor(name) {
return name.startsWith(PACKAGE_SCOPE) ? name.slice(PACKAGE_SCOPE.length) : null;
}
function pathIfPackageExists(rootDir, name) {
const packageDir = packageDirFor(name);
if (!packageDir) return null;
const candidate = path.join(rootDir, packageDir);
return fs.existsSync(path.join(candidate, 'package.json')) ? candidate : null;
}
function readPackageVersion(packagePath) {
if (VERSION_CACHE.has(packagePath)) {
return VERSION_CACHE.get(packagePath);
}
try {
const packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'), 'utf8'));
const version = packageJson.version || null;
VERSION_CACHE.set(packagePath, version);
return version;
} catch {
VERSION_CACHE.set(packagePath, null);
return null;
}
}
function resolveSpecifier(name) {
if (!name.startsWith(PACKAGE_SCOPE)) {
return null;
}
const commonPlatPath = pathIfPackageExists(COMMON_PLAT_PACKAGES_ROOT, name);
if (PACKAGE_SOURCE === 'common-plat') {
return commonPlatPath ? 'workspace:*' : null;
}
if (PACKAGE_SOURCE === 'gitea') {
return commonPlatPath ? readPackageVersion(commonPlatPath) : null;
}
return commonPlatPath ? 'workspace:*' : null;
}
function rewriteDependencySet(dependencies = {}) {
for (const dependencyName of Object.keys(dependencies)) {
const rewrittenSpecifier = resolveSpecifier(dependencyName);
if (rewrittenSpecifier) {
dependencies[dependencyName] = rewrittenSpecifier;
}
}
}
function logSourceOnce() {
if (loggedSource) {
return;
}
loggedSource = true;
process.stderr.write(
`[bytelyst] pnpm package source=${PACKAGE_SOURCE} commonPlatRoot=${COMMON_PLAT_ROOT}\n`,
);
}
module.exports = {
hooks: {
readPackage(packageJson) {
logSourceOnce();
if (packageJson.name?.startsWith(PACKAGE_SCOPE)) {
return packageJson;
}
rewriteDependencySet(packageJson.dependencies);
rewriteDependencySet(packageJson.devDependencies);
rewriteDependencySet(packageJson.optionalDependencies);
return packageJson;
},
},
};