feat(FN-4938): complete Step 2 — add helper and wire cleanup

Fusion-Task-Id: FN-4938
Fusion-Task-Lineage: 8b53a5da-1321-4796-9775-ff043efdcef3
This commit is contained in:
Fusion (runfusion.ai)
2026-05-18 01:41:22 -07:00
committed by gsxdsm
parent 365639afa6
commit d702231adc
6 changed files with 227 additions and 3 deletions

View File

@@ -0,0 +1,44 @@
import { existsSync } from "node:fs";
import { rm } from "node:fs/promises";
import { resolve } from "node:path";
export const DESKTOP_ARTIFACT_RELATIVE_PATHS = ["packages/desktop/dist", "packages/desktop/dist-electron"] as const;
type CleanupLogger = {
log: (message: string) => void;
warn: (message: string) => void;
};
export async function removeDesktopBuildArtifacts(
worktreePath: string,
logger?: CleanupLogger,
): Promise<{ removed: string[]; skipped: string[]; failures: Array<{ path: string; error: string }> }> {
const removed: string[] = [];
const skipped: string[] = [];
const failures: Array<{ path: string; error: string }> = [];
if (!worktreePath) {
logger?.warn?.("Desktop artifact cleanup skipped: missing worktree path");
return { removed, skipped, failures };
}
for (const relativePath of DESKTOP_ARTIFACT_RELATIVE_PATHS) {
const absolutePath = resolve(worktreePath, relativePath);
if (!existsSync(absolutePath)) {
skipped.push(relativePath);
continue;
}
try {
await rm(absolutePath, { recursive: true, force: true });
removed.push(relativePath);
logger?.log?.(`Removed desktop build artifact directory: ${relativePath}`);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
failures.push({ path: relativePath, error: message });
logger?.warn?.(`Failed to remove desktop build artifact directory ${relativePath}: ${message}`);
}
}
return { removed, skipped, failures };
}