feat(FN-4605): complete Step 3 — add workspace-root bootstrap and pretest hooks

Fusion-Task-Id: FN-4605
Fusion-Task-Lineage: 472b0ccb-d015-4ff7-bdf2-1d5d05ae09e9
This commit is contained in:
Fusion
2026-05-15 08:10:03 -07:00
committed by gsxdsm
parent aa7a2ee812
commit a9362c8f29
4 changed files with 57 additions and 4 deletions

View File

@@ -188,21 +188,43 @@ function run(
}
}
function resolveWorkspaceRoot(explicitRootDir) {
if (process.env.FUSION_PROJECT_DIR) {
return path.resolve(process.env.FUSION_PROJECT_DIR);
}
if (explicitRootDir) {
return path.resolve(explicitRootDir);
}
let current = path.resolve(process.cwd());
while (true) {
if (existsSync(path.join(current, "pnpm-workspace.yaml"))) {
return current;
}
const parent = path.dirname(current);
if (parent === current) break;
current = parent;
}
return path.resolve(process.cwd());
}
export function ensureTestArtifacts(
rootDir = process.cwd(),
rootDir,
runFn = run,
existsFn = existsSync,
statFn = statSync,
readdirFn = readdirSync,
runOptions = {},
) {
const missingOrStale = detectMissingOrStaleArtifacts(rootDir, existsFn, statFn, readdirFn);
const resolvedRootDir = resolveWorkspaceRoot(rootDir);
const missingOrStale = detectMissingOrStaleArtifacts(resolvedRootDir, existsFn, statFn, readdirFn);
if (missingOrStale.length === 0) return [];
const names = missingOrStale.map((pkg) => pkg.name);
console.log(`[test-bootstrap] rebuilding workspace dist artifacts (missing or stale): ${names.join(", ")}`);
if (runFn === run) {
runFn("pnpm", [...names.flatMap((name) => ["--filter", name]), "build"], rootDir, {
runFn("pnpm", [...names.flatMap((name) => ["--filter", name]), "build"], resolvedRootDir, {
...runOptions,
pkgEntries: missingOrStale,
existsFn,
@@ -210,7 +232,7 @@ export function ensureTestArtifacts(
readdirFn,
});
} else {
runFn("pnpm", [...names.flatMap((name) => ["--filter", name]), "build"], rootDir);
runFn("pnpm", [...names.flatMap((name) => ["--filter", name]), "build"], resolvedRootDir);
}
return names;
}