retireBuild
uses node:fs
A build that's being replaced (the one before the known-good, when pnpm verify makes a new one), kept among the
older ones as builds/<id>, named by the history entry it was made from, the oldest beyond keep going. One that
doesn't say what it was made from, or one kept already, goes. Where it's kept.
import { buildRecord, KEEP_BUILDS, pruneKeptBuilds } from "#codebase/tcmts/cli/builds"; import fs from "node:fs"; import path from "node:path"; export function retireBuild(root: string, dir: string, keep = KEEP_BUILDS): string | undefined { if (!fs.existsSync(dir)) return undefined; const head = buildRecord(dir)?.head; const to = head ? path.join(root, "builds", head.slice(0, 8)) : undefined; if (to && !fs.existsSync(to)) { fs.mkdirSync(path.dirname(to), { recursive: true }); fs.renameSync(dir, to); } else fs.rmSync(dir, { recursive: true, force: true }); pruneKeptBuilds(root, keep); return to && fs.existsSync(to) ? to : undefined; }