mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:40:44 +00:00
fix: prune stale root chunks before rebuilds
This commit is contained in:
@@ -16,6 +16,7 @@ const extraArgs = process.argv.slice(2);
|
||||
const INEFFECTIVE_DYNAMIC_IMPORT_RE = /\[INEFFECTIVE_DYNAMIC_IMPORT\]/;
|
||||
const UNRESOLVED_IMPORT_RE = /\[UNRESOLVED_IMPORT\]/;
|
||||
const ANSI_ESCAPE_RE = new RegExp(String.raw`\u001B\[[0-9;]*m`, "g");
|
||||
const HASHED_ROOT_JS_RE = /^(?<base>.+)-[A-Za-z0-9_-]+\.js$/u;
|
||||
|
||||
function removeDistPluginNodeModulesSymlinks(rootDir) {
|
||||
const extensionsDir = path.join(rootDir, "extensions");
|
||||
@@ -47,6 +48,34 @@ function pruneStaleRuntimeSymlinks() {
|
||||
removeDistPluginNodeModulesSymlinks(path.join(cwd, "dist-runtime"));
|
||||
}
|
||||
|
||||
export function pruneStaleRootChunkFiles(params = {}) {
|
||||
const cwd = params.cwd ?? process.cwd();
|
||||
const fsImpl = params.fs ?? fs;
|
||||
const roots = [path.join(cwd, "dist"), path.join(cwd, "dist-runtime")];
|
||||
for (const root of roots) {
|
||||
let entries = [];
|
||||
try {
|
||||
entries = fsImpl.readdirSync(root, { withFileTypes: true });
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
if (!entry.isFile()) {
|
||||
continue;
|
||||
}
|
||||
if (!HASHED_ROOT_JS_RE.test(entry.name)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
fsImpl.rmSync(path.join(root, entry.name), { force: true });
|
||||
} catch {
|
||||
// Best-effort cleanup. The subsequent build will overwrite any stragglers.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function pruneSourceCheckoutBundledPluginNodeModules(params = {}) {
|
||||
const cwd = params.cwd ?? process.cwd();
|
||||
const logger = params.logger ?? console;
|
||||
@@ -116,6 +145,7 @@ function isMainModule() {
|
||||
if (isMainModule()) {
|
||||
pruneSourceCheckoutBundledPluginNodeModules();
|
||||
pruneStaleRuntimeSymlinks();
|
||||
pruneStaleRootChunkFiles();
|
||||
const invocation = resolveTsdownBuildInvocation();
|
||||
const result = spawnSync(invocation.command, invocation.args, invocation.options);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user