@module-federation/sdk 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/dist/_virtual/_rolldown/runtime.cjs +19 -0
- package/dist/_virtual/_rolldown/runtime.js +18 -0
- package/dist/constant.cjs +70 -0
- package/dist/constant.cjs.map +1 -0
- package/dist/constant.d.ts +53 -0
- package/dist/constant.js +55 -0
- package/dist/constant.js.map +1 -0
- package/dist/createModuleFederationConfig.cjs +9 -0
- package/dist/createModuleFederationConfig.cjs.map +1 -0
- package/dist/createModuleFederationConfig.d.ts +6 -0
- package/dist/createModuleFederationConfig.js +8 -0
- package/dist/createModuleFederationConfig.js.map +1 -0
- package/dist/dom.cjs +180 -0
- package/dist/dom.cjs.map +1 -0
- package/dist/dom.d.ts +33 -0
- package/dist/dom.js +176 -0
- package/dist/dom.js.map +1 -0
- package/dist/env.cjs +34 -0
- package/dist/env.cjs.map +1 -0
- package/dist/env.d.ts +12 -0
- package/dist/env.js +30 -0
- package/dist/env.js.map +1 -0
- package/dist/generateSnapshotFromManifest.cjs +138 -0
- package/dist/generateSnapshotFromManifest.cjs.map +1 -0
- package/dist/generateSnapshotFromManifest.d.ts +20 -0
- package/dist/generateSnapshotFromManifest.js +134 -0
- package/dist/generateSnapshotFromManifest.js.map +1 -0
- package/dist/index.cjs +104 -0
- package/dist/index.d.ts +21 -1
- package/dist/index.js +17 -0
- package/dist/logger.cjs +129 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.ts +34 -0
- package/dist/logger.js +125 -0
- package/dist/logger.js.map +1 -0
- package/dist/node.cjs +122 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.ts +15 -0
- package/dist/node.js +120 -0
- package/dist/node.js.map +1 -0
- package/dist/normalize-webpack-path.cjs +28 -0
- package/dist/normalize-webpack-path.cjs.map +1 -0
- package/dist/normalize-webpack-path.d.ts +10 -1
- package/dist/normalize-webpack-path.js +26 -0
- package/dist/normalize-webpack-path.js.map +1 -0
- package/dist/normalizeOptions.cjs +19 -0
- package/dist/normalizeOptions.cjs.map +1 -0
- package/dist/normalizeOptions.d.ts +5 -0
- package/dist/normalizeOptions.js +18 -0
- package/dist/normalizeOptions.js.map +1 -0
- package/dist/types/common.d.ts +14 -0
- package/dist/types/hooks.d.ts +16 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/manifest.d.ts +34 -0
- package/dist/types/plugins/ConsumeSharedPlugin.cjs +13 -0
- package/dist/types/plugins/ConsumeSharedPlugin.cjs.map +1 -0
- package/dist/types/plugins/ConsumeSharedPlugin.d.ts +109 -0
- package/dist/types/plugins/ConsumeSharedPlugin.js +8 -0
- package/dist/types/plugins/ConsumeSharedPlugin.js.map +1 -0
- package/dist/types/plugins/ContainerPlugin.cjs +13 -0
- package/dist/types/plugins/ContainerPlugin.cjs.map +1 -0
- package/dist/types/plugins/ContainerPlugin.d.ts +42 -0
- package/dist/types/plugins/ContainerPlugin.js +8 -0
- package/dist/types/plugins/ContainerPlugin.js.map +1 -0
- package/dist/types/plugins/ContainerReferencePlugin.cjs +13 -0
- package/dist/types/plugins/ContainerReferencePlugin.cjs.map +1 -0
- package/dist/types/plugins/ContainerReferencePlugin.d.ts +24 -0
- package/dist/types/plugins/ContainerReferencePlugin.js +8 -0
- package/dist/types/plugins/ContainerReferencePlugin.js.map +1 -0
- package/dist/types/plugins/ModuleFederationPlugin.cjs +13 -0
- package/dist/types/plugins/ModuleFederationPlugin.cjs.map +1 -0
- package/dist/types/plugins/ModuleFederationPlugin.d.ts +455 -0
- package/dist/types/plugins/ModuleFederationPlugin.js +8 -0
- package/dist/types/plugins/ModuleFederationPlugin.js.map +1 -0
- package/dist/types/plugins/ProvideSharedPlugin.cjs +13 -0
- package/dist/types/plugins/ProvideSharedPlugin.cjs.map +1 -0
- package/dist/types/plugins/ProvideSharedPlugin.d.ts +97 -0
- package/dist/types/plugins/ProvideSharedPlugin.js +8 -0
- package/dist/types/plugins/ProvideSharedPlugin.js.map +1 -0
- package/dist/types/plugins/SharePlugin.cjs +13 -0
- package/dist/types/plugins/SharePlugin.cjs.map +1 -0
- package/dist/types/plugins/SharePlugin.d.ts +26 -0
- package/dist/types/plugins/SharePlugin.js +8 -0
- package/dist/types/plugins/SharePlugin.js.map +1 -0
- package/dist/types/plugins/index.d.ts +6 -0
- package/dist/types/snapshot.d.ts +81 -0
- package/dist/types/stats.d.ts +101 -0
- package/dist/utils.cjs +127 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/{src/utils.d.ts → utils.d.ts} +7 -3
- package/dist/utils.js +116 -0
- package/dist/utils.js.map +1 -0
- package/package.json +14 -7
- package/dist/index.cjs.cjs +0 -1032
- package/dist/index.cjs.cjs.map +0 -1
- package/dist/index.cjs.d.ts +0 -1
- package/dist/index.esm.js +0 -978
- package/dist/index.esm.js.map +0 -1
- package/dist/normalize-webpack-path.cjs.cjs +0 -42
- package/dist/normalize-webpack-path.cjs.cjs.map +0 -1
- package/dist/normalize-webpack-path.cjs.d.ts +0 -1
- package/dist/normalize-webpack-path.esm.js +0 -39
- package/dist/normalize-webpack-path.esm.js.map +0 -1
- package/dist/src/constant.d.ts +0 -49
- package/dist/src/createModuleFederationConfig.d.ts +0 -2
- package/dist/src/dom.d.ts +0 -29
- package/dist/src/env.d.ts +0 -8
- package/dist/src/generateSnapshotFromManifest.d.ts +0 -15
- package/dist/src/index.d.ts +0 -11
- package/dist/src/logger.d.ts +0 -32
- package/dist/src/node.d.ts +0 -11
- package/dist/src/normalize-webpack-path.d.ts +0 -5
- package/dist/src/normalizeOptions.d.ts +0 -1
- package/dist/src/types/common.d.ts +0 -10
- package/dist/src/types/hooks.d.ts +0 -12
- package/dist/src/types/index.d.ts +0 -6
- package/dist/src/types/manifest.d.ts +0 -29
- package/dist/src/types/plugins/ContainerPlugin.d.ts +0 -32
- package/dist/src/types/plugins/ContainerReferencePlugin.d.ts +0 -15
- package/dist/src/types/plugins/ModuleFederationPlugin.d.ts +0 -425
- package/dist/src/types/plugins/SharePlugin.d.ts +0 -21
- package/dist/src/types/plugins/index.d.ts +0 -4
- package/dist/src/types/snapshot.d.ts +0 -77
- package/dist/src/types/stats.d.ts +0 -97
package/dist/dom.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { warn } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/dom.ts
|
|
4
|
+
async function safeWrapper(callback, disableWarn) {
|
|
5
|
+
try {
|
|
6
|
+
return await callback();
|
|
7
|
+
} catch (e) {
|
|
8
|
+
!disableWarn && warn(e);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function isStaticResourcesEqual(url1, url2) {
|
|
13
|
+
const REG_EXP = /^(https?:)?\/\//i;
|
|
14
|
+
return url1.replace(REG_EXP, "").replace(/\/$/, "") === url2.replace(REG_EXP, "").replace(/\/$/, "");
|
|
15
|
+
}
|
|
16
|
+
function createScript(info) {
|
|
17
|
+
let script = null;
|
|
18
|
+
let needAttach = true;
|
|
19
|
+
let timeout = 2e4;
|
|
20
|
+
let timeoutId;
|
|
21
|
+
const scripts = document.getElementsByTagName("script");
|
|
22
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
23
|
+
const s = scripts[i];
|
|
24
|
+
const scriptSrc = s.getAttribute("src");
|
|
25
|
+
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
26
|
+
script = s;
|
|
27
|
+
needAttach = false;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (!script) {
|
|
32
|
+
const attrs = info.attrs;
|
|
33
|
+
script = document.createElement("script");
|
|
34
|
+
script.type = attrs?.["type"] === "module" ? "module" : "text/javascript";
|
|
35
|
+
let createScriptRes = void 0;
|
|
36
|
+
if (info.createScriptHook) {
|
|
37
|
+
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
38
|
+
if (createScriptRes instanceof HTMLScriptElement) script = createScriptRes;
|
|
39
|
+
else if (typeof createScriptRes === "object") {
|
|
40
|
+
if ("script" in createScriptRes && createScriptRes.script) script = createScriptRes.script;
|
|
41
|
+
if ("timeout" in createScriptRes && createScriptRes.timeout) timeout = createScriptRes.timeout;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!script.src) script.src = info.url;
|
|
45
|
+
if (attrs && !createScriptRes) Object.keys(attrs).forEach((name) => {
|
|
46
|
+
if (script) {
|
|
47
|
+
if (name === "async" || name === "defer") script[name] = attrs[name];
|
|
48
|
+
else if (!script.getAttribute(name)) script.setAttribute(name, attrs[name]);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
let executionError = null;
|
|
53
|
+
const executionErrorHandler = typeof window !== "undefined" ? (evt) => {
|
|
54
|
+
if (evt.filename && isStaticResourcesEqual(evt.filename, info.url)) {
|
|
55
|
+
const err = /* @__PURE__ */ new Error(`ScriptExecutionError: Script "${info.url}" loaded but threw a runtime error during execution: ${evt.message} (${evt.filename}:${evt.lineno}:${evt.colno})`);
|
|
56
|
+
err.name = "ScriptExecutionError";
|
|
57
|
+
executionError = err;
|
|
58
|
+
}
|
|
59
|
+
} : null;
|
|
60
|
+
if (executionErrorHandler) window.addEventListener("error", executionErrorHandler);
|
|
61
|
+
const onScriptComplete = async (prev, event) => {
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
if (executionErrorHandler) window.removeEventListener("error", executionErrorHandler);
|
|
64
|
+
const onScriptCompleteCallback = () => {
|
|
65
|
+
if (event?.type === "error") {
|
|
66
|
+
const networkError = /* @__PURE__ */ new Error(`ScriptNetworkError: Failed to load script "${info.url}" - the script URL is unreachable or the server returned an error (network failure, 404, CORS, etc.)`);
|
|
67
|
+
networkError.name = "ScriptNetworkError";
|
|
68
|
+
info?.onErrorCallback && info?.onErrorCallback(networkError);
|
|
69
|
+
} else if (executionError) info?.onErrorCallback && info?.onErrorCallback(executionError);
|
|
70
|
+
else info?.cb && info?.cb();
|
|
71
|
+
};
|
|
72
|
+
if (script) {
|
|
73
|
+
script.onerror = null;
|
|
74
|
+
script.onload = null;
|
|
75
|
+
safeWrapper(() => {
|
|
76
|
+
const { needDeleteScript = true } = info;
|
|
77
|
+
if (needDeleteScript) script?.parentNode && script.parentNode.removeChild(script);
|
|
78
|
+
});
|
|
79
|
+
if (prev && typeof prev === "function") {
|
|
80
|
+
const result = prev(event);
|
|
81
|
+
if (result instanceof Promise) {
|
|
82
|
+
const res = await result;
|
|
83
|
+
onScriptCompleteCallback();
|
|
84
|
+
return res;
|
|
85
|
+
}
|
|
86
|
+
onScriptCompleteCallback();
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
onScriptCompleteCallback();
|
|
91
|
+
};
|
|
92
|
+
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
93
|
+
script.onload = onScriptComplete.bind(null, script.onload);
|
|
94
|
+
timeoutId = setTimeout(() => {
|
|
95
|
+
onScriptComplete(null, /* @__PURE__ */ new Error(`Remote script "${info.url}" time-outed.`));
|
|
96
|
+
}, timeout);
|
|
97
|
+
return {
|
|
98
|
+
script,
|
|
99
|
+
needAttach
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function createLink(info) {
|
|
103
|
+
let link = null;
|
|
104
|
+
let needAttach = true;
|
|
105
|
+
const links = document.getElementsByTagName("link");
|
|
106
|
+
for (let i = 0; i < links.length; i++) {
|
|
107
|
+
const l = links[i];
|
|
108
|
+
const linkHref = l.getAttribute("href");
|
|
109
|
+
const linkRel = l.getAttribute("rel");
|
|
110
|
+
if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
|
|
111
|
+
link = l;
|
|
112
|
+
needAttach = false;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!link) {
|
|
117
|
+
link = document.createElement("link");
|
|
118
|
+
link.setAttribute("href", info.url);
|
|
119
|
+
let createLinkRes = void 0;
|
|
120
|
+
const attrs = info.attrs;
|
|
121
|
+
if (info.createLinkHook) {
|
|
122
|
+
createLinkRes = info.createLinkHook(info.url, attrs);
|
|
123
|
+
if (createLinkRes instanceof HTMLLinkElement) link = createLinkRes;
|
|
124
|
+
}
|
|
125
|
+
if (attrs && !createLinkRes) Object.keys(attrs).forEach((name) => {
|
|
126
|
+
if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const onLinkComplete = (prev, event) => {
|
|
130
|
+
const onLinkCompleteCallback = () => {
|
|
131
|
+
if (event?.type === "error") info?.onErrorCallback && info?.onErrorCallback(event);
|
|
132
|
+
else info?.cb && info?.cb();
|
|
133
|
+
};
|
|
134
|
+
if (link) {
|
|
135
|
+
link.onerror = null;
|
|
136
|
+
link.onload = null;
|
|
137
|
+
safeWrapper(() => {
|
|
138
|
+
const { needDeleteLink = true } = info;
|
|
139
|
+
if (needDeleteLink) link?.parentNode && link.parentNode.removeChild(link);
|
|
140
|
+
});
|
|
141
|
+
if (prev) {
|
|
142
|
+
const res = prev(event);
|
|
143
|
+
onLinkCompleteCallback();
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
onLinkCompleteCallback();
|
|
148
|
+
};
|
|
149
|
+
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
150
|
+
link.onload = onLinkComplete.bind(null, link.onload);
|
|
151
|
+
return {
|
|
152
|
+
link,
|
|
153
|
+
needAttach
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function loadScript(url, info) {
|
|
157
|
+
const { attrs = {}, createScriptHook } = info;
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
const { script, needAttach } = createScript({
|
|
160
|
+
url,
|
|
161
|
+
cb: resolve,
|
|
162
|
+
onErrorCallback: reject,
|
|
163
|
+
attrs: {
|
|
164
|
+
fetchpriority: "high",
|
|
165
|
+
...attrs
|
|
166
|
+
},
|
|
167
|
+
createScriptHook,
|
|
168
|
+
needDeleteScript: true
|
|
169
|
+
});
|
|
170
|
+
needAttach && document.head.appendChild(script);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
export { createLink, createScript, isStaticResourcesEqual, loadScript, safeWrapper };
|
|
176
|
+
//# sourceMappingURL=dom.js.map
|
package/dist/dom.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { CreateScriptHookDom, CreateScriptHookReturnDom } from './types';\nimport { warn } from './utils';\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function safeWrapper<T extends (...args: Array<any>) => any>(\n callback: T,\n disableWarn?: boolean,\n): Promise<ReturnType<T> | undefined> {\n try {\n const res = await callback();\n return res;\n } catch (e) {\n !disableWarn && warn(e);\n return;\n }\n}\n\nexport function isStaticResourcesEqual(url1: string, url2: string): boolean {\n const REG_EXP = /^(https?:)?\\/\\//i;\n // Transform url1 and url2 into relative paths\n const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\\/$/, '');\n const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\\/$/, '');\n // Check if the relative paths are identical\n return relativeUrl1 === relativeUrl2;\n}\n\nexport function createScript(info: {\n url: string;\n cb?: (value: void | PromiseLike<void>) => void;\n onErrorCallback?: (error: Error) => void;\n attrs?: Record<string, any>;\n needDeleteScript?: boolean;\n createScriptHook?: CreateScriptHookDom;\n}): { script: HTMLScriptElement; needAttach: boolean } {\n // Retrieve the existing script element by its src attribute\n let script: HTMLScriptElement | null = null;\n let needAttach = true;\n let timeout = 20000;\n let timeoutId: NodeJS.Timeout;\n const scripts = document.getElementsByTagName('script');\n\n for (let i = 0; i < scripts.length; i++) {\n const s = scripts[i];\n const scriptSrc = s.getAttribute('src');\n if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {\n script = s;\n needAttach = false;\n break;\n }\n }\n\n if (!script) {\n const attrs = info.attrs;\n script = document.createElement('script');\n script.type = attrs?.['type'] === 'module' ? 'module' : 'text/javascript';\n let createScriptRes: CreateScriptHookReturnDom = undefined;\n if (info.createScriptHook) {\n createScriptRes = info.createScriptHook(info.url, info.attrs);\n\n if (createScriptRes instanceof HTMLScriptElement) {\n script = createScriptRes;\n } else if (typeof createScriptRes === 'object') {\n if ('script' in createScriptRes && createScriptRes.script) {\n script = createScriptRes.script;\n }\n if ('timeout' in createScriptRes && createScriptRes.timeout) {\n timeout = createScriptRes.timeout;\n }\n }\n }\n if (!script.src) {\n script.src = info.url;\n }\n if (attrs && !createScriptRes) {\n Object.keys(attrs).forEach((name) => {\n if (script) {\n if (name === 'async' || name === 'defer') {\n script[name] = attrs[name];\n // Attributes that do not exist are considered overridden\n } else if (!script.getAttribute(name)) {\n script.setAttribute(name, attrs[name]);\n }\n }\n });\n }\n }\n\n // Capture JS runtime errors thrown by this script's IIFE during execution.\n // The browser still fires onload even when the script throws, so without this\n // listener the execution error would silently become an uncaught global exception.\n let executionError: Error | null = null;\n const executionErrorHandler =\n typeof window !== 'undefined'\n ? (evt: ErrorEvent) => {\n if (evt.filename && isStaticResourcesEqual(evt.filename, info.url)) {\n const err = new Error(\n `ScriptExecutionError: Script \"${info.url}\" loaded but threw a runtime error during execution: ${evt.message} (${evt.filename}:${evt.lineno}:${evt.colno})`,\n );\n err.name = 'ScriptExecutionError';\n executionError = err;\n }\n }\n : null;\n if (executionErrorHandler) {\n window.addEventListener('error', executionErrorHandler);\n }\n\n const onScriptComplete = async (\n prev: OnErrorEventHandler | GlobalEventHandlers['onload'] | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event: any,\n ): Promise<void> => {\n clearTimeout(timeoutId);\n if (executionErrorHandler) {\n window.removeEventListener('error', executionErrorHandler);\n }\n const onScriptCompleteCallback = () => {\n if (event?.type === 'error') {\n const networkError = new Error(\n `ScriptNetworkError: Failed to load script \"${info.url}\" - the script URL is unreachable or the server returned an error (network failure, 404, CORS, etc.)`,\n );\n networkError.name = 'ScriptNetworkError';\n info?.onErrorCallback && info?.onErrorCallback(networkError);\n } else if (executionError) {\n // Script fetched OK (onload fired) but IIFE threw during execution.\n info?.onErrorCallback && info?.onErrorCallback(executionError);\n } else {\n info?.cb && info?.cb();\n }\n };\n\n // Prevent memory leaks in IE.\n if (script) {\n script.onerror = null;\n script.onload = null;\n safeWrapper(() => {\n const { needDeleteScript = true } = info;\n if (needDeleteScript) {\n script?.parentNode && script.parentNode.removeChild(script);\n }\n });\n if (prev && typeof prev === 'function') {\n const result = (prev as any)(event);\n if (result instanceof Promise) {\n const res = await result;\n onScriptCompleteCallback();\n return res;\n }\n onScriptCompleteCallback();\n return result;\n }\n }\n onScriptCompleteCallback();\n };\n\n script.onerror = onScriptComplete.bind(null, script.onerror);\n script.onload = onScriptComplete.bind(null, script.onload);\n\n timeoutId = setTimeout(() => {\n onScriptComplete(\n null,\n new Error(`Remote script \"${info.url}\" time-outed.`),\n );\n }, timeout);\n\n return { script, needAttach };\n}\n\nexport function createLink(info: {\n url: string;\n cb?: (value: void | PromiseLike<void>) => void;\n onErrorCallback?: (error: Error) => void;\n attrs: Record<string, string>;\n needDeleteLink?: boolean;\n createLinkHook?: (\n url: string,\n attrs?: Record<string, any>,\n ) => HTMLLinkElement | void;\n}) {\n // <link rel=\"preload\" href=\"script.js\" as=\"script\">\n\n // Retrieve the existing script element by its src attribute\n let link: HTMLLinkElement | null = null;\n let needAttach = true;\n const links = document.getElementsByTagName('link');\n for (let i = 0; i < links.length; i++) {\n const l = links[i];\n const linkHref = l.getAttribute('href');\n const linkRel = l.getAttribute('rel');\n if (\n linkHref &&\n isStaticResourcesEqual(linkHref, info.url) &&\n linkRel === info.attrs['rel']\n ) {\n link = l;\n needAttach = false;\n break;\n }\n }\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('href', info.url);\n\n let createLinkRes: void | HTMLLinkElement = undefined;\n const attrs = info.attrs;\n\n if (info.createLinkHook) {\n createLinkRes = info.createLinkHook(info.url, attrs);\n if (createLinkRes instanceof HTMLLinkElement) {\n link = createLinkRes;\n }\n }\n\n if (attrs && !createLinkRes) {\n Object.keys(attrs).forEach((name) => {\n if (link && !link.getAttribute(name)) {\n link.setAttribute(name, attrs[name]);\n }\n });\n }\n }\n\n const onLinkComplete = (\n prev: OnErrorEventHandler | GlobalEventHandlers['onload'] | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event: any,\n ): void => {\n const onLinkCompleteCallback = () => {\n if (event?.type === 'error') {\n info?.onErrorCallback && info?.onErrorCallback(event);\n } else {\n info?.cb && info?.cb();\n }\n };\n // Prevent memory leaks in IE.\n if (link) {\n link.onerror = null;\n link.onload = null;\n safeWrapper(() => {\n const { needDeleteLink = true } = info;\n if (needDeleteLink) {\n link?.parentNode && link.parentNode.removeChild(link);\n }\n });\n if (prev) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const res = (prev as any)(event);\n onLinkCompleteCallback();\n return res;\n }\n }\n onLinkCompleteCallback();\n };\n\n link.onerror = onLinkComplete.bind(null, link.onerror);\n link.onload = onLinkComplete.bind(null, link.onload);\n\n return { link, needAttach };\n}\n\nexport function loadScript(\n url: string,\n info: {\n attrs?: Record<string, any>;\n createScriptHook?: CreateScriptHookDom;\n },\n) {\n const { attrs = {}, createScriptHook } = info;\n return new Promise<void>((resolve, reject) => {\n const { script, needAttach } = createScript({\n url,\n cb: resolve,\n onErrorCallback: reject,\n attrs: {\n fetchpriority: 'high',\n ...attrs,\n },\n createScriptHook,\n needDeleteScript: true,\n });\n needAttach && document.head.appendChild(script);\n });\n}\n"],"mappings":";;;AAGA,eAAsB,YACpB,UACA,aACoC;AACpC,KAAI;AAEF,SADY,MAAM,UAAU;UAErB,GAAG;AACV,GAAC,eAAe,KAAK,EAAE;AACvB;;;AAIJ,SAAgB,uBAAuB,MAAc,MAAuB;CAC1E,MAAM,UAAU;AAKhB,QAHqB,KAA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ACA,MAIA;CACA,MAAM,EAAE,QAAQ,EAAE,EAAE,qBAAqB;AACzC,QAAO,IAAI,SAAe,SAAS,WAAW;EAC5C,MAAM,EAAE,QAAQ,eAAe,aAAa;GAC1C;GACA,IAAI;GACJ,iBAAiB;GACjB,OAAO;IACL,eAAe;IACf,GAAG;IACJ;GACD;GACA,kBAAkB;GACnB,CAAC;AACF,gBAAc,SAAS,KAAK,YAAY,OAAO;GAC/C"}
|
package/dist/env.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const require_constant = require('./constant.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/env.ts
|
|
4
|
+
const isBrowserEnvValue = typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
5
|
+
function isBrowserEnv() {
|
|
6
|
+
return isBrowserEnvValue;
|
|
7
|
+
}
|
|
8
|
+
function isReactNativeEnv() {
|
|
9
|
+
return typeof navigator !== "undefined" && navigator?.product === "ReactNative";
|
|
10
|
+
}
|
|
11
|
+
function isBrowserDebug() {
|
|
12
|
+
try {
|
|
13
|
+
if (isBrowserEnv() && window.localStorage) return Boolean(localStorage.getItem(require_constant.BROWSER_LOG_KEY));
|
|
14
|
+
} catch (error) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
function isDebugMode() {
|
|
20
|
+
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) return Boolean(process.env["FEDERATION_DEBUG"]);
|
|
21
|
+
if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) return true;
|
|
22
|
+
return isBrowserDebug();
|
|
23
|
+
}
|
|
24
|
+
const getProcessEnv = function() {
|
|
25
|
+
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.getProcessEnv = getProcessEnv;
|
|
30
|
+
exports.isBrowserEnv = isBrowserEnv;
|
|
31
|
+
exports.isBrowserEnvValue = isBrowserEnvValue;
|
|
32
|
+
exports.isDebugMode = isDebugMode;
|
|
33
|
+
exports.isReactNativeEnv = isReactNativeEnv;
|
|
34
|
+
//# sourceMappingURL=env.cjs.map
|
package/dist/env.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.cjs","names":["BROWSER_LOG_KEY"],"sources":["../src/env.ts"],"sourcesContent":["import { BROWSER_LOG_KEY } from './constant';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var FEDERATION_DEBUG: string | undefined;\n}\n\n// Declare the ENV_TARGET constant that will be defined by DefinePlugin\ndeclare const ENV_TARGET: 'web' | 'node';\n\nconst isBrowserEnvValue =\n typeof ENV_TARGET !== 'undefined'\n ? ENV_TARGET === 'web'\n : typeof window !== 'undefined' && typeof window.document !== 'undefined';\n\nfunction isBrowserEnv(): boolean {\n return isBrowserEnvValue;\n}\n\nfunction isReactNativeEnv(): boolean {\n return (\n typeof navigator !== 'undefined' && navigator?.product === 'ReactNative'\n );\n}\n\nfunction isBrowserDebug() {\n try {\n if (isBrowserEnv() && window.localStorage) {\n return Boolean(localStorage.getItem(BROWSER_LOG_KEY));\n }\n } catch (error) {\n return false;\n }\n return false;\n}\n\nfunction isDebugMode(): boolean {\n if (\n typeof process !== 'undefined' &&\n process.env &&\n process.env['FEDERATION_DEBUG']\n ) {\n return Boolean(process.env['FEDERATION_DEBUG']);\n }\n\n if (typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG)) {\n return true;\n }\n\n return isBrowserDebug();\n}\n\nconst getProcessEnv = function (): Record<string, string | undefined> {\n return typeof process !== 'undefined' && process.env ? process.env : {};\n};\n\nexport {\n isBrowserEnv,\n isBrowserEnvValue,\n isReactNativeEnv,\n isDebugMode,\n getProcessEnv,\n};\n"],"mappings":";;;AAUA,MAAM,oBACJ,OAAO,eAAe,cAClB,eAAe,QACf,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAElE,SAAS,eAAwB;AAC/B,QAAO;;AAGT,SAAS,mBAA4B;AACnC,QACE,OAAO,cAAc,eAAe,WAAW,YAAY;;AAI/D,SAAS,iBAAiB;AACxB,KAAI;AACF,MAAI,cAAc,IAAI,OAAO,aAC3B,QAAO,QAAQ,aAAa,QAAQA,iCAAgB,CAAC;UAEhD,OAAO;AACd,SAAO;;AAET,QAAO;;AAGT,SAAS,cAAuB;AAC9B,KACE,OAAO,YAAY,eACnB,QAAQ,OACR,QAAQ,IAAI,oBAEZ,QAAO,QAAQ,QAAQ,IAAI,oBAAoB;AAGjD,KAAI,OAAO,qBAAqB,eAAe,QAAQ,iBAAiB,CACtE,QAAO;AAGT,QAAO,gBAAgB;;AAGzB,MAAM,gBAAgB,WAAgD;AACpE,QAAO,OAAO,YAAY,eAAe,QAAQ,MAAM,QAAQ,MAAM,EAAE"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/env.d.ts
|
|
2
|
+
declare global {
|
|
3
|
+
var FEDERATION_DEBUG: string | undefined;
|
|
4
|
+
}
|
|
5
|
+
declare const isBrowserEnvValue: boolean;
|
|
6
|
+
declare function isBrowserEnv(): boolean;
|
|
7
|
+
declare function isReactNativeEnv(): boolean;
|
|
8
|
+
declare function isDebugMode(): boolean;
|
|
9
|
+
declare const getProcessEnv: () => Record<string, string | undefined>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getProcessEnv, isBrowserEnv, isBrowserEnvValue, isDebugMode, isReactNativeEnv };
|
|
12
|
+
//# sourceMappingURL=env.d.ts.map
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BROWSER_LOG_KEY } from "./constant.js";
|
|
2
|
+
|
|
3
|
+
//#region src/env.ts
|
|
4
|
+
const isBrowserEnvValue = typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
5
|
+
function isBrowserEnv() {
|
|
6
|
+
return isBrowserEnvValue;
|
|
7
|
+
}
|
|
8
|
+
function isReactNativeEnv() {
|
|
9
|
+
return typeof navigator !== "undefined" && navigator?.product === "ReactNative";
|
|
10
|
+
}
|
|
11
|
+
function isBrowserDebug() {
|
|
12
|
+
try {
|
|
13
|
+
if (isBrowserEnv() && window.localStorage) return Boolean(localStorage.getItem(BROWSER_LOG_KEY));
|
|
14
|
+
} catch (error) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
function isDebugMode() {
|
|
20
|
+
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) return Boolean(process.env["FEDERATION_DEBUG"]);
|
|
21
|
+
if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) return true;
|
|
22
|
+
return isBrowserDebug();
|
|
23
|
+
}
|
|
24
|
+
const getProcessEnv = function() {
|
|
25
|
+
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { getProcessEnv, isBrowserEnv, isBrowserEnvValue, isDebugMode, isReactNativeEnv };
|
|
30
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","names":[],"sources":["../src/env.ts"],"sourcesContent":["import { BROWSER_LOG_KEY } from './constant';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var FEDERATION_DEBUG: string | undefined;\n}\n\n// Declare the ENV_TARGET constant that will be defined by DefinePlugin\ndeclare const ENV_TARGET: 'web' | 'node';\n\nconst isBrowserEnvValue =\n typeof ENV_TARGET !== 'undefined'\n ? ENV_TARGET === 'web'\n : typeof window !== 'undefined' && typeof window.document !== 'undefined';\n\nfunction isBrowserEnv(): boolean {\n return isBrowserEnvValue;\n}\n\nfunction isReactNativeEnv(): boolean {\n return (\n typeof navigator !== 'undefined' && navigator?.product === 'ReactNative'\n );\n}\n\nfunction isBrowserDebug() {\n try {\n if (isBrowserEnv() && window.localStorage) {\n return Boolean(localStorage.getItem(BROWSER_LOG_KEY));\n }\n } catch (error) {\n return false;\n }\n return false;\n}\n\nfunction isDebugMode(): boolean {\n if (\n typeof process !== 'undefined' &&\n process.env &&\n process.env['FEDERATION_DEBUG']\n ) {\n return Boolean(process.env['FEDERATION_DEBUG']);\n }\n\n if (typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG)) {\n return true;\n }\n\n return isBrowserDebug();\n}\n\nconst getProcessEnv = function (): Record<string, string | undefined> {\n return typeof process !== 'undefined' && process.env ? process.env : {};\n};\n\nexport {\n isBrowserEnv,\n isBrowserEnvValue,\n isReactNativeEnv,\n isDebugMode,\n getProcessEnv,\n};\n"],"mappings":";;;AAUA,MAAM,oBACJ,OAAO,eAAe,cAClB,eAAe,QACf,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAElE,SAAS,eAAwB;AAC/B,QAAO;;AAGT,SAAS,mBAA4B;AACnC,QACE,OAAO,cAAc,eAAe,WAAW,YAAY;;AAI/D,SAAS,iBAAiB;AACxB,KAAI;AACF,MAAI,cAAc,IAAI,OAAO,aAC3B,QAAO,QAAQ,aAAa,QAAQ,gBAAgB,CAAC;UAEhD,OAAO;AACd,SAAO;;AAET,QAAO;;AAGT,SAAS,cAAuB;AAC9B,KACE,OAAO,YAAY,eACnB,QAAQ,OACR,QAAQ,IAAI,oBAEZ,QAAO,QAAQ,QAAQ,IAAI,oBAAoB;AAGjD,KAAI,OAAO,qBAAqB,eAAe,QAAQ,iBAAiB,CACtE,QAAO;AAGT,QAAO,gBAAgB;;AAGzB,MAAM,gBAAgB,WAAgD;AACpE,QAAO,OAAO,YAAY,eAAe,QAAQ,MAAM,QAAQ,MAAM,EAAE"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const require_constant = require('./constant.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/generateSnapshotFromManifest.ts
|
|
4
|
+
const simpleJoinRemoteEntry = (rPath, rName) => {
|
|
5
|
+
if (!rPath) return rName;
|
|
6
|
+
const transformPath = (str) => {
|
|
7
|
+
if (str === ".") return "";
|
|
8
|
+
if (str.startsWith("./")) return str.replace("./", "");
|
|
9
|
+
if (str.startsWith("/")) {
|
|
10
|
+
const strWithoutSlash = str.slice(1);
|
|
11
|
+
if (strWithoutSlash.endsWith("/")) return strWithoutSlash.slice(0, -1);
|
|
12
|
+
return strWithoutSlash;
|
|
13
|
+
}
|
|
14
|
+
return str;
|
|
15
|
+
};
|
|
16
|
+
const transformedPath = transformPath(rPath);
|
|
17
|
+
if (!transformedPath) return rName;
|
|
18
|
+
if (transformedPath.endsWith("/")) return `${transformedPath}${rName}`;
|
|
19
|
+
return `${transformedPath}/${rName}`;
|
|
20
|
+
};
|
|
21
|
+
function inferAutoPublicPath(url) {
|
|
22
|
+
return url.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
|
|
23
|
+
}
|
|
24
|
+
function generateSnapshotFromManifest(manifest, options = {}) {
|
|
25
|
+
const { remotes = {}, overrides = {}, version } = options;
|
|
26
|
+
let remoteSnapshot;
|
|
27
|
+
const getPublicPath = () => {
|
|
28
|
+
if ("publicPath" in manifest.metaData) {
|
|
29
|
+
if ((manifest.metaData.publicPath === "auto" || manifest.metaData.publicPath === "") && version) return inferAutoPublicPath(version);
|
|
30
|
+
return manifest.metaData.publicPath;
|
|
31
|
+
} else return manifest.metaData.getPublicPath;
|
|
32
|
+
};
|
|
33
|
+
const overridesKeys = Object.keys(overrides);
|
|
34
|
+
let remotesInfo = {};
|
|
35
|
+
if (!Object.keys(remotes).length) remotesInfo = manifest.remotes?.reduce((res, next) => {
|
|
36
|
+
let matchedVersion;
|
|
37
|
+
const name = next.federationContainerName;
|
|
38
|
+
if (overridesKeys.includes(name)) matchedVersion = overrides[name];
|
|
39
|
+
else if ("version" in next) matchedVersion = next.version;
|
|
40
|
+
else matchedVersion = next.entry;
|
|
41
|
+
res[name] = { matchedVersion };
|
|
42
|
+
return res;
|
|
43
|
+
}, {}) || {};
|
|
44
|
+
Object.keys(remotes).forEach((key) => remotesInfo[key] = { matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key] });
|
|
45
|
+
const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes = {
|
|
46
|
+
path: "",
|
|
47
|
+
name: "",
|
|
48
|
+
zip: "",
|
|
49
|
+
api: ""
|
|
50
|
+
}, buildInfo: { buildVersion }, globalName, ssrRemoteEntry } = manifest.metaData;
|
|
51
|
+
const { exposes } = manifest;
|
|
52
|
+
let basicRemoteSnapshot = {
|
|
53
|
+
version: version ? version : "",
|
|
54
|
+
buildVersion,
|
|
55
|
+
globalName,
|
|
56
|
+
remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
|
|
57
|
+
remoteEntryType,
|
|
58
|
+
remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
|
|
59
|
+
remoteTypesZip: remoteTypes.zip || "",
|
|
60
|
+
remoteTypesAPI: remoteTypes.api || "",
|
|
61
|
+
remotesInfo,
|
|
62
|
+
shared: manifest?.shared.map((item) => ({
|
|
63
|
+
assets: item.assets,
|
|
64
|
+
sharedName: item.name,
|
|
65
|
+
version: item.version,
|
|
66
|
+
usedExports: item.referenceExports || []
|
|
67
|
+
})),
|
|
68
|
+
modules: exposes?.map((expose) => ({
|
|
69
|
+
moduleName: expose.name,
|
|
70
|
+
modulePath: expose.path,
|
|
71
|
+
assets: expose.assets
|
|
72
|
+
}))
|
|
73
|
+
};
|
|
74
|
+
if (manifest.metaData?.prefetchInterface) {
|
|
75
|
+
const prefetchInterface = manifest.metaData.prefetchInterface;
|
|
76
|
+
basicRemoteSnapshot = {
|
|
77
|
+
...basicRemoteSnapshot,
|
|
78
|
+
prefetchInterface
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (manifest.metaData?.prefetchEntry) {
|
|
82
|
+
const { path, name, type } = manifest.metaData.prefetchEntry;
|
|
83
|
+
basicRemoteSnapshot = {
|
|
84
|
+
...basicRemoteSnapshot,
|
|
85
|
+
prefetchEntry: simpleJoinRemoteEntry(path, name),
|
|
86
|
+
prefetchEntryType: type
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if ("publicPath" in manifest.metaData) {
|
|
90
|
+
remoteSnapshot = {
|
|
91
|
+
...basicRemoteSnapshot,
|
|
92
|
+
publicPath: getPublicPath()
|
|
93
|
+
};
|
|
94
|
+
if (typeof manifest.metaData.ssrPublicPath === "string") remoteSnapshot.ssrPublicPath = manifest.metaData.ssrPublicPath;
|
|
95
|
+
} else remoteSnapshot = {
|
|
96
|
+
...basicRemoteSnapshot,
|
|
97
|
+
getPublicPath: getPublicPath()
|
|
98
|
+
};
|
|
99
|
+
if (ssrRemoteEntry) {
|
|
100
|
+
const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
|
|
101
|
+
remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
|
|
102
|
+
remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || "commonjs-module";
|
|
103
|
+
}
|
|
104
|
+
return remoteSnapshot;
|
|
105
|
+
}
|
|
106
|
+
function isManifestProvider(moduleInfo) {
|
|
107
|
+
if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(require_constant.MANIFEST_EXT)) return true;
|
|
108
|
+
else return false;
|
|
109
|
+
}
|
|
110
|
+
function getManifestFileName(manifestOptions) {
|
|
111
|
+
if (!manifestOptions) return {
|
|
112
|
+
statsFileName: require_constant.StatsFileName,
|
|
113
|
+
manifestFileName: require_constant.ManifestFileName
|
|
114
|
+
};
|
|
115
|
+
let filePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
|
|
116
|
+
let fileName = typeof manifestOptions === "boolean" ? "" : manifestOptions.fileName || "";
|
|
117
|
+
const JSON_EXT = ".json";
|
|
118
|
+
const addExt = (name) => {
|
|
119
|
+
if (name.endsWith(JSON_EXT)) return name;
|
|
120
|
+
return `${name}${JSON_EXT}`;
|
|
121
|
+
};
|
|
122
|
+
const insertSuffix = (name, suffix) => {
|
|
123
|
+
return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
|
|
124
|
+
};
|
|
125
|
+
const manifestFileName = fileName ? addExt(fileName) : require_constant.ManifestFileName;
|
|
126
|
+
return {
|
|
127
|
+
statsFileName: simpleJoinRemoteEntry(filePath, fileName ? insertSuffix(manifestFileName, "-stats") : require_constant.StatsFileName),
|
|
128
|
+
manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
exports.generateSnapshotFromManifest = generateSnapshotFromManifest;
|
|
134
|
+
exports.getManifestFileName = getManifestFileName;
|
|
135
|
+
exports.inferAutoPublicPath = inferAutoPublicPath;
|
|
136
|
+
exports.isManifestProvider = isManifestProvider;
|
|
137
|
+
exports.simpleJoinRemoteEntry = simpleJoinRemoteEntry;
|
|
138
|
+
//# sourceMappingURL=generateSnapshotFromManifest.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSnapshotFromManifest.cjs","names":["MANIFEST_EXT","StatsFileName","ManifestFileName"],"sources":["../src/generateSnapshotFromManifest.ts"],"sourcesContent":["import {\n Manifest,\n ProviderModuleInfo,\n ModuleInfo,\n BasicProviderModuleInfo,\n ConsumerModuleInfo,\n ManifestProvider,\n moduleFederationPlugin,\n} from './types';\nimport { MANIFEST_EXT, ManifestFileName, StatsFileName } from './constant';\n\ninterface IOptions {\n remotes?: Record<string, string>;\n overrides?: Record<string, string>;\n version?: string;\n}\n\nexport const simpleJoinRemoteEntry = (rPath: string, rName: string): string => {\n if (!rPath) {\n return rName;\n }\n const transformPath = (str: string) => {\n if (str === '.') {\n return '';\n }\n if (str.startsWith('./')) {\n return str.replace('./', '');\n }\n if (str.startsWith('/')) {\n const strWithoutSlash = str.slice(1);\n if (strWithoutSlash.endsWith('/')) {\n return strWithoutSlash.slice(0, -1);\n }\n return strWithoutSlash;\n }\n return str;\n };\n\n const transformedPath = transformPath(rPath);\n\n if (!transformedPath) {\n return rName;\n }\n\n if (transformedPath.endsWith('/')) {\n return `${transformedPath}${rName}`;\n }\n\n return `${transformedPath}/${rName}`;\n};\n\nexport function inferAutoPublicPath(url: string): string {\n return url\n .replace(/#.*$/, '')\n .replace(/\\?.*$/, '')\n .replace(/\\/[^\\/]+$/, '/');\n}\n\n// Priority: overrides > remotes\n// eslint-disable-next-line max-lines-per-function\nexport function generateSnapshotFromManifest(\n manifest: Manifest,\n options: IOptions = {},\n): ProviderModuleInfo {\n const { remotes = {}, overrides = {}, version } = options;\n let remoteSnapshot: ProviderModuleInfo;\n\n const getPublicPath = (): string => {\n if ('publicPath' in manifest.metaData) {\n if (\n (manifest.metaData.publicPath === 'auto' ||\n manifest.metaData.publicPath === '') &&\n version\n ) {\n // use same implementation as publicPath auto runtime module implements\n return inferAutoPublicPath(version);\n }\n return manifest.metaData.publicPath;\n } else {\n return manifest.metaData.getPublicPath;\n }\n };\n\n const overridesKeys = Object.keys(overrides);\n\n let remotesInfo: ConsumerModuleInfo['remotesInfo'] = {};\n\n // If remotes are not provided, only the remotes in the manifest will be read\n if (!Object.keys(remotes).length) {\n remotesInfo =\n manifest.remotes?.reduce(\n (res, next) => {\n let matchedVersion: string;\n const name = next.federationContainerName;\n // overrides have higher priority\n if (overridesKeys.includes(name)) {\n matchedVersion = overrides[name];\n } else {\n if ('version' in next) {\n matchedVersion = next.version;\n } else {\n matchedVersion = next.entry;\n }\n }\n res[name] = {\n matchedVersion,\n };\n return res;\n },\n {} as ConsumerModuleInfo['remotesInfo'],\n ) || {};\n }\n\n // If remotes (deploy scenario) are specified, they need to be traversed again\n Object.keys(remotes).forEach(\n (key) =>\n (remotesInfo[key] = {\n // overrides will override dependencies\n matchedVersion: overridesKeys.includes(key)\n ? overrides[key]\n : remotes[key],\n }),\n );\n\n const {\n remoteEntry: {\n path: remoteEntryPath,\n name: remoteEntryName,\n type: remoteEntryType,\n },\n types: remoteTypes = { path: '', name: '', zip: '', api: '' },\n buildInfo: { buildVersion },\n globalName,\n ssrRemoteEntry,\n } = manifest.metaData;\n const { exposes } = manifest;\n\n let basicRemoteSnapshot: BasicProviderModuleInfo = {\n version: version ? version : '',\n buildVersion,\n globalName,\n remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),\n remoteEntryType,\n remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),\n remoteTypesZip: remoteTypes.zip || '',\n remoteTypesAPI: remoteTypes.api || '',\n remotesInfo,\n shared: manifest?.shared.map((item) => ({\n assets: item.assets,\n sharedName: item.name,\n version: item.version,\n // @ts-ignore\n usedExports: item.referenceExports || [],\n })),\n modules: exposes?.map((expose) => ({\n moduleName: expose.name,\n modulePath: expose.path,\n assets: expose.assets,\n })),\n };\n\n if (manifest.metaData?.prefetchInterface) {\n const prefetchInterface = manifest.metaData.prefetchInterface;\n\n basicRemoteSnapshot = {\n ...basicRemoteSnapshot,\n prefetchInterface,\n };\n }\n\n if (manifest.metaData?.prefetchEntry) {\n const { path, name, type } = manifest.metaData.prefetchEntry;\n\n basicRemoteSnapshot = {\n ...basicRemoteSnapshot,\n prefetchEntry: simpleJoinRemoteEntry(path, name),\n prefetchEntryType: type,\n };\n }\n\n if ('publicPath' in manifest.metaData) {\n remoteSnapshot = {\n ...basicRemoteSnapshot,\n publicPath: getPublicPath(),\n };\n if (typeof manifest.metaData.ssrPublicPath === 'string') {\n remoteSnapshot.ssrPublicPath = manifest.metaData.ssrPublicPath;\n }\n } else {\n remoteSnapshot = {\n ...basicRemoteSnapshot,\n getPublicPath: getPublicPath(),\n };\n }\n\n if (ssrRemoteEntry) {\n const fullSSRRemoteEntry = simpleJoinRemoteEntry(\n ssrRemoteEntry.path,\n ssrRemoteEntry.name,\n );\n remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;\n remoteSnapshot.ssrRemoteEntryType =\n ssrRemoteEntry.type || 'commonjs-module';\n }\n\n return remoteSnapshot;\n}\n\nexport function isManifestProvider(\n moduleInfo: ModuleInfo | ManifestProvider,\n): moduleInfo is ManifestProvider {\n if (\n 'remoteEntry' in moduleInfo &&\n moduleInfo.remoteEntry.includes(MANIFEST_EXT)\n ) {\n return true;\n } else {\n return false;\n }\n}\n\nexport function getManifestFileName(\n manifestOptions?: moduleFederationPlugin.ModuleFederationPluginOptions['manifest'],\n): {\n statsFileName: string;\n manifestFileName: string;\n} {\n if (!manifestOptions) {\n return {\n statsFileName: StatsFileName,\n manifestFileName: ManifestFileName,\n };\n }\n\n let filePath =\n typeof manifestOptions === 'boolean' ? '' : manifestOptions.filePath || '';\n let fileName =\n typeof manifestOptions === 'boolean' ? '' : manifestOptions.fileName || '';\n\n const JSON_EXT = '.json';\n const addExt = (name: string): string => {\n if (name.endsWith(JSON_EXT)) {\n return name;\n }\n return `${name}${JSON_EXT}`;\n };\n const insertSuffix = (name: string, suffix: string): string => {\n return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);\n };\n const manifestFileName = fileName ? addExt(fileName) : ManifestFileName;\n const statsFileName = fileName\n ? insertSuffix(manifestFileName, '-stats')\n : StatsFileName;\n\n return {\n statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),\n manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName),\n };\n}\n"],"mappings":";;;AAiBA,MAAa,yBAAyB,OAAe,UAA0B;AAC7E,KAAI,CAAC,MACH,QAAO;CAET,MAAM,iBAAiB,QAAgB;AACrC,MAAI,QAAQ,IACV,QAAO;AAET,MAAI,IAAI,WAAW,KAAK,CACtB,QAAO,IAAI,QAAQ,MAAM,GAAG;AAE9B,MAAI,IAAI,WAAW,IAAI,EA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d,YACgC;AAChC,KACE,iBAAiB,cACjB,WAAW,YAAY,SAASA,8BAAa,CAE7C,QAAO;KAEP,QAAO;;AAIX,SAAgB,oBACd,iBAIA;AACA,KAAI,CAAC,gBACH,QAAO;EACL,eAAeC;EACf,kBAAkBC;EACnB;CAGH,IAAI,WACF,OAAO,oBAAoB,YAAY,KAAK,gBAAgB,YAAY;CAC1E,IAAI,WACF,OAAO,oBAAoB,YAAY,KAAK,gBAAgB,YAAY;CAE1E,MAAM,WAAW;CACjB,MAAM,UAAU,SAAyB;AACvC,MAAI,KAAK,SAAS,SAAS,CACzB,QAAO;AAET,SAAO,GAAG,OAAO;;CAEnB,MAAM,gBAAgB,MAAc,WAA2B;AAC7D,SAAO,KAAK,QAAQ,UAAU,GAAG,SAAS,WAAW;;CAEvD,MAAM,mBAAmB,WAAW,OAAO,SAAS,GAAGA;AAKvD,QAAO;EACL,eAAe,sBAAsB,UALjB,WAClB,aAAa,kBAAkB,SAAS,GACxCD,+BAG2D;EAC7D,kBAAkB,sBAAsB,UAAU,iBAAiB;EACpE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Manifest } from "./types/manifest.js";
|
|
2
|
+
import { ManifestProvider, ModuleInfo, ProviderModuleInfo } from "./types/snapshot.js";
|
|
3
|
+
import { ModuleFederationPluginOptions } from "./types/plugins/ModuleFederationPlugin.js";
|
|
4
|
+
//#region src/generateSnapshotFromManifest.d.ts
|
|
5
|
+
interface IOptions {
|
|
6
|
+
remotes?: Record<string, string>;
|
|
7
|
+
overrides?: Record<string, string>;
|
|
8
|
+
version?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const simpleJoinRemoteEntry: (rPath: string, rName: string) => string;
|
|
11
|
+
declare function inferAutoPublicPath(url: string): string;
|
|
12
|
+
declare function generateSnapshotFromManifest(manifest: Manifest, options?: IOptions): ProviderModuleInfo;
|
|
13
|
+
declare function isManifestProvider(moduleInfo: ModuleInfo | ManifestProvider): moduleInfo is ManifestProvider;
|
|
14
|
+
declare function getManifestFileName(manifestOptions?: ModuleFederationPluginOptions['manifest']): {
|
|
15
|
+
statsFileName: string;
|
|
16
|
+
manifestFileName: string;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { generateSnapshotFromManifest, getManifestFileName, inferAutoPublicPath, isManifestProvider, simpleJoinRemoteEntry };
|
|
20
|
+
//# sourceMappingURL=generateSnapshotFromManifest.d.ts.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { MANIFEST_EXT, ManifestFileName, StatsFileName } from "./constant.js";
|
|
2
|
+
|
|
3
|
+
//#region src/generateSnapshotFromManifest.ts
|
|
4
|
+
const simpleJoinRemoteEntry = (rPath, rName) => {
|
|
5
|
+
if (!rPath) return rName;
|
|
6
|
+
const transformPath = (str) => {
|
|
7
|
+
if (str === ".") return "";
|
|
8
|
+
if (str.startsWith("./")) return str.replace("./", "");
|
|
9
|
+
if (str.startsWith("/")) {
|
|
10
|
+
const strWithoutSlash = str.slice(1);
|
|
11
|
+
if (strWithoutSlash.endsWith("/")) return strWithoutSlash.slice(0, -1);
|
|
12
|
+
return strWithoutSlash;
|
|
13
|
+
}
|
|
14
|
+
return str;
|
|
15
|
+
};
|
|
16
|
+
const transformedPath = transformPath(rPath);
|
|
17
|
+
if (!transformedPath) return rName;
|
|
18
|
+
if (transformedPath.endsWith("/")) return `${transformedPath}${rName}`;
|
|
19
|
+
return `${transformedPath}/${rName}`;
|
|
20
|
+
};
|
|
21
|
+
function inferAutoPublicPath(url) {
|
|
22
|
+
return url.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
|
|
23
|
+
}
|
|
24
|
+
function generateSnapshotFromManifest(manifest, options = {}) {
|
|
25
|
+
const { remotes = {}, overrides = {}, version } = options;
|
|
26
|
+
let remoteSnapshot;
|
|
27
|
+
const getPublicPath = () => {
|
|
28
|
+
if ("publicPath" in manifest.metaData) {
|
|
29
|
+
if ((manifest.metaData.publicPath === "auto" || manifest.metaData.publicPath === "") && version) return inferAutoPublicPath(version);
|
|
30
|
+
return manifest.metaData.publicPath;
|
|
31
|
+
} else return manifest.metaData.getPublicPath;
|
|
32
|
+
};
|
|
33
|
+
const overridesKeys = Object.keys(overrides);
|
|
34
|
+
let remotesInfo = {};
|
|
35
|
+
if (!Object.keys(remotes).length) remotesInfo = manifest.remotes?.reduce((res, next) => {
|
|
36
|
+
let matchedVersion;
|
|
37
|
+
const name = next.federationContainerName;
|
|
38
|
+
if (overridesKeys.includes(name)) matchedVersion = overrides[name];
|
|
39
|
+
else if ("version" in next) matchedVersion = next.version;
|
|
40
|
+
else matchedVersion = next.entry;
|
|
41
|
+
res[name] = { matchedVersion };
|
|
42
|
+
return res;
|
|
43
|
+
}, {}) || {};
|
|
44
|
+
Object.keys(remotes).forEach((key) => remotesInfo[key] = { matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key] });
|
|
45
|
+
const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes = {
|
|
46
|
+
path: "",
|
|
47
|
+
name: "",
|
|
48
|
+
zip: "",
|
|
49
|
+
api: ""
|
|
50
|
+
}, buildInfo: { buildVersion }, globalName, ssrRemoteEntry } = manifest.metaData;
|
|
51
|
+
const { exposes } = manifest;
|
|
52
|
+
let basicRemoteSnapshot = {
|
|
53
|
+
version: version ? version : "",
|
|
54
|
+
buildVersion,
|
|
55
|
+
globalName,
|
|
56
|
+
remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
|
|
57
|
+
remoteEntryType,
|
|
58
|
+
remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
|
|
59
|
+
remoteTypesZip: remoteTypes.zip || "",
|
|
60
|
+
remoteTypesAPI: remoteTypes.api || "",
|
|
61
|
+
remotesInfo,
|
|
62
|
+
shared: manifest?.shared.map((item) => ({
|
|
63
|
+
assets: item.assets,
|
|
64
|
+
sharedName: item.name,
|
|
65
|
+
version: item.version,
|
|
66
|
+
usedExports: item.referenceExports || []
|
|
67
|
+
})),
|
|
68
|
+
modules: exposes?.map((expose) => ({
|
|
69
|
+
moduleName: expose.name,
|
|
70
|
+
modulePath: expose.path,
|
|
71
|
+
assets: expose.assets
|
|
72
|
+
}))
|
|
73
|
+
};
|
|
74
|
+
if (manifest.metaData?.prefetchInterface) {
|
|
75
|
+
const prefetchInterface = manifest.metaData.prefetchInterface;
|
|
76
|
+
basicRemoteSnapshot = {
|
|
77
|
+
...basicRemoteSnapshot,
|
|
78
|
+
prefetchInterface
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (manifest.metaData?.prefetchEntry) {
|
|
82
|
+
const { path, name, type } = manifest.metaData.prefetchEntry;
|
|
83
|
+
basicRemoteSnapshot = {
|
|
84
|
+
...basicRemoteSnapshot,
|
|
85
|
+
prefetchEntry: simpleJoinRemoteEntry(path, name),
|
|
86
|
+
prefetchEntryType: type
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if ("publicPath" in manifest.metaData) {
|
|
90
|
+
remoteSnapshot = {
|
|
91
|
+
...basicRemoteSnapshot,
|
|
92
|
+
publicPath: getPublicPath()
|
|
93
|
+
};
|
|
94
|
+
if (typeof manifest.metaData.ssrPublicPath === "string") remoteSnapshot.ssrPublicPath = manifest.metaData.ssrPublicPath;
|
|
95
|
+
} else remoteSnapshot = {
|
|
96
|
+
...basicRemoteSnapshot,
|
|
97
|
+
getPublicPath: getPublicPath()
|
|
98
|
+
};
|
|
99
|
+
if (ssrRemoteEntry) {
|
|
100
|
+
const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
|
|
101
|
+
remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
|
|
102
|
+
remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || "commonjs-module";
|
|
103
|
+
}
|
|
104
|
+
return remoteSnapshot;
|
|
105
|
+
}
|
|
106
|
+
function isManifestProvider(moduleInfo) {
|
|
107
|
+
if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) return true;
|
|
108
|
+
else return false;
|
|
109
|
+
}
|
|
110
|
+
function getManifestFileName(manifestOptions) {
|
|
111
|
+
if (!manifestOptions) return {
|
|
112
|
+
statsFileName: StatsFileName,
|
|
113
|
+
manifestFileName: ManifestFileName
|
|
114
|
+
};
|
|
115
|
+
let filePath = typeof manifestOptions === "boolean" ? "" : manifestOptions.filePath || "";
|
|
116
|
+
let fileName = typeof manifestOptions === "boolean" ? "" : manifestOptions.fileName || "";
|
|
117
|
+
const JSON_EXT = ".json";
|
|
118
|
+
const addExt = (name) => {
|
|
119
|
+
if (name.endsWith(JSON_EXT)) return name;
|
|
120
|
+
return `${name}${JSON_EXT}`;
|
|
121
|
+
};
|
|
122
|
+
const insertSuffix = (name, suffix) => {
|
|
123
|
+
return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
|
|
124
|
+
};
|
|
125
|
+
const manifestFileName = fileName ? addExt(fileName) : ManifestFileName;
|
|
126
|
+
return {
|
|
127
|
+
statsFileName: simpleJoinRemoteEntry(filePath, fileName ? insertSuffix(manifestFileName, "-stats") : StatsFileName),
|
|
128
|
+
manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
export { generateSnapshotFromManifest, getManifestFileName, inferAutoPublicPath, isManifestProvider, simpleJoinRemoteEntry };
|
|
134
|
+
//# sourceMappingURL=generateSnapshotFromManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSnapshotFromManifest.js","names":[],"sources":["../src/generateSnapshotFromManifest.ts"],"sourcesContent":["import {\n Manifest,\n ProviderModuleInfo,\n ModuleInfo,\n BasicProviderModuleInfo,\n ConsumerModuleInfo,\n ManifestProvider,\n moduleFederationPlugin,\n} from './types';\nimport { MANIFEST_EXT, ManifestFileName, StatsFileName } from './constant';\n\ninterface IOptions {\n remotes?: Record<string, string>;\n overrides?: Record<string, string>;\n version?: string;\n}\n\nexport const simpleJoinRemoteEntry = (rPath: string, rName: string): string => {\n if (!rPath) {\n return rName;\n }\n const transformPath = (str: string) => {\n if (str === '.') {\n return '';\n }\n if (str.startsWith('./')) {\n return str.replace('./', '');\n }\n if (str.startsWith('/')) {\n const strWithoutSlash = str.slice(1);\n if (strWithoutSlash.endsWith('/')) {\n return strWithoutSlash.slice(0, -1);\n }\n return strWithoutSlash;\n }\n return str;\n };\n\n const transformedPath = transformPath(rPath);\n\n if (!transformedPath) {\n return rName;\n }\n\n if (transformedPath.endsWith('/')) {\n return `${transformedPath}${rName}`;\n }\n\n return `${transformedPath}/${rName}`;\n};\n\nexport function inferAutoPublicPath(url: string): string {\n return url\n .replace(/#.*$/, '')\n .replace(/\\?.*$/, '')\n .replace(/\\/[^\\/]+$/, '/');\n}\n\n// Priority: overrides > remotes\n// eslint-disable-next-line max-lines-per-function\nexport function generateSnapshotFromManifest(\n manifest: Manifest,\n options: IOptions = {},\n): ProviderModuleInfo {\n const { remotes = {}, overrides = {}, version } = options;\n let remoteSnapshot: ProviderModuleInfo;\n\n const getPublicPath = (): string => {\n if ('publicPath' in manifest.metaData) {\n if (\n (manifest.metaData.publicPath === 'auto' ||\n manifest.metaData.publicPath === '') &&\n version\n ) {\n // use same implementation as publicPath auto runtime module implements\n return inferAutoPublicPath(version);\n }\n return manifest.metaData.publicPath;\n } else {\n return manifest.metaData.getPublicPath;\n }\n };\n\n const overridesKeys = Object.keys(overrides);\n\n let remotesInfo: ConsumerModuleInfo['remotesInfo'] = {};\n\n // If remotes are not provided, only the remotes in the manifest will be read\n if (!Object.keys(remotes).length) {\n remotesInfo =\n manifest.remotes?.reduce(\n (res, next) => {\n let matchedVersion: string;\n const name = next.federationContainerName;\n // overrides have higher priority\n if (overridesKeys.includes(name)) {\n matchedVersion = overrides[name];\n } else {\n if ('version' in next) {\n matchedVersion = next.version;\n } else {\n matchedVersion = next.entry;\n }\n }\n res[name] = {\n matchedVersion,\n };\n return res;\n },\n {} as ConsumerModuleInfo['remotesInfo'],\n ) || {};\n }\n\n // If remotes (deploy scenario) are specified, they need to be traversed again\n Object.keys(remotes).forEach(\n (key) =>\n (remotesInfo[key] = {\n // overrides will override dependencies\n matchedVersion: overridesKeys.includes(key)\n ? overrides[key]\n : remotes[key],\n }),\n );\n\n const {\n remoteEntry: {\n path: remoteEntryPath,\n name: remoteEntryName,\n type: remoteEntryType,\n },\n types: remoteTypes = { path: '', name: '', zip: '', api: '' },\n buildInfo: { buildVersion },\n globalName,\n ssrRemoteEntry,\n } = manifest.metaData;\n const { exposes } = manifest;\n\n let basicRemoteSnapshot: BasicProviderModuleInfo = {\n version: version ? version : '',\n buildVersion,\n globalName,\n remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),\n remoteEntryType,\n remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),\n remoteTypesZip: remoteTypes.zip || '',\n remoteTypesAPI: remoteTypes.api || '',\n remotesInfo,\n shared: manifest?.shared.map((item) => ({\n assets: item.assets,\n sharedName: item.name,\n version: item.version,\n // @ts-ignore\n usedExports: item.referenceExports || [],\n })),\n modules: exposes?.map((expose) => ({\n moduleName: expose.name,\n modulePath: expose.path,\n assets: expose.assets,\n })),\n };\n\n if (manifest.metaData?.prefetchInterface) {\n const prefetchInterface = manifest.metaData.prefetchInterface;\n\n basicRemoteSnapshot = {\n ...basicRemoteSnapshot,\n prefetchInterface,\n };\n }\n\n if (manifest.metaData?.prefetchEntry) {\n const { path, name, type } = manifest.metaData.prefetchEntry;\n\n basicRemoteSnapshot = {\n ...basicRemoteSnapshot,\n prefetchEntry: simpleJoinRemoteEntry(path, name),\n prefetchEntryType: type,\n };\n }\n\n if ('publicPath' in manifest.metaData) {\n remoteSnapshot = {\n ...basicRemoteSnapshot,\n publicPath: getPublicPath(),\n };\n if (typeof manifest.metaData.ssrPublicPath === 'string') {\n remoteSnapshot.ssrPublicPath = manifest.metaData.ssrPublicPath;\n }\n } else {\n remoteSnapshot = {\n ...basicRemoteSnapshot,\n getPublicPath: getPublicPath(),\n };\n }\n\n if (ssrRemoteEntry) {\n const fullSSRRemoteEntry = simpleJoinRemoteEntry(\n ssrRemoteEntry.path,\n ssrRemoteEntry.name,\n );\n remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;\n remoteSnapshot.ssrRemoteEntryType =\n ssrRemoteEntry.type || 'commonjs-module';\n }\n\n return remoteSnapshot;\n}\n\nexport function isManifestProvider(\n moduleInfo: ModuleInfo | ManifestProvider,\n): moduleInfo is ManifestProvider {\n if (\n 'remoteEntry' in moduleInfo &&\n moduleInfo.remoteEntry.includes(MANIFEST_EXT)\n ) {\n return true;\n } else {\n return false;\n }\n}\n\nexport function getManifestFileName(\n manifestOptions?: moduleFederationPlugin.ModuleFederationPluginOptions['manifest'],\n): {\n statsFileName: string;\n manifestFileName: string;\n} {\n if (!manifestOptions) {\n return {\n statsFileName: StatsFileName,\n manifestFileName: ManifestFileName,\n };\n }\n\n let filePath =\n typeof manifestOptions === 'boolean' ? '' : manifestOptions.filePath || '';\n let fileName =\n typeof manifestOptions === 'boolean' ? '' : manifestOptions.fileName || '';\n\n const JSON_EXT = '.json';\n const addExt = (name: string): string => {\n if (name.endsWith(JSON_EXT)) {\n return name;\n }\n return `${name}${JSON_EXT}`;\n };\n const insertSuffix = (name: string, suffix: string): string => {\n return name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);\n };\n const manifestFileName = fileName ? addExt(fileName) : ManifestFileName;\n const statsFileName = fileName\n ? insertSuffix(manifestFileName, '-stats')\n : StatsFileName;\n\n return {\n statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),\n manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName),\n };\n}\n"],"mappings":";;;AAiBA,MAAa,yBAAyB,OAAe,UAA0B;AAC7E,KAAI,CAAC,MACH,QAAO;CAET,MAAM,i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