everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
34 lines (32 loc) • 1.49 kB
JavaScript
import { UI_REMOTE_ENTRY_FILENAME, UI_REMOTE_SERVER_ENTRY_FILENAME } from "every-plugin/ui/manifest";
//#region src/ui/slot.ts
const trimBase = (value) => (value ?? "").replace(/\/$/, "");
const withBuster = (url, buster) => buster ? `${url}?v=${encodeURIComponent(buster)}` : url;
function requireEntry(entryUrl, env, slot, surface, devFixed) {
if (entryUrl) return entryUrl;
if (env === "development") return devFixed;
throw new Error(`slot "${slot}" has no derived ${surface} entry — pins resolve it from the version manifest (the fixed dev name is development-only)`);
}
function ssrEntryUrl(slot, env) {
if (slot.ssrEntryUrl) return slot.ssrEntryUrl;
if (env === "development") return slot.ssrUrl ? withBuster(`${trimBase(slot.ssrUrl)}/${UI_REMOTE_SERVER_ENTRY_FILENAME}`, slot.ssrIntegrity ?? slot.containerVersion) : void 0;
if (!slot.ssrUrl) return void 0;
throw new Error(`slot "${slot.name}" has no derived ssr entry — pins resolve it from the version manifest (the fixed dev name is development-only)`);
}
function entryUrls(slot, env) {
const base = trimBase(slot.publicUrl ?? slot.url);
return {
get web() {
return requireEntry(slot.entryUrl, env, slot.name, "web", withBuster(`${base}/${UI_REMOTE_ENTRY_FILENAME}`, slot.integrity));
},
get ssr() {
return ssrEntryUrl(slot, env);
},
get browserManifest() {
return slot.localPath ? void 0 : slot.browserManifestUrl;
}
};
}
//#endregion
export { entryUrls };
//# sourceMappingURL=slot.mjs.map