everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
1 lines • 10.6 kB
Source Map (JSON)
{"version":3,"file":"composition.mjs","names":[],"sources":["../../../src/services/deploy/composition.ts"],"sourcesContent":["import type { BosConfigInput } from \"../../types\";\nimport { readInstalledFrameworkVersion } from \"../framework-version\";\nimport {\n checkPlatformCompat,\n type Manifest,\n type ResolvePlatformManifestOptions,\n resolvePlatformManifest,\n} from \"../platform/manifest\";\nimport { stampInheritedRemotes } from \"../resolution/release-composition\";\nimport { readWorkspaceCatalog } from \"../workspace/catalog\";\nimport { findWorkspaceRoot } from \"../workspace/workspace\";\nimport { collectRemoteDescriptors } from \"./rollback\";\nimport { resolveRemoteVersion } from \"./version-manifest\";\n\n/**\n * The deploy train's composition plane (ADR 0034 amendment — release-scoped\n * extends inheritance): every remote remote the leaf does not author is a\n * base-runtime remote, and its bytes must come from the child's pinned release\n * instead of drifting with the parent's live config pointer.\n *\n * Without this plane, a root publish (rc.N+1) moves the inherited auth pin\n * while a platform-pinned child's own ui stays built against rc.N — the\n * host's shared-singleton guard (#546) refuses the composition at boot and\n * the child's health degrades after its next redeploy. Two layers close it:\n * the release manifest records its own remote-pin map (the `remotes` field,\n * composed on the release leg), and the deploy train stamps those pins onto\n * the inherited remotes of the child's publish payload — child-wins over the\n * parent's live pointer at every consumer boot.\n */\n\n/**\n * Resolve the release manifest for a deploy: the authored `platform` pin via\n * record-first resolution (children), otherwise the latest pointer (root\n * runtimes). Returns null when no manifest is published — a normal state for\n * children pinned to pre-manifest releases. Resolution failures surface; the\n * caller warns and continues unpinned (the composition gate still\n * cross-checks the actual resolved bytes).\n */\nexport async function resolveReleaseManifestForDeploy(input: {\n configDir: string;\n authoredConfig: Record<string, unknown>;\n /** test/registry seam — threaded to the platform-manifest resolution */\n resolveOptions?: Partial<ResolvePlatformManifestOptions>;\n}): Promise<Manifest | null> {\n const resolved = await resolvePlatformManifest({\n configDir: input.configDir,\n localConfig: input.authoredConfig,\n ...input.resolveOptions,\n });\n return resolved?.manifest ?? null;\n}\n\n/** Authored remote paths: every remote whose code source the leaf itself declares. */\nexport { authoredRemoteKeys } from \"../resolution/release-composition\";\n\nexport interface StampOutcome {\n stamped: string[];\n}\n\n/**\n * Stamp inherited remotes: for every `app.*` remote in the release manifest's\n * `remotes` map that the authored config does not author (see\n * `authoredRemoteKeys` — configuring a remote is not authoring it), write the release's\n * recorded production URL + pin into the payload. Child-wins deep merge then\n * shadows the parent's live config pointer at every consumer boot, so the\n * child composes exactly the bytes its pinned release published. Remotes the\n * child authors stay untouched, and a manifest without `remotes` (pre-amendment\n * releases) stamps nothing — the composition gate covers those children.\n */\nexport function stampRemotesFromRelease(input: {\n payload: Record<string, unknown>;\n authoredConfig: Record<string, unknown>;\n manifest: Manifest;\n}): StampOutcome {\n const outcome = stampInheritedRemotes({\n config: input.payload,\n authoredConfig: input.authoredConfig,\n remotes: input.manifest.remotes,\n mode: \"payload\",\n });\n return { stamped: outcome.stamped };\n}\n\nexport interface CompositionGateReport {\n ok: boolean;\n violations: string[];\n}\n\nexport interface CompositionGateInput {\n configDir: string;\n authoredConfig: Record<string, unknown>;\n resolvedShape: Record<string, unknown>;\n resolvedRelease: Manifest | null;\n /**\n * The remote names the leaf-payload verification leg proved servable;\n * an unresolvable merged-shape remote outside this set is reported as a\n * violation instead of skipped-silently (inherited stamps are not covered\n * by that leg).\n */\n verifiedRemotes?: ReadonlySet<string>;\n /** test seam — threaded to the version-manifest fetch */\n fetchImpl?: typeof fetch;\n}\n\n/**\n * The deploy-train composition gate: cross-compare the shared-singleton\n * versions of every pinned UI remote in the extends-merged shape (the boot\n * guard's mirror, #546), plus — for authored platform pins — the ADR 0034\n * compat check of the child against its own release. Runs after pin\n * verification, before publish.\n */\nexport async function runCompositionGate(\n input: CompositionGateInput,\n): Promise<CompositionGateReport> {\n const violations: string[] = [\n ...(await compositionSkewViolations(input.resolvedShape, {\n ...(input.fetchImpl ? { fetchImpl: input.fetchImpl } : {}),\n ...(input.verifiedRemotes ? { verifiedRemotes: input.verifiedRemotes } : {}),\n })),\n ];\n if (typeof input.authoredConfig.release === \"string\" && input.resolvedRelease) {\n violations.push(...platformCompatViolations(input.resolvedRelease, input.configDir));\n }\n return { ok: violations.length === 0, violations };\n}\n\n/**\n * Cross-compare each pinned UI remote's embedded shared-singleton versions. An\n * unresolvable pin the pin/SRI verification leg already proved servable is\n * skipped (transient fetch failure); any unresolvable pin outside that set is\n * reported — the boot's version-manifest derivation would refuse it anyway.\n */\nexport async function compositionSkewViolations(\n merged: Record<string, unknown>,\n opts: { fetchImpl?: typeof fetch; verifiedRemotes?: ReadonlySet<string> } = {},\n): Promise<string[]> {\n const uiRemotes = collectRemoteDescriptors(merged as BosConfigInput).filter(\n (ref) => ref.remote === \"app.ui\" || ref.remote.endsWith(\".ui\"),\n );\n if (uiRemotes.length === 0) return [];\n\n const versionsByName = new Map<string, Array<{ remote: string; version: string }>>();\n const violations: string[] = [];\n\n await Promise.all(\n uiRemotes.map(async ({ remote, base, digest }) => {\n try {\n const resolved = await resolveRemoteVersion({\n base,\n digest,\n ...(opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}),\n });\n for (const [name, version] of Object.entries(resolved.sharedVersions ?? {})) {\n const uses = versionsByName.get(name) ?? [];\n uses.push({ remote, version });\n versionsByName.set(name, uses);\n }\n } catch (error) {\n if (opts.verifiedRemotes?.has(remote)) return;\n const reason = error instanceof Error ? error.message : String(error);\n violations.push(\n `Pinned UI remote \"${remote}\" version manifest does not serve at its production URL (${reason}) — ` +\n `a consumer boot cannot derive its shared singletons; investigate the storage origin or redeploy the bundle.`,\n );\n }\n }),\n );\n\n for (const [name, uses] of versionsByName) {\n const first = uses[0];\n if (!first) continue;\n const diverged = uses.find((use) => use.version !== first.version);\n if (!diverged) continue;\n violations.push(\n `Shared singleton \"${name}\" skew across UI sources: \"${first.remote}\" was built against ` +\n `${first.version}, \"${diverged.remote}\" against ${diverged.version} — the composition refuses to load ` +\n `a split module graph. Redeploy the older bundle: \\`bos upgrade\\` realigns the platform pin, ` +\n `\\`bos deploy\\` rebuilds against it (issue #546).`,\n );\n }\n return violations;\n}\n\n/**\n * The ADR 0034 compat check, scoping the child's installed framework version\n * and workspace catalog against its OWN pinned release — a child resolving\n * via record-first never fails for being older than the parent's latest.\n */\nexport function platformCompatViolations(manifest: Manifest, configDir: string): string[] {\n const root = findWorkspaceRoot(configDir)?.dir ?? configDir;\n const violations = checkPlatformCompat(manifest, {\n platformVersion: readInstalledFrameworkVersion(configDir, \"everything-dev\"),\n catalog: readWorkspaceCatalog(root),\n });\n return violations.map(\n (violation) =>\n `${violation.message} — run \\`bos upgrade\\` to realign your platform pin with \\`bos deploy\\``,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,eAAsB,gCAAgC,OAKzB;CAM3B,QAAO,MALgB,wBAAwB;EAC7C,WAAW,MAAM;EACjB,aAAa,MAAM;EACnB,GAAG,MAAM;CACX,CAAC,EACc,EAAE,YAAY;AAC/B;;;;;;;;;;;AAmBA,SAAgB,wBAAwB,OAIvB;CAOf,OAAO,EAAE,SANO,sBAAsB;EACpC,QAAQ,MAAM;EACd,gBAAgB,MAAM;EACtB,SAAS,MAAM,SAAS;EACxB,MAAM;CACR,CACwB,CAAC,CAAC,QAAQ;AACpC;;;;;;;;AA8BA,eAAsB,mBACpB,OACgC;CAChC,MAAM,aAAuB,CAC3B,GAAI,MAAM,0BAA0B,MAAM,eAAe;EACvD,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;EACxD,GAAI,MAAM,kBAAkB,EAAE,iBAAiB,MAAM,gBAAgB,IAAI,CAAC;CAC5E,CAAC,CACH;CACA,IAAI,OAAO,MAAM,eAAe,YAAY,YAAY,MAAM,iBAC5D,WAAW,KAAK,GAAG,yBAAyB,MAAM,iBAAiB,MAAM,SAAS,CAAC;CAErF,OAAO;EAAE,IAAI,WAAW,WAAW;EAAG;CAAW;AACnD;;;;;;;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