heldBuilds
uses node:fs
What the leases in work hold (leaseBuilds): those of processes still running (an ended one's is removed).
import { ownerGone } from "#codebase/tcmts/cli/web"; import fs from "node:fs"; import path from "node:path"; export function heldBuilds(work: string): { builds: Set<string>; assets: Set<string> } { const builds = new Set<string>(); const assets = new Set<string>(); for (const e of fs.existsSync(work) ? fs.readdirSync(work) : []) { if (!/^lease\..+\.json$/.test(e)) continue; if (ownerGone(e)) { fs.rmSync(path.join(work, e), { force: true }); continue; } try { const held = JSON.parse(fs.readFileSync(path.join(work, e), "utf8")) as { builds?: string[]; assets?: string[]; }; for (const b of held.builds ?? []) builds.add(b); for (const a of held.assets ?? []) assets.add(a); } catch { // released as it was read } } return { builds, assets }; }