UNPKG

everything-dev

Version:

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

95 lines (94 loc) • 2.98 kB
//#region src/services/lockfile/boot.ts function segmentsOf(remotePath) { return remotePath.split("."); } function entryAt(root, segments) { let cursor = root; for (const segment of segments) { if (!cursor || typeof cursor !== "object") return void 0; cursor = cursor[segment]; } return cursor; } /** Clone-and-set along the path: untouched branches keep their identity. */ function setIn(root, segments, value) { if (segments.length === 0) return root; const clone = { ...root }; const [head, ...rest] = segments; const headKey = head; if (rest.length === 0) { clone[headKey] = value; return clone; } const child = root[headKey]; clone[headKey] = child && typeof child === "object" ? setIn(child, rest, value) : setIn({}, rest, value); return clone; } function applyCompositionLockfile(config, lockfile) { const applied = []; const drift = []; let working = config; let mutated = false; const runtimeRef = `bos://${config.account}/${config.domain}`; if (lockfile.runtimeRef !== runtimeRef) return { config, applied, drift: [{ path: "*", detail: `the lockfile freezes ${lockfile.runtimeRef}, not this runtime (${runtimeRef}) — not applied` }] }; for (const [remotePath, entry] of Object.entries(lockfile.remotes)) { const segments = segmentsOf(remotePath); const current = entryAt(working, segments); if (entry.kind === "pluginRef") { if (typeof current === "string") { if (current !== entry.ref) { drift.push({ path: remotePath, detail: `plugin ref ${current} differs from the frozen ${entry.ref}` }); working = setIn(working, segments, entry.ref); mutated = true; } continue; } drift.push({ path: remotePath, detail: `the lockfile freezes a bare plugin ref but the resolved composition carries an entry` }); continue; } if (!current || typeof current !== "object") { drift.push({ path: remotePath, detail: "the resolved composition no longer carries this remote — run `bos lock`" }); continue; } const ref = current; const frozenDigest = entry.digest && typeof entry.digest.manifest === "string" ? entry.digest.manifest : void 0; const servingDigest = typeof ref.digest?.manifest === "string" ? ref.digest.manifest : void 0; if (!frozenDigest) continue; if (servingDigest && servingDigest === frozenDigest) continue; if (servingDigest) drift.push({ path: remotePath, detail: `serving ${servingDigest} differs from the frozen ${frozenDigest}` }); else applied.push(remotePath); const base = entry.base ?? (typeof ref.production === "string" ? ref.production : void 0); const stamped = { ...ref }; if (base) stamped.production = base; if (entry.digest) stamped.digest = entry.digest; working = setIn(working, segments, stamped); mutated = true; } return { config: mutated ? working : config, applied, drift }; } //#endregion export { applyCompositionLockfile }; //# sourceMappingURL=boot.mjs.map