UNPKG

everything-dev

Version:

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

223 lines (221 loc) • 9.88 kB
const require_semver = require("../../utils/semver.cjs"); const require_manifest_schema = require("./manifest-schema.cjs"); const require_resolution = require("../registry/resolution.cjs"); const require_ownership = require("../scaffold/ownership.cjs"); let node_fs = require("node:fs"); let node_path = require("node:path"); let node_url = require("node:url"); let effect = require("effect"); let node_crypto = require("node:crypto"); let every_plugin_shared_deps_spec = require("every-plugin/shared-deps-spec"); let glob = require("glob"); //#region src/services/platform/manifest.ts /** * The platform release manifest (ADR 0034) — schema, composer, inventory, * registry key helpers, and the compat check. One composer feeds both publish * homes (FastKV pointer slot + in-image staging); the image digest is * deliberately absent — it derives from the tags at deploy preflight. The * homes' one known divergence is the compat floor: publisher-side (previous * release) in FastKV, own version — failing closed — in the image, which * cannot read the registry inside the build. * * Resolution (the machine) and the cache live in `registry/resolution.ts` and * `registry/cache.ts`; the service below re-exposes the resolver through the * machine's compatibility adapter. */ /** * The template-source file set a release inventory hashes: the ownership * inventory's static paths, the agent-sync globs, and the per-plugin template * scaffolding (`plugins/_template/*` — the sources of the per-plugin sync * patterns). Files absent from the release source are skipped, mirroring * sync's transitional tolerance. */ const TEMPLATE_SCAFFOLD_SOURCES = [ "plugins/_template/rspack.config.js", "plugins/_template/tsconfig.json", "plugins/_template/tests/types.d.ts" ]; function templateSourcePaths(sourceDir) { const paths = /* @__PURE__ */ new Set([...require_ownership.FRAMEWORK_OWNED_SYNC_FILES, ...TEMPLATE_SCAFFOLD_SOURCES]); for (const match of glob.glob.sync(require_ownership.AGENT_SYNC_GLOBS, { cwd: sourceDir, nodir: true, dot: true, ignore: [ "**/node_modules/**", "**/.git/**", "**/dist/**", "**/.bos/**" ] })) paths.add((0, node_path.relative)(sourceDir, (0, node_path.join)(sourceDir, match))); return [...paths].sort(); } function computeTemplateInventory(sourceDir) { const inventory = []; for (const relativeFilePath of templateSourcePaths(sourceDir)) { const fullPath = (0, node_path.join)(sourceDir, relativeFilePath); if (!(0, node_fs.existsSync)(fullPath)) continue; try { const content = (0, node_fs.readFileSync)(fullPath); inventory.push({ path: relativeFilePath, sha256: (0, node_crypto.createHash)("sha256").update(content).digest("hex") }); } catch {} } return inventory.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0); } function composeSharedDepsFromCatalog(catalog) { const deps = {}; for (const spec of every_plugin_shared_deps_spec.SHARED_DEP_SPECS) { const version = catalog[spec.name]; if (!version) continue; deps[spec.name] = { version, ...(0, every_plugin_shared_deps_spec.shareConfigFor)(spec, version) }; } return deps; } function composePlatformReleaseManifest(inputs) { const semver = parseSemver(inputs.frameworkVersion.trim()); const tags = semver ? [`v${semver.major}.${semver.minor}.${semver.patch}${semver.prerelease ? `-${semver.prerelease}` : ""}`] : []; const slots = inputs.slots ? Object.fromEntries(Object.entries(inputs.slots).sort(([a], [b]) => a < b ? -1 : 1)) : void 0; return require_manifest_schema.PlatformReleaseManifestSchema.parse({ schemaVersion: 1, kind: "everything-dev/platform-manifest", frameworkVersion: inputs.frameworkVersion, everyPluginVersion: inputs.everyPluginVersion, ...inputs.gitSha ? { gitSha: inputs.gitSha } : {}, image: { ref: inputs.imageRef, tags }, catalog: inputs.catalog, sharedDeps: composeSharedDepsFromCatalog(inputs.catalog), templateInventory: inputs.templateInventory, compat: { minChild: inputs.compatMinChild }, ...slots ? { slots } : {} }); } /** The one serializer for both publish homes — byte-identical by construction. */ function serializePlatformReleaseManifest(manifest) { return JSON.stringify(manifest); } /** * The in-image copy (ADR 0034 pt 1): generated inside the docker build at * `packages/everything-dev/dist/platform-manifest.json`. Resolved relative to * this module — the compiled layout is `<pkg>/dist/services/platform/manifest.mjs` * (two directory levels up = `<pkg>/dist/`), the source layout is * `<pkg>/src/services/platform/manifest.ts` (four levels up = the pnpm parent * dir, then `<pkg>/dist/`). Both candidates are tried; absent or unparsable → * null. */ function readInImagePlatformManifest() { const moduleFile = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href); const candidates = [(0, node_path.join)(moduleFile, "..", "..", "platform-manifest.json"), (0, node_path.join)(moduleFile, "..", "..", "..", "..", "dist", "platform-manifest.json")]; for (const path of candidates) try { return require_manifest_schema.PlatformReleaseManifestSchema.parse(JSON.parse((0, node_fs.readFileSync)(path, "utf-8"))); } catch {} return null; } function parseSemver(version) { const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(version.trim()); if (!match) return null; return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), ...match[4] ? { prerelease: match[4] } : {} }; } /** * The additive compat gate (ADR 0034 pt 5): the child's framework version must * sit inside the release's compat window, and strict singletons must agree * exactly with the release's pins. A sibling of the federation check — never * a relaxation of it. */ function checkPlatformCompat(manifest, subject) { const violations = []; if (subject.platformVersion) { if (require_semver.compareSemver(subject.platformVersion, manifest.compat.minChild) < 0) violations.push({ kind: "minChild", message: `platform ${subject.platformVersion} is older than this release's compat floor ${manifest.compat.minChild}` }); if (require_semver.compareSemver(subject.platformVersion, manifest.frameworkVersion) > 0) violations.push({ kind: "minChild", message: `platform ${subject.platformVersion} is newer than this release ${manifest.frameworkVersion}` }); } for (const [name, pin] of Object.entries(manifest.sharedDeps)) { const childVersion = subject.catalog[name]; if (pin.strictVersion) { if (!childVersion) { violations.push({ kind: "shared-dep", name, message: `strict singleton "${name}" is missing from the child catalog (release pins ${pin.version})` }); continue; } if (childVersion !== pin.version) violations.push({ kind: "shared-dep", name, message: `strict singleton "${name}" is ${childVersion}, the release pins ${pin.version}` }); continue; } if (typeof pin.requiredVersion === "string" && childVersion) { if (!require_semver.satisfiesConstraint(childVersion, pin.requiredVersion)) violations.push({ kind: "shared-dep", name, message: `"${name}" is ${childVersion}, which does not satisfy the release range ${pin.requiredVersion}` }); } } return violations; } /** * The platform release manifest as a Context.Service: the same "module is * the implementation, the tag is the seam" shape as FastKVRegistryService — * CLI handlers `yield*` the tag; pure and standalone callers keep using the * plain functions. Tests provide `Layer.succeed` fakes instead of module * mocks. Resolution comes from `registry/resolution.ts` (the machine's * compatibility adapter). */ var PlatformManifestService = class extends effect.Context.Service()("everything-dev/platform/manifest") { static Live = effect.Layer.succeed(this, this.of({ resolvePlatformManifest: require_resolution.resolvePlatformManifest, composePlatformReleaseManifest, checkPlatformCompat, readInImagePlatformManifest })); }; /** * The child-side upgrade-path line (`.scratch/catalog-drift/issues/05`): * when the resolved chain head is a NEWER release than this runtime's * authored pin, the runtime is servable-but-behind — the dev boot surfaces * the upgrade instead of waiting for a load-time skew to explain it. Empty * (no notice) when either side is unknown, or the pin is current-or-ahead. * Never reads npm: the FastKV pointer only advances when the parent's * release leg completed, so "pin trails pointer" already implies "the * chain is servable right now" — no transient mid-train state leaks in. */ function chainHeadPinLagNotice(headFrameworkVersion, authoredPlatformPin) { if (!headFrameworkVersion || !authoredPlatformPin) return void 0; if (require_semver.compareSemver(headFrameworkVersion, authoredPlatformPin) <= 0) return void 0; return `platform upgrade for this runtime: the chain head advanced to ${headFrameworkVersion}, this runtime pins ${authoredPlatformPin} — run bos upgrade; until then the pinned release keeps resolving the older chain`; } //#endregion exports.PlatformManifestService = PlatformManifestService; exports.PlatformReleaseManifestSchema = require_manifest_schema.PlatformReleaseManifestSchema; exports.chainHeadPinLagNotice = chainHeadPinLagNotice; exports.checkPlatformCompat = checkPlatformCompat; exports.composePlatformReleaseManifest = composePlatformReleaseManifest; exports.composeSharedDepsFromCatalog = composeSharedDepsFromCatalog; exports.computeTemplateInventory = computeTemplateInventory; exports.readInImagePlatformManifest = readInImagePlatformManifest; exports.resolvePlatformManifest = require_resolution.resolvePlatformManifest; exports.serializePlatformReleaseManifest = serializePlatformReleaseManifest; exports.walkExtendsChain = require_resolution.walkExtendsChain; //# sourceMappingURL=manifest.cjs.map