openclaw/scripts/runtime-postbuild-shared.mjs
Ayaan Zaidi 76922aba44
fix: private QA builds omit CLI diagnostic companions (#165200)
With `OPENCLAW_BUILD_PRIVATE_QA=1`, the build emitted a test-env chunk that references the two CLI diagnostic CommonJS companions, but never copied them into `dist`, so `check-package-dist-imports.mjs` failed. Runtime postbuild now copies the companions only when the private-QA facade was emitted, and the run-node input-state tracker treats their sources as postbuild inputs.

Proof (Docker): the private-QA build exits 0 on both. The closure check exits 1 on base (exactly the two missing companions) and 0 here. The normal build, closure check and pack exit 0 on both. A timestamp-controlled dist diff is empty, and the `npm pack --dry-run` lists match at 13,793 paths. The public publication path never enables private QA. The new cases fail on base and pass here.

Fixes #165159.

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-10-05 08:22:01 +08:00

50 lines
1.2 KiB
JavaScript

// Shared filesystem helpers for runtime postbuild scripts.
import fs from "node:fs";
import { dirname } from "node:path";
export const CLI_DIAGNOSTIC_COMPANIONS = [
"cli-process-diagnostics.test-support.cjs",
"cli-process-tree.test-support.cjs",
];
/**
* Writes text only when contents changed and returns whether a write happened.
*/
export function writeTextFileIfChanged(filePath, contents) {
const next = String(contents);
try {
const current = fs.readFileSync(filePath, "utf8");
if (current === next) {
return false;
}
} catch {
// Write the file when it does not exist or cannot be read.
}
fs.mkdirSync(dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, next, "utf8");
return true;
}
/**
* Removes one file if present, treating missing paths as success.
*/
export function removeFileIfExists(filePath) {
try {
fs.rmSync(filePath, { force: true });
return true;
} catch {
return false;
}
}
/**
* Removes a file or directory tree if present.
*/
export function removePathIfExists(filePath) {
try {
fs.rmSync(filePath, { recursive: true, force: true });
return true;
} catch {
return false;
}
}