fix(update): harden global updates

This commit is contained in:
Peter Steinberger
2026-02-02 04:44:35 -08:00
parent 6b0d6e2540
commit 57d008a33d
7 changed files with 122 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ export type CommandRunner = (
const PRIMARY_PACKAGE_NAME = "openclaw";
const ALL_PACKAGE_NAMES = [PRIMARY_PACKAGE_NAME] as const;
const GLOBAL_RENAME_PREFIX = ".";
async function pathExists(targetPath: string): Promise<boolean> {
try {
@@ -142,3 +143,39 @@ export function globalInstallArgs(manager: GlobalInstallManager, spec: string):
}
return ["npm", "i", "-g", spec];
}
export async function cleanupGlobalRenameDirs(params: {
globalRoot: string;
packageName: string;
}): Promise<{ removed: string[] }> {
const removed: string[] = [];
const root = params.globalRoot.trim();
const name = params.packageName.trim();
if (!root || !name) {
return { removed };
}
const prefix = `${GLOBAL_RENAME_PREFIX}${name}-`;
let entries: string[] = [];
try {
entries = await fs.readdir(root);
} catch {
return { removed };
}
for (const entry of entries) {
if (!entry.startsWith(prefix)) {
continue;
}
const target = path.join(root, entry);
try {
const stat = await fs.lstat(target);
if (!stat.isDirectory()) {
continue;
}
await fs.rm(target, { recursive: true, force: true });
removed.push(entry);
} catch {
// ignore cleanup failures
}
}
return { removed };
}