everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
1 lines • 16.3 kB
Source Map (JSON)
{"version":3,"file":"manifest.cjs","names":["FRAMEWORK_OWNED_SYNC_FILES","AGENT_SYNC_GLOBS","relative","join","existsSync","readFileSync","createHash","SHARED_DEP_SPECS","shareConfigFor","PlatformReleaseManifestSchema","fileURLToPath","compareSemver","satisfiesConstraint","Context","Layer"],"sources":["../../../src/services/platform/manifest.ts"],"sourcesContent":["/**\n * The platform release manifest (ADR 0034) — schema, composer, inventory,\n * registry key helpers, and the compat check. One composer feeds both publish\n * homes (FastKV pointer slot + in-image staging); the image digest is\n * deliberately absent — it derives from the tags at deploy preflight. The\n * homes' one known divergence is the compat floor: publisher-side (previous\n * release) in FastKV, own version — failing closed — in the image, which\n * cannot read the registry inside the build.\n *\n * Resolution (the machine) and the cache live in `registry/resolution.ts` and\n * `registry/cache.ts`; the service below re-exposes the resolver through the\n * machine's compatibility adapter.\n */\nimport { createHash } from \"node:crypto\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Context, Layer } from \"effect\";\nimport {\n SHARED_DEP_SPECS,\n type SharedDependencyConfig,\n shareConfigFor,\n} from \"every-plugin/shared-deps-spec\";\nimport { glob } from \"glob\";\nimport { compareSemver, satisfiesConstraint } from \"../../utils/semver\";\nimport { resolvePlatformManifest } from \"../registry/resolution\";\nimport { AGENT_SYNC_GLOBS, FRAMEWORK_OWNED_SYNC_FILES } from \"../scaffold/ownership\";\n\nexport type {\n PlatformManifestCache,\n ResolvedPlatformManifest,\n} from \"../registry/resolution\";\nexport {\n type ResolvePlatformManifestOptions,\n resolvePlatformManifest,\n walkExtendsChain,\n} from \"../registry/resolution\";\nexport { type PlatformReleaseManifest, PlatformReleaseManifestSchema } from \"./manifest-schema\";\n\nimport { type PlatformReleaseManifest, PlatformReleaseManifestSchema } from \"./manifest-schema\";\n\n/** One recorded release slot (see {@link PlatformReleaseManifestSchema.slots}). */\nexport interface ReleaseSlotRecord {\n base: string;\n pin: { manifest: string; integrity: string };\n}\n\nexport interface TemplateInventoryEntry {\n path: string;\n sha256: string;\n}\n\n// The release-pointer key derivations moved to `registry/pointer.ts` (the\n// pre-cutover wire quarantine); the post-cutover keys live in the key model\n// (`registry/keys.ts`).\n\n/**\n * The template-source file set a release inventory hashes: the ownership\n * inventory's static paths, the agent-sync globs, and the per-plugin template\n * scaffolding (`plugins/_template/*` — the sources of the per-plugin sync\n * patterns). Files absent from the release source are skipped, mirroring\n * sync's transitional tolerance.\n */\nconst TEMPLATE_SCAFFOLD_SOURCES = [\n \"plugins/_template/rspack.config.js\",\n \"plugins/_template/tsconfig.json\",\n \"plugins/_template/tests/types.d.ts\",\n];\n\nfunction templateSourcePaths(sourceDir: string): string[] {\n const paths = new Set<string>([...FRAMEWORK_OWNED_SYNC_FILES, ...TEMPLATE_SCAFFOLD_SOURCES]);\n for (const match of glob.sync(AGENT_SYNC_GLOBS, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n ignore: [\"**/node_modules/**\", \"**/.git/**\", \"**/dist/**\", \"**/.bos/**\"],\n })) {\n paths.add(relative(sourceDir, join(sourceDir, match)));\n }\n return [...paths].sort();\n}\n\nexport function computeTemplateInventory(sourceDir: string): TemplateInventoryEntry[] {\n const inventory: TemplateInventoryEntry[] = [];\n for (const relativeFilePath of templateSourcePaths(sourceDir)) {\n const fullPath = join(sourceDir, relativeFilePath);\n if (!existsSync(fullPath)) continue;\n try {\n const content = readFileSync(fullPath);\n inventory.push({\n path: relativeFilePath,\n sha256: createHash(\"sha256\").update(content).digest(\"hex\"),\n });\n } catch {\n // unreadable at compose time → not part of the release inventory\n }\n }\n return inventory.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));\n}\n\nexport function composeSharedDepsFromCatalog(\n catalog: Record<string, string>,\n): Record<string, SharedDependencyConfig> {\n const deps: Record<string, SharedDependencyConfig> = {};\n for (const spec of SHARED_DEP_SPECS) {\n const version = catalog[spec.name];\n if (!version) continue;\n deps[spec.name] = { version, ...shareConfigFor(spec, version) };\n }\n return deps;\n}\n\nexport interface ComposePlatformReleaseManifestInputs {\n frameworkVersion: string;\n everyPluginVersion: string;\n gitSha?: string;\n imageRef: string;\n catalog: Record<string, string>;\n templateInventory: TemplateInventoryEntry[];\n compatMinChild: string;\n /** The release's own slot-pin map — sorted here so identical payloads\n * compose identical manifest bytes across machines (the burned-version\n * guard compares serialized bytes). */\n slots?: Record<string, ReleaseSlotRecord>;\n}\n\nexport function composePlatformReleaseManifest(\n inputs: ComposePlatformReleaseManifestInputs,\n): PlatformReleaseManifest {\n // The manifest carries only the derivable tag — the exact version tag the\n // tag scheme pushes for semver releases (ADR 0021). Sha-tags are git facts\n // an image build cannot see; derivation (`ref@v<version>` → digest) keys off\n // the version tag so both publish homes stay byte-identical without any\n // build-context plumbing.\n const semver = parseSemver(inputs.frameworkVersion.trim());\n const tags = semver\n ? [\n `v${semver.major}.${semver.minor}.${semver.patch}${semver.prerelease ? `-${semver.prerelease}` : \"\"}`,\n ]\n : [];\n const slots = inputs.slots\n ? Object.fromEntries(Object.entries(inputs.slots).sort(([a], [b]) => (a < b ? -1 : 1)))\n : undefined;\n return PlatformReleaseManifestSchema.parse({\n schemaVersion: 1,\n kind: \"everything-dev/platform-manifest\",\n frameworkVersion: inputs.frameworkVersion,\n everyPluginVersion: inputs.everyPluginVersion,\n ...(inputs.gitSha ? { gitSha: inputs.gitSha } : {}),\n image: { ref: inputs.imageRef, tags },\n catalog: inputs.catalog,\n sharedDeps: composeSharedDepsFromCatalog(inputs.catalog),\n templateInventory: inputs.templateInventory,\n compat: { minChild: inputs.compatMinChild },\n ...(slots ? { slots } : {}),\n });\n}\n\n/** The one serializer for both publish homes — byte-identical by construction. */\nexport function serializePlatformReleaseManifest(manifest: PlatformReleaseManifest): string {\n return JSON.stringify(manifest);\n}\n\n/**\n * The in-image copy (ADR 0034 pt 1): generated inside the docker build at\n * `packages/everything-dev/dist/platform-manifest.json`. Resolved relative to\n * this module — the compiled layout is `<pkg>/dist/services/platform/manifest.mjs`\n * (two directory levels up = `<pkg>/dist/`), the source layout is\n * `<pkg>/src/services/platform/manifest.ts` (four levels up = the pnpm parent\n * dir, then `<pkg>/dist/`). Both candidates are tried; absent or unparsable →\n * null.\n */\nexport function readInImagePlatformManifest(): PlatformReleaseManifest | null {\n const moduleFile = fileURLToPath(import.meta.url);\n const candidates = [\n join(moduleFile, \"..\", \"..\", \"platform-manifest.json\"),\n join(moduleFile, \"..\", \"..\", \"..\", \"..\", \"dist\", \"platform-manifest.json\"),\n ];\n for (const path of candidates) {\n try {\n return PlatformReleaseManifestSchema.parse(JSON.parse(readFileSync(path, \"utf-8\")));\n } catch {\n // try the next layout candidate\n }\n }\n return null;\n}\n\nfunction parseSemver(\n version: string,\n): { major: number; minor: number; patch: number; prerelease?: string } | null {\n const match = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(version.trim());\n if (!match) return null;\n return {\n major: Number(match[1]),\n minor: Number(match[2]),\n patch: Number(match[3]),\n ...(match[4] ? { prerelease: match[4] } : {}),\n };\n}\n\nexport interface PlatformCompatSubject {\n /** The child's recorded platform pin / installed framework version. */\n platformVersion?: string;\n catalog: Record<string, string>;\n}\n\nexport interface PlatformCompatViolation {\n kind: \"minChild\" | \"shared-dep\";\n name?: string;\n message: string;\n}\n\n/**\n * The additive compat gate (ADR 0034 pt 5): the child's framework version must\n * sit inside the release's compat window, and strict singletons must agree\n * exactly with the release's pins. A sibling of the federation check — never\n * a relaxation of it.\n */\nexport function checkPlatformCompat(\n manifest: PlatformReleaseManifest,\n subject: PlatformCompatSubject,\n): PlatformCompatViolation[] {\n const violations: PlatformCompatViolation[] = [];\n\n if (subject.platformVersion) {\n if (compareSemver(subject.platformVersion, manifest.compat.minChild) < 0) {\n violations.push({\n kind: \"minChild\",\n message: `platform ${subject.platformVersion} is older than this release's compat floor ${manifest.compat.minChild}`,\n });\n }\n if (compareSemver(subject.platformVersion, manifest.frameworkVersion) > 0) {\n violations.push({\n kind: \"minChild\",\n message: `platform ${subject.platformVersion} is newer than this release ${manifest.frameworkVersion}`,\n });\n }\n }\n\n for (const [name, pin] of Object.entries(manifest.sharedDeps)) {\n const childVersion = subject.catalog[name];\n if (pin.strictVersion) {\n if (!childVersion) {\n violations.push({\n kind: \"shared-dep\",\n name,\n message: `strict singleton \"${name}\" is missing from the child catalog (release pins ${pin.version})`,\n });\n continue;\n }\n if (childVersion !== pin.version) {\n violations.push({\n kind: \"shared-dep\",\n name,\n message: `strict singleton \"${name}\" is ${childVersion}, the release pins ${pin.version}`,\n });\n }\n continue;\n }\n if (typeof pin.requiredVersion === \"string\" && childVersion) {\n if (!satisfiesConstraint(childVersion, pin.requiredVersion)) {\n violations.push({\n kind: \"shared-dep\",\n name,\n message: `\"${name}\" is ${childVersion}, which does not satisfy the release range ${pin.requiredVersion}`,\n });\n }\n }\n }\n\n return violations;\n}\n\n/**\n * The platform release manifest as a Context.Service: the same \"module is\n * the implementation, the tag is the seam\" shape as FastKVRegistryService —\n * CLI handlers `yield*` the tag; pure and standalone callers keep using the\n * plain functions. Tests provide `Layer.succeed` fakes instead of module\n * mocks. Resolution comes from `registry/resolution.ts` (the machine's\n * compatibility adapter).\n */\nexport class PlatformManifestService extends Context.Service<\n PlatformManifestService,\n {\n resolvePlatformManifest: typeof resolvePlatformManifest;\n composePlatformReleaseManifest: typeof composePlatformReleaseManifest;\n checkPlatformCompat: typeof checkPlatformCompat;\n readInImagePlatformManifest: typeof readInImagePlatformManifest;\n }\n>()(\"everything-dev/platform/manifest\") {\n static readonly Live = Layer.succeed(\n this,\n this.of({\n resolvePlatformManifest,\n composePlatformReleaseManifest,\n checkPlatformCompat,\n readInImagePlatformManifest,\n }),\n );\n}\n\n/**\n * The child-side upgrade-path line (`.scratch/catalog-drift/issues/05`):\n * when the resolved chain head is a NEWER release than this runtime's\n * authored pin, the runtime is servable-but-behind — the dev boot surfaces\n * the upgrade instead of waiting for a load-time skew to explain it. Empty\n * (no notice) when either side is unknown, or the pin is current-or-ahead.\n * Never reads npm: the FastKV pointer only advances when the parent's\n * release leg completed, so \"pin trails pointer\" already implies \"the\n * chain is servable right now\" — no transient mid-train state leaks in.\n */\nexport function chainHeadPinLagNotice(\n headFrameworkVersion: string | undefined,\n authoredPlatformPin: string | undefined,\n): string | undefined {\n if (!headFrameworkVersion || !authoredPlatformPin) return undefined;\n if (compareSemver(headFrameworkVersion, authoredPlatformPin) <= 0) return undefined;\n return (\n `platform upgrade for this runtime: the chain head advanced to ${headFrameworkVersion}, ` +\n `this runtime pins ${authoredPlatformPin} — run bos upgrade; until then the pinned release ` +\n `keeps resolving the older chain`\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAM,4BAA4B;CAChC;CACA;CACA;AACF;AAEA,SAAS,oBAAoB,WAA6B;CACxD,MAAM,wBAAQ,IAAI,IAAY,CAAC,GAAGA,8CAA4B,GAAG,yBAAyB,CAAC;CAC3F,KAAK,MAAM,SAAS,UAAK,KAAKC,oCAAkB;EAC9C,KAAK;EACL,OAAO;EACP,KAAK;EACL,QAAQ;GAAC;GAAsB;GAAc;GAAc;EAAY;CACzE,CAAC,GACC,MAAM,QAAIC,oBAAS,eAAWC,gBAAK,WAAW,KAAK,CAAC,CAAC;CAEvD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK;AACzB;AAEA,SAAgB,yBAAyB,WAA6C;CACpF,MAAM,YAAsC,CAAC;CAC7C,KAAK,MAAM,oBAAoB,oBAAoB,SAAS,GAAG;EAC7D,MAAM,eAAWA,gBAAK,WAAW,gBAAgB;EACjD,IAAI,KAACC,oBAAW,QAAQ,GAAG;EAC3B,IAAI;GACF,MAAM,cAAUC,sBAAa,QAAQ;GACrC,UAAU,KAAK;IACb,MAAM;IACN,YAAQC,wBAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,C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