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

@@ -49,7 +49,7 @@ BUILD_LOCK_DIR="${TMPDIR:-/tmp}/openclaw-parallels-build.lock"
TIMEOUT_INSTALL_SITE_S=420
TIMEOUT_INSTALL_TGZ_S=420
TIMEOUT_INSTALL_REGISTRY_S=420
TIMEOUT_UPDATE_DEV_S="${OPENCLAW_PARALLELS_MACOS_UPDATE_DEV_TIMEOUT_S:-1200}"
TIMEOUT_UPDATE_DEV_S="${OPENCLAW_PARALLELS_MACOS_UPDATE_DEV_TIMEOUT_S:-1800}"
TIMEOUT_VERIFY_S=60
TIMEOUT_ONBOARD_S=180
TIMEOUT_GATEWAY_S=180

View File

@@ -21,6 +21,7 @@ import {
unlinkSync,
writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { basename, dirname, isAbsolute, join, posix, relative } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { resolveNpmRunner } from "./npm-runner.mjs";
@@ -861,6 +862,29 @@ function shouldRunBundledPluginPostinstall(params) {
return true;
}
export function pruneOpenClawCompileCache(params = {}) {
const env = params.env ?? process.env;
const pathExists = params.existsSync ?? existsSync;
const remove = params.rmSync ?? rmSync;
const log = params.log ?? console;
const baseDirs = [
env.NODE_DISABLE_COMPILE_CACHE ? "" : env.NODE_COMPILE_CACHE,
join(tmpdir(), "node-compile-cache"),
].filter((value, index, values) => value && values.indexOf(value) === index);
for (const baseDir of baseDirs) {
const cacheRoot = join(baseDir, "openclaw");
if (!pathExists(cacheRoot)) {
continue;
}
try {
remove(cacheRoot, { recursive: true, force: true, maxRetries: 2, retryDelay: 100 });
} catch (error) {
log.warn?.(`[postinstall] could not prune OpenClaw compile cache: ${String(error)}`);
}
}
}
export function runBundledPluginPostinstall(params = {}) {
const env = params.env ?? process.env;
const packageRoot = params.packageRoot ?? DEFAULT_PACKAGE_ROOT;
@@ -871,6 +895,12 @@ export function runBundledPluginPostinstall(params = {}) {
if (env?.[DISABLE_POSTINSTALL_ENV]?.trim()) {
return;
}
pruneOpenClawCompileCache({
env,
existsSync: pathExists,
rmSync: params.rmSync,
log,
});
if (isSourceCheckoutRoot({ packageRoot, existsSync: pathExists })) {
try {
pruneBundledPluginSourceNodeModules({