fix(runner): support recursive package.json scanning in build verification

This commit is contained in:
2026-06-03 14:28:13 -07:00
parent fa0e460c1c
commit 76c161eedf
2 changed files with 114 additions and 54 deletions

View File

@@ -24,39 +24,73 @@ function runBuildVerification(
const { execSync } = require("child_process");
const absoluteAppPath = path.join(repoRoot, appPath);
const pkgJsonPath = path.join(absoluteAppPath, "package.json");
if (!fs.existsSync(pkgJsonPath)) {
return { success: true }; // No package.json, skip build check
// Find all directories containing package.json (excluding node_modules, .git, .next, .vibncode, dist)
const pkgDirs: string[] = [];
function scan(dir: string) {
try {
const files = fs.readdirSync(dir);
if (files.includes("package.json")) {
pkgDirs.push(dir);
}
for (const file of files) {
if (
file === "node_modules" ||
file === ".git" ||
file === ".next" ||
file === ".vibncode" ||
file === "dist"
) {
continue;
}
const full = path.join(dir, file);
if (fs.statSync(full).isDirectory()) {
scan(full);
}
}
} catch {}
}
try {
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
// Only verify if there is an explicit build script
if (!pkg.scripts || !pkg.scripts.build) {
return { success: true };
scan(absoluteAppPath);
if (pkgDirs.length === 0) {
return { success: true }; // No package.json anywhere, skip build check
}
for (const dir of pkgDirs) {
const pkgJsonPath = path.join(dir, "package.json");
try {
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
// Skip if there's no build script or if it's the root container which is just a workspace wrapper
if (!pkg.scripts || !pkg.scripts.build || pkg.name === "workspace") {
continue;
}
console.log(
`[Ralph Loop] Running automatic build verification: npm run build inside ${dir}...`,
);
execSync("npm run build", {
cwd: dir,
stdio: "pipe",
timeout: 60000,
});
} catch (err: any) {
const stderr = err.stderr
? err.stderr.toString()
: err.message || String(err);
console.warn(
`[Ralph Loop] Build verification failed inside ${dir}:`,
stderr,
);
return {
success: false,
error: `Build failed in directory "${path.relative(repoRoot, dir)}":\n${stderr.slice(-3000)}`,
};
}
console.log(
`[Ralph Loop] Running automatic build verification: npm run build inside ${absoluteAppPath}...`,
);
// Run npm run build with a 45s timeout to prevent hanging
execSync("npm run build", {
cwd: absoluteAppPath,
stdio: "pipe",
timeout: 45000,
});
return { success: true };
} catch (err: any) {
const stderr = err.stderr
? err.stderr.toString()
: err.message || String(err);
console.warn(`[Ralph Loop] Build verification failed:`, stderr);
return {
success: false,
error: stderr.slice(-3000), // Cap the log length to avoid flooding the prompt context
};
}
return { success: true };
}
export interface OutputLine {