perf(plugins): skip fresh boundary dts prep

This commit is contained in:
Vincent Koc
2026-04-07 12:19:40 +01:00
parent b374a031ec
commit 3493db46a4
3 changed files with 180 additions and 13 deletions

View File

@@ -1,9 +1,22 @@
import { describe, expect, it } from "vitest";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
createPrefixedOutputWriter,
isArtifactSetFresh,
runNodeStepsInParallel,
} from "../../scripts/prepare-extension-package-boundary-artifacts.mjs";
const tempRoots = new Set<string>();
afterEach(() => {
for (const rootDir of tempRoots) {
fs.rmSync(rootDir, { force: true, recursive: true });
}
tempRoots.clear();
});
describe("prepare-extension-package-boundary-artifacts", () => {
it("prefixes each completed line and flushes the trailing partial line", () => {
let output = "";
@@ -40,4 +53,36 @@ describe("prepare-extension-package-boundary-artifacts", () => {
expect(Date.now() - startedAt).toBeLessThan(2_000);
});
it("treats artifacts as fresh only when outputs are newer than inputs", () => {
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-boundary-prep-"));
tempRoots.add(rootDir);
const inputPath = path.join(rootDir, "src", "demo.ts");
const outputPath = path.join(rootDir, "dist", "demo.tsbuildinfo");
fs.mkdirSync(path.dirname(inputPath), { recursive: true });
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
fs.writeFileSync(inputPath, "export const demo = 1;\n", "utf8");
fs.writeFileSync(outputPath, "ok\n", "utf8");
fs.utimesSync(inputPath, new Date(1_000), new Date(1_000));
fs.utimesSync(outputPath, new Date(2_000), new Date(2_000));
expect(
isArtifactSetFresh({
rootDir,
inputPaths: ["src"],
outputPaths: ["dist/demo.tsbuildinfo"],
}),
).toBe(true);
fs.utimesSync(inputPath, new Date(3_000), new Date(3_000));
expect(
isArtifactSetFresh({
rootDir,
inputPaths: ["src"],
outputPaths: ["dist/demo.tsbuildinfo"],
}),
).toBe(false);
});
});