UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

82 lines (80 loc) • 2.7 kB
import { slotPublishKey } from "../resolution/release-plane.mjs"; import { findWorkspaceRoot } from "../workspace/workspace.mjs"; import { auditSessionPlane } from "../resolution/plane-audit.mjs"; import { existsSync } from "node:fs"; import { join } from "node:path"; import process from "node:process"; import { spawnSync } from "node:child_process"; //#region src/services/scaffold/upgrade-realign.ts const ownedKeysFrom = (lines) => [...new Set(lines.filter((line) => line.kind === "owned").map((line) => slotPublishKey(line.slot)))].sort(); /** Detect owned slots the freshly resolved plane still finds diverging. */ async function detectOwnedDivergentKeys(session, options) { const lines = await auditSessionPlane(session, options); return { keys: ownedKeysFrom(lines), lines }; } /** * Republish `keys` through the scoped deploy train, running the freshly * installed bos binary. Output is forwarded to stderr — the migration phase * runs under `--json` re-exec, where stdout is the structured result. */ async function realignOwnedSlots(projectDir, keys, log = (message) => process.stderr.write(`${message}\n`)) { const realigned = []; const failures = []; if (!existsSync(join(projectDir, ".bos", "session.json"))) { log(` [realign] No stored CLI session in .bos/ — skipping the owned-slot republish of ${keys.join(", ")}. Run \`bos login\`, then: bos deploy --packages ${keys.join(",")}`); return { keys: [...keys], realigned, failures }; } const workspaceDir = findWorkspaceRoot(projectDir)?.dir ?? projectDir; const bosBin = join(workspaceDir, "node_modules", ".bin", "bos"); if (!existsSync(bosBin)) { log(` [realign] bos binary not found at ${bosBin} — skipping the owned-slot republish`); return { keys: [...keys], realigned, failures }; } log(` [realign] Republishing owned slots built against the old chain: ${keys.join(", ")}`); const child = spawnSync(bosBin, [ "deploy", "--packages", keys.join(",") ], { cwd: projectDir, stdio: [ "inherit", "pipe", "pipe" ], encoding: "utf-8", env: { ...process.env, BOS_NO_BANNER: "1" } }); if (child.stdout) process.stderr.write(child.stdout); if (child.stderr) process.stderr.write(child.stderr); if (child.status === 0) realigned.push(...keys); else { failures.push({ key: keys.join(","), error: `bos deploy --packages exited ${child.status ?? "n/a"}` }); log(` [realign] Republish failed — realign by hand: bos deploy --packages ${keys.join(",")}`); } return { keys: [...keys], realigned, failures }; } //#endregion export { detectOwnedDivergentKeys, realignOwnedSlots }; //# sourceMappingURL=upgrade-realign.mjs.map