UNPKG

everything-dev

Version:

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

85 lines (83 loc) • 3.1 kB
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs"); const require_release_plane = require("../resolution/release-plane.cjs"); const require_workspace = require("../workspace/workspace.cjs"); const require_plane_audit = require("../resolution/plane-audit.cjs"); let node_fs = require("node:fs"); let node_path = require("node:path"); let node_process = require("node:process"); node_process = require_runtime.__toESM(node_process, 1); let node_child_process = require("node:child_process"); //#region src/services/scaffold/upgrade-realign.ts const ownedKeysFrom = (lines) => [...new Set(lines.filter((line) => line.kind === "owned").map((line) => require_release_plane.slotPublishKey(line.slot)))].sort(); /** Detect owned slots the freshly resolved plane still finds diverging. */ async function detectOwnedDivergentKeys(session, options) { const lines = await require_plane_audit.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) => node_process.default.stderr.write(`${message}\n`)) { const realigned = []; const failures = []; if (!(0, node_fs.existsSync)((0, node_path.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 = require_workspace.findWorkspaceRoot(projectDir)?.dir ?? projectDir; const bosBin = (0, node_path.join)(workspaceDir, "node_modules", ".bin", "bos"); if (!(0, node_fs.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 = (0, node_child_process.spawnSync)(bosBin, [ "deploy", "--packages", keys.join(",") ], { cwd: projectDir, stdio: [ "inherit", "pipe", "pipe" ], encoding: "utf-8", env: { ...node_process.default.env, BOS_NO_BANNER: "1" } }); if (child.stdout) node_process.default.stderr.write(child.stdout); if (child.stderr) node_process.default.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 exports.detectOwnedDivergentKeys = detectOwnedDivergentKeys; exports.realignOwnedSlots = realignOwnedSlots; //# sourceMappingURL=upgrade-realign.cjs.map