fix(plugins): track package boundary dts freshness

This commit is contained in:
Vincent Koc
2026-04-07 12:59:38 +01:00
parent 97c031a8db
commit 76296a9d14
4 changed files with 64 additions and 41 deletions

View File

@@ -193,6 +193,7 @@ function isRelevantCompileInput(filePath) {
function collectNewestMtime(entryPath, params = {}) {
const includeFile = params.includeFile ?? (() => true);
const skipDistDirectories = params.skipDistDirectories ?? true;
let newestMtimeMs = 0;
function visit(currentPath) {
@@ -202,7 +203,7 @@ function collectNewestMtime(entryPath, params = {}) {
const stats = statSync(currentPath);
if (stats.isDirectory()) {
const basename = path.basename(currentPath);
if (basename === "dist" || basename === "node_modules") {
if ((skipDistDirectories && basename === "dist") || basename === "node_modules") {
return;
}
for (const child of readdirSync(currentPath)) {
@@ -241,10 +242,9 @@ export function isBoundaryCompileFresh(extensionId, params = {}) {
collectNewestMtime(extensionRoot, { includeFile: isRelevantCompileInput });
const sharedNewestInputMtimeMs =
params.sharedNewestInputMtimeMs ??
Math.max(
collectNewestMtime(resolve(rootDir, "dist/plugin-sdk")),
collectNewestMtime(resolve(rootDir, "packages/plugin-sdk/dist")),
);
collectNewestMtime(resolve(rootDir, "packages/plugin-sdk/dist"), {
skipDistDirectories: false,
});
const newestInputMtimeMs = Math.max(extensionNewestInputMtimeMs, sharedNewestInputMtimeMs);
const oldestOutputMtimeMs = collectOldestMtime([
resolveBoundaryTsStampPath(extensionId, rootDir),
@@ -553,13 +553,19 @@ async function runCompileCheck(extensionIds) {
process.stdout.write(
`preparing plugin-sdk boundary artifacts for ${extensionIds.length} plugins\n`,
);
runNodeStep("plugin-sdk boundary prep", [prepareBoundaryArtifactsBin], 420_000);
runNodeStep(
"plugin-sdk boundary prep",
[prepareBoundaryArtifactsBin, "--mode=package-boundary"],
420_000,
);
const prepElapsedMs = Date.now() - prepStartedAt;
const concurrency = resolveCompileConcurrency();
const verboseFreshLogs = process.env.OPENCLAW_EXTENSION_BOUNDARY_VERBOSE_FRESH === "1";
const sharedNewestInputMtimeMs = Math.max(
collectNewestMtime(resolve(repoRoot, "dist/plugin-sdk")),
collectNewestMtime(resolve(repoRoot, "packages/plugin-sdk/dist")),
const sharedNewestInputMtimeMs = collectNewestMtime(
resolve(repoRoot, "packages/plugin-sdk/dist"),
{
skipDistDirectories: false,
},
);
process.stdout.write(`compile concurrency ${concurrency}\n`);
const compileStartedAt = Date.now();

View File

@@ -7,6 +7,7 @@ const require = createRequire(import.meta.url);
const repoRoot = resolve(import.meta.dirname, "..");
const tscBin = require.resolve("typescript/bin/tsc");
const TYPE_INPUT_EXTENSIONS = new Set([".ts", ".tsx", ".d.ts", ".js", ".mjs", ".json"]);
const VALID_MODES = new Set(["all", "package-boundary"]);
const ROOT_DTS_INPUTS = [
"tsconfig.json",
@@ -36,6 +37,15 @@ function isRelevantTypeInput(filePath) {
return TYPE_INPUT_EXTENSIONS.has(path.extname(filePath));
}
export function parseMode(argv = process.argv.slice(2)) {
const modeArg = argv.find((arg) => arg.startsWith("--mode="));
const mode = modeArg?.slice("--mode=".length) ?? "all";
if (!VALID_MODES.has(mode)) {
throw new Error(`Unknown mode: ${mode}`);
}
return mode;
}
function collectNewestMtime(paths, params = {}) {
const rootDir = params.rootDir ?? repoRoot;
const includeFile = params.includeFile ?? (() => true);
@@ -199,8 +209,9 @@ export async function runNodeStepsInParallel(steps) {
}
}
export async function main() {
export async function main(argv = process.argv.slice(2)) {
try {
const mode = parseMode(argv);
const rootDtsFresh = isArtifactSetFresh({
inputPaths: ROOT_DTS_INPUTS,
outputPaths: ["dist/plugin-sdk/.tsbuildinfo"],
@@ -221,14 +232,16 @@ export async function main() {
});
const pendingSteps = [];
if (!rootDtsFresh) {
pendingSteps.push({
label: "plugin-sdk boundary dts",
args: [tscBin, "-p", "tsconfig.plugin-sdk.dts.json"],
timeoutMs: 300_000,
});
} else {
process.stdout.write("[plugin-sdk boundary dts] fresh; skipping\n");
if (mode === "all") {
if (!rootDtsFresh) {
pendingSteps.push({
label: "plugin-sdk boundary dts",
args: [tscBin, "-p", "tsconfig.plugin-sdk.dts.json"],
timeoutMs: 300_000,
});
} else {
process.stdout.write("[plugin-sdk boundary dts] fresh; skipping\n");
}
}
if (!packageDtsFresh) {
pendingSteps.push({
@@ -244,13 +257,13 @@ export async function main() {
await runNodeStepsInParallel(pendingSteps);
}
if (!entryShimsFresh || pendingSteps.length > 0) {
if (mode === "all" && (!entryShimsFresh || pendingSteps.length > 0)) {
await runNodeStep(
"plugin-sdk boundary root shims",
["--import", "tsx", resolve(repoRoot, "scripts/write-plugin-sdk-entry-dts.ts")],
120_000,
);
} else {
} else if (mode === "all") {
process.stdout.write("[plugin-sdk boundary root shims] fresh; skipping\n");
}
} catch (error) {