UNPKG

everything-dev

Version:

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

1 lines • 4.58 kB
{"version":3,"file":"slot.cjs","names":["UI_REMOTE_SERVER_ENTRY_FILENAME","UI_REMOTE_ENTRY_FILENAME"],"sources":["../../src/ui/slot.ts"],"sourcesContent":["import {\n UI_REMOTE_ENTRY_FILENAME,\n UI_REMOTE_SERVER_ENTRY_FILENAME,\n} from \"every-plugin/ui/manifest\";\nimport type { BosEnv } from \"../merge\";\n\n/**\n * The host's entry-URL SlotResolver: one pure derivation from a stamped\n * config slot to the URLs each surface loads. `EntrySlot` is structural —\n * the version-manifest derivation (atomic-deploys 04) stamps exactly these\n * fields onto `RuntimeConfig` slots, so they satisfy it as-is. Each surface\n * of `entryUrls` resolves (and throws) lazily — a caller reading only `web`\n * never trips the ssr surface's resolution, and vice versa.\n */\nexport interface EntrySlot {\n /** slot identity, verbatim in resolution errors */\n name: string;\n url?: string;\n /** browser-facing base (ADR 0011) — the base rule is publicUrl ?? url, inside this module */\n publicUrl?: string;\n /** pin-derived hashed browser entry (absent in development) */\n entryUrl?: string;\n ssrUrl?: string;\n /** pin-derived hashed SSR entry */\n ssrEntryUrl?: string;\n integrity?: string;\n ssrIntegrity?: string;\n /** dev-only freshness token (localUiRemoteEntry's container mtime) */\n containerVersion?: string;\n /** pin-derived hashed browser manifest — absent for local slots, which no\n * pin derivation ever stamps (atomic-deploys 08) and the resolver drops\n * even if one were stamped */\n browserManifestUrl?: string;\n localPath?: string;\n}\n\nexport interface EntryUrls {\n /** browser script src / registration entry — bustered fixed name in dev, hashed in prod */\n readonly web: string;\n /** server container entry; undefined when the slot has no SSR coordinates */\n readonly ssr?: string;\n /** pin-derived hashed mf-manifest; undefined ⟺ local slot (atomic-deploys 08, STRUCTURAL) */\n readonly browserManifest?: string;\n}\n\nconst trimBase = (value: string | undefined): string => (value ?? \"\").replace(/\\/$/, \"\");\n\nconst withBuster = (url: string, buster: string | undefined): string =>\n buster ? `${url}?v=${encodeURIComponent(buster)}` : url;\n\nfunction requireEntry(\n entryUrl: string | undefined,\n env: BosEnv,\n slot: string,\n surface: string,\n devFixed: string,\n): string {\n if (entryUrl) return entryUrl;\n if (env === \"development\") return devFixed;\n throw new Error(\n `slot \"${slot}\" has no derived ${surface} entry — pins resolve it from the version manifest ` +\n `(the fixed dev name is development-only)`,\n );\n}\n\nfunction ssrEntryUrl(slot: EntrySlot, env: BosEnv): string | undefined {\n if (slot.ssrEntryUrl) return slot.ssrEntryUrl;\n if (env === \"development\") {\n return slot.ssrUrl\n ? withBuster(\n `${trimBase(slot.ssrUrl)}/${UI_REMOTE_SERVER_ENTRY_FILENAME}`,\n slot.ssrIntegrity ?? slot.containerVersion,\n )\n : undefined;\n }\n if (!slot.ssrUrl) return undefined;\n throw new Error(\n `slot \"${slot.name}\" has no derived ssr entry — pins resolve it from the version manifest ` +\n `(the fixed dev name is development-only)`,\n );\n}\n\nexport function entryUrls(slot: EntrySlot, env: BosEnv): EntryUrls {\n const base = trimBase(slot.publicUrl ?? slot.url);\n return {\n get web() {\n return requireEntry(\n slot.entryUrl,\n env,\n slot.name,\n \"web\",\n withBuster(`${base}/${UI_REMOTE_ENTRY_FILENAME}`, slot.integrity),\n );\n },\n get ssr() {\n return ssrEntryUrl(slot, env);\n },\n get browserManifest() {\n return slot.localPath ? undefined : slot.browserManifestUrl;\n },\n };\n}\n"],"mappings":";;;AA6CA,MAAM,YAAY,WAAuC,SAAS,GAAE,CAAE,QAAQ,OAAO,EAAE;AAEvF,MAAM,cAAc,KAAa,WAC/B,SAAS,GAAG,IAAI,KAAK,mBAAmB,MAAM,MAAM;AAEtD,SAAS,aACP,UACA,KACA,MACA,SACA,UACQ;CACR,IAAI,UAAU,OAAO;CACrB,IAAI,QAAQ,eAAe,OAAO;CAClC,MAAM,IAAI,MACR,SAAS,KAAK,mBAAmB,QAAQ,4FAE3C;AACF;AAEA,SAAS,YAAY,MAAiB,KAAiC;CACrE,IAAI,KAAK,aAAa,OAAO,KAAK;CAClC,IAAI,QAAQ,eACV,OAAO,KAAK,SACR,WACE,GAAG,SAAS,KAAK,MAAM,EAAE,GAAGA,4DAC5B,KAAK,gBAAgB,KAAK,gBAC5B,IACA;CAEN,IAAI,CAAC,KAAK,QAAQ,OAAO;CACzB,MAAM,IAAI,MACR,SAAS,KAAK,KAAK,gHAErB;AACF;AAEA,SAAgB,UAAU,MAAiB,KAAwB;CACjE,MAAM,OAAO,SAAS,KAAK,aAAa,KAAK,GAAG;CAChD,OAAO;EACL,IAAI,MAAM;GACR,OAAO,aACL,KAAK,UACL,KACA,KAAK,MACL,OACA,WAAW,GAAG,KAAK,GAAGC,qDAA4B,KAAK,SAAS,CAClE;EACF;EACA,IAAI,MAAM;GACR,OAAO,YAAY,MAAM,GAAG;EAC9B;EACA,IAAI,kBAAkB;GACpB,OAAO,KAAK,YAAY,SAAY,KAAK;EAC3C;CACF;AACF"}