fix(build): keep tsdown prune best-effort

This commit is contained in:
Ayaan Zaidi
2026-04-08 21:14:45 +05:30
parent 654ad0a1fb
commit 17e6ef4076
2 changed files with 41 additions and 10 deletions

View File

@@ -47,17 +47,22 @@ function pruneStaleRuntimeSymlinks() {
removeDistPluginNodeModulesSymlinks(path.join(cwd, "dist-runtime"));
}
function pruneSourceCheckoutBundledPluginNodeModules() {
const cwd = process.cwd();
export function pruneSourceCheckoutBundledPluginNodeModules(params = {}) {
const cwd = params.cwd ?? process.cwd();
const logger = params.logger ?? console;
if (!isSourceCheckoutRoot({ packageRoot: cwd, existsSync: fs.existsSync })) {
return;
}
pruneBundledPluginSourceNodeModules({
extensionsDir: path.join(cwd, "extensions"),
existsSync: fs.existsSync,
readdirSync: fs.readdirSync,
rmSync: fs.rmSync,
});
try {
pruneBundledPluginSourceNodeModules({
extensionsDir: path.join(cwd, "extensions"),
existsSync: fs.existsSync,
readdirSync: fs.readdirSync,
rmSync: fs.rmSync,
});
} catch (error) {
logger.warn(`tsdown: could not prune bundled plugin source node_modules: ${String(error)}`);
}
}
function findFatalUnresolvedImport(lines) {

View File

@@ -1,5 +1,9 @@
import { describe, expect, it } from "vitest";
import { resolveTsdownBuildInvocation } from "../../scripts/tsdown-build.mjs";
import fs from "node:fs";
import { describe, expect, it, vi } from "vitest";
import {
pruneSourceCheckoutBundledPluginNodeModules,
resolveTsdownBuildInvocation,
} from "../../scripts/tsdown-build.mjs";
describe("resolveTsdownBuildInvocation", () => {
it("routes Windows tsdown builds through the pnpm runner instead of shell=true", () => {
@@ -30,4 +34,26 @@ describe("resolveTsdownBuildInvocation", () => {
},
});
});
it("keeps source-checkout prune best-effort", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const rmSync = vi.spyOn(fs, "rmSync");
rmSync.mockImplementation(() => {
throw new Error("locked");
});
expect(() =>
pruneSourceCheckoutBundledPluginNodeModules({
cwd: process.cwd(),
}),
).not.toThrow();
expect(warn).toHaveBeenCalledWith(
"tsdown: could not prune bundled plugin source node_modules: Error: locked",
);
warn.mockRestore();
rmSync.mockRestore();
});
});