fix(update): prune stale compile cache on install

This commit is contained in:
Peter Steinberger
2026-04-29 05:14:43 +01:00
parent ab39f2b272
commit 128115fb25
3 changed files with 57 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import {
createBundledRuntimeDependencyInstallEnv,
createNestedNpmInstallEnv,
isDirectPostinstallInvocation,
pruneOpenClawCompileCache,
pruneInstalledPackageDist,
discoverBundledPluginRuntimeDeps,
pruneBundledPluginSourceNodeModules,
@@ -180,6 +181,31 @@ describe("bundled plugin postinstall", () => {
expect(spawnSync).not.toHaveBeenCalled();
});
it("prunes OpenClaw compile cache during package postinstall", () => {
const removed: string[] = [];
const existsSync = vi.fn((value: string) =>
value.endsWith(path.join("openclaw-cache", "openclaw")),
);
const rmSync = vi.fn((value: string) => {
removed.push(value);
});
pruneOpenClawCompileCache({
env: { NODE_COMPILE_CACHE: path.join("/tmp", "openclaw-cache") },
existsSync,
rmSync,
log: { warn: vi.fn() },
});
expect(removed).toEqual([path.join("/tmp", "openclaw-cache", "openclaw")]);
expect(rmSync).toHaveBeenCalledWith(path.join("/tmp", "openclaw-cache", "openclaw"), {
recursive: true,
force: true,
maxRetries: 2,
retryDelay: 100,
});
});
it("prunes source-checkout bundled plugin node_modules", async () => {
const packageRoot = await createTempDirAsync("openclaw-source-checkout-");
const extensionsDir = path.join(packageRoot, "extensions");