mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 19:14:44 +00:00
fix: prune stale generated declarations before tsdown build
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
createTsdownOutputScanner,
|
||||
pruneSourceCheckoutBundledPluginNodeModules,
|
||||
pruneStaleRootChunkFiles,
|
||||
pruneUntrackedGeneratedSourceDeclarations,
|
||||
resolveTsdownBuildInvocation,
|
||||
runTsdownBuildInvocation,
|
||||
} from "../../scripts/tsdown-build.mjs";
|
||||
@@ -138,6 +139,37 @@ describe("resolveTsdownBuildInvocation", () => {
|
||||
await expectPathMissing(path.join(rootDir, "dist-runtime"));
|
||||
await expect(fsPromises.readFile(unrelatedFile, "utf8")).resolves.toBe("keep\n");
|
||||
});
|
||||
|
||||
it("prunes untracked generated declaration files that shadow source entries", async () => {
|
||||
const rootDir = createTempDir("openclaw-tsdown-source-dts-");
|
||||
const signalDir = path.join(rootDir, "extensions", "signal");
|
||||
const signalSrcDir = path.join(signalDir, "src");
|
||||
await fsPromises.mkdir(signalSrcDir, { recursive: true });
|
||||
await fsPromises.writeFile(path.join(signalDir, "api.ts"), "export {};\n");
|
||||
await fsPromises.writeFile(path.join(signalDir, "api.d.ts"), "export {};\n");
|
||||
await fsPromises.writeFile(path.join(signalSrcDir, "probe.ts"), "export {};\n");
|
||||
await fsPromises.writeFile(path.join(signalSrcDir, "probe.d.ts"), "export {};\n");
|
||||
await fsPromises.writeFile(
|
||||
path.join(signalSrcDir, "ambient.d.ts"),
|
||||
"declare const x: string;\n",
|
||||
);
|
||||
|
||||
const removed = pruneUntrackedGeneratedSourceDeclarations({
|
||||
cwd: rootDir,
|
||||
spawnSync: () => ({
|
||||
status: 0,
|
||||
stdout:
|
||||
"extensions/signal/api.d.ts\nextensions/signal/src/probe.d.ts\nextensions/signal/src/ambient.d.ts\n",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(removed).toBe(2);
|
||||
await expectPathMissing(path.join(signalDir, "api.d.ts"));
|
||||
await expectPathMissing(path.join(signalSrcDir, "probe.d.ts"));
|
||||
await expect(
|
||||
fsPromises.readFile(path.join(signalSrcDir, "ambient.d.ts"), "utf8"),
|
||||
).resolves.toBe("declare const x: string;\n");
|
||||
});
|
||||
});
|
||||
|
||||
describe("createTsdownOutputScanner", () => {
|
||||
|
||||
Reference in New Issue
Block a user