@module-federation/bridge-react 2.0.1 → 2.1.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/CHANGELOG.md +8 -0
- package/dist/base.cjs.js +4 -4
- package/dist/base.es.js +5 -5
- package/dist/{bridge-base-BVX0EbsV.mjs → bridge-base-B7EKIpJ7.mjs} +1 -1
- package/dist/{bridge-base-vSCG9ebE.js → bridge-base-BLno0Ytr.js} +1 -1
- package/dist/{createHelpers-CGhHhtAd.mjs → createHelpers-4fOvXdyD.mjs} +2 -2
- package/dist/{createHelpers-12yCVhCu.js → createHelpers-DVr-JIwn.js} +2 -2
- package/dist/data-fetch-server-middleware.cjs.js +4 -4
- package/dist/data-fetch-server-middleware.es.js +2 -2
- package/dist/data-fetch-utils.cjs.js +2 -2
- package/dist/data-fetch-utils.es.js +4 -4
- package/dist/{index-DtXhorFI.mjs → index-CafhxM-l.mjs} +1 -1
- package/dist/{index-DhFNWacm.js → index-Cmp3JjCw.js} +2 -2
- package/dist/index.cjs.js +5 -5
- package/dist/index.es.js +6 -6
- package/dist/{lazy-load-component-plugin-C7jasFos.js → lazy-load-component-plugin-B0jL1C-H.js} +2 -2
- package/dist/{lazy-load-component-plugin-CrSLH5YP.mjs → lazy-load-component-plugin-CXfIn_mH.mjs} +2 -2
- package/dist/lazy-load-component-plugin.cjs.js +2 -2
- package/dist/lazy-load-component-plugin.es.js +2 -2
- package/dist/lazy-utils.cjs.js +2 -2
- package/dist/lazy-utils.es.js +7 -7
- package/dist/logger-BWq2gts-.mjs +138 -0
- package/dist/logger-DT66A_Pv.js +137 -0
- package/dist/{prefetch-DMJyBeIs.mjs → prefetch-CmkSilpl.mjs} +395 -167
- package/dist/{prefetch-CFRpPfZQ.js → prefetch-CvCACzJH.js} +401 -173
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.es.js +1 -1
- package/dist/router-v7.cjs.js +1 -1
- package/dist/router-v7.es.js +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.es.js +1 -1
- package/dist/{utils-TDonIHDD.js → utils-BelRTG4G.js} +18 -4
- package/dist/{utils-DpoLOH_j.mjs → utils-DYUQLv_v.mjs} +21 -7
- package/dist/v18.cjs.js +1 -1
- package/dist/v18.es.js +1 -1
- package/dist/v19.cjs.js +1 -1
- package/dist/v19.es.js +1 -1
- package/package.json +6 -6
- package/dist/index.esm-BvTtsZnu.mjs +0 -491
- package/dist/index.esm-CYiGJfQW.js +0 -490
|
@@ -1,5 +1,278 @@
|
|
|
1
|
-
import { x as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger, e as getDataFetchMap, i as initDataFetchMap, n as getDataFetchItem, M as MF_DATA_FETCH_STATUS, p as MF_DATA_FETCH_TYPE,
|
|
2
|
-
import {
|
|
1
|
+
import { A as warn, x as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger, e as getDataFetchMap, i as initDataFetchMap, n as getDataFetchItem, M as MF_DATA_FETCH_STATUS, p as MF_DATA_FETCH_TYPE, B as DOWNGRADE_KEY, G as callAllDowngrade, H as callDowngrade, I as getDowngradeTag, J as composeKeyWithSeparator, k as getDataFetchInfo, m as getDataFetchMapKey } from "./utils-DYUQLv_v.mjs";
|
|
2
|
+
import { i as isBrowserEnv } from "./logger-BWq2gts-.mjs";
|
|
3
|
+
async function safeWrapper(callback, disableWarn) {
|
|
4
|
+
try {
|
|
5
|
+
return await callback();
|
|
6
|
+
} catch (e) {
|
|
7
|
+
warn(e);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function isStaticResourcesEqual(url1, url2) {
|
|
12
|
+
const REG_EXP = /^(https?:)?\/\//i;
|
|
13
|
+
return url1.replace(REG_EXP, "").replace(/\/$/, "") === url2.replace(REG_EXP, "").replace(/\/$/, "");
|
|
14
|
+
}
|
|
15
|
+
function createScript(info) {
|
|
16
|
+
let script = null;
|
|
17
|
+
let needAttach = true;
|
|
18
|
+
let timeout = 2e4;
|
|
19
|
+
let timeoutId;
|
|
20
|
+
const scripts = document.getElementsByTagName("script");
|
|
21
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
22
|
+
const s = scripts[i];
|
|
23
|
+
const scriptSrc = s.getAttribute("src");
|
|
24
|
+
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
25
|
+
script = s;
|
|
26
|
+
needAttach = false;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!script) {
|
|
31
|
+
const attrs = info.attrs;
|
|
32
|
+
script = document.createElement("script");
|
|
33
|
+
script.type = (attrs == null ? void 0 : attrs["type"]) === "module" ? "module" : "text/javascript";
|
|
34
|
+
let createScriptRes = void 0;
|
|
35
|
+
if (info.createScriptHook) {
|
|
36
|
+
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
37
|
+
if (createScriptRes instanceof HTMLScriptElement) script = createScriptRes;
|
|
38
|
+
else if (typeof createScriptRes === "object") {
|
|
39
|
+
if ("script" in createScriptRes && createScriptRes.script) script = createScriptRes.script;
|
|
40
|
+
if ("timeout" in createScriptRes && createScriptRes.timeout) timeout = createScriptRes.timeout;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!script.src) script.src = info.url;
|
|
44
|
+
if (attrs && !createScriptRes) Object.keys(attrs).forEach((name) => {
|
|
45
|
+
if (script) {
|
|
46
|
+
if (name === "async" || name === "defer") script[name] = attrs[name];
|
|
47
|
+
else if (!script.getAttribute(name)) script.setAttribute(name, attrs[name]);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const onScriptComplete = async (prev, event) => {
|
|
52
|
+
clearTimeout(timeoutId);
|
|
53
|
+
const onScriptCompleteCallback = () => {
|
|
54
|
+
if ((event == null ? void 0 : event.type) === "error") (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
55
|
+
else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
56
|
+
};
|
|
57
|
+
if (script) {
|
|
58
|
+
script.onerror = null;
|
|
59
|
+
script.onload = null;
|
|
60
|
+
safeWrapper(() => {
|
|
61
|
+
const { needDeleteScript = true } = info;
|
|
62
|
+
if (needDeleteScript) (script == null ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
|
|
63
|
+
});
|
|
64
|
+
if (prev && typeof prev === "function") {
|
|
65
|
+
const result = prev(event);
|
|
66
|
+
if (result instanceof Promise) {
|
|
67
|
+
const res = await result;
|
|
68
|
+
onScriptCompleteCallback();
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
onScriptCompleteCallback();
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
onScriptCompleteCallback();
|
|
76
|
+
};
|
|
77
|
+
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
78
|
+
script.onload = onScriptComplete.bind(null, script.onload);
|
|
79
|
+
timeoutId = setTimeout(() => {
|
|
80
|
+
onScriptComplete(null, /* @__PURE__ */ new Error(`Remote script "${info.url}" time-outed.`));
|
|
81
|
+
}, timeout);
|
|
82
|
+
return {
|
|
83
|
+
script,
|
|
84
|
+
needAttach
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function createLink(info) {
|
|
88
|
+
let link = null;
|
|
89
|
+
let needAttach = true;
|
|
90
|
+
const links = document.getElementsByTagName("link");
|
|
91
|
+
for (let i = 0; i < links.length; i++) {
|
|
92
|
+
const l = links[i];
|
|
93
|
+
const linkHref = l.getAttribute("href");
|
|
94
|
+
const linkRel = l.getAttribute("rel");
|
|
95
|
+
if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
|
|
96
|
+
link = l;
|
|
97
|
+
needAttach = false;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!link) {
|
|
102
|
+
link = document.createElement("link");
|
|
103
|
+
link.setAttribute("href", info.url);
|
|
104
|
+
let createLinkRes = void 0;
|
|
105
|
+
const attrs = info.attrs;
|
|
106
|
+
if (info.createLinkHook) {
|
|
107
|
+
createLinkRes = info.createLinkHook(info.url, attrs);
|
|
108
|
+
if (createLinkRes instanceof HTMLLinkElement) link = createLinkRes;
|
|
109
|
+
}
|
|
110
|
+
if (attrs && !createLinkRes) Object.keys(attrs).forEach((name) => {
|
|
111
|
+
if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const onLinkComplete = (prev, event) => {
|
|
115
|
+
const onLinkCompleteCallback = () => {
|
|
116
|
+
if ((event == null ? void 0 : event.type) === "error") (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
117
|
+
else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
118
|
+
};
|
|
119
|
+
if (link) {
|
|
120
|
+
link.onerror = null;
|
|
121
|
+
link.onload = null;
|
|
122
|
+
safeWrapper(() => {
|
|
123
|
+
const { needDeleteLink = true } = info;
|
|
124
|
+
if (needDeleteLink) (link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
125
|
+
});
|
|
126
|
+
if (prev) {
|
|
127
|
+
const res = prev(event);
|
|
128
|
+
onLinkCompleteCallback();
|
|
129
|
+
return res;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
onLinkCompleteCallback();
|
|
133
|
+
};
|
|
134
|
+
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
135
|
+
link.onload = onLinkComplete.bind(null, link.onload);
|
|
136
|
+
return {
|
|
137
|
+
link,
|
|
138
|
+
needAttach
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function loadScript(url, info) {
|
|
142
|
+
const { attrs = {}, createScriptHook } = info;
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
const { script, needAttach } = createScript({
|
|
145
|
+
url,
|
|
146
|
+
cb: resolve,
|
|
147
|
+
onErrorCallback: reject,
|
|
148
|
+
attrs: {
|
|
149
|
+
fetchpriority: "high",
|
|
150
|
+
...attrs
|
|
151
|
+
},
|
|
152
|
+
createScriptHook,
|
|
153
|
+
needDeleteScript: true
|
|
154
|
+
});
|
|
155
|
+
needAttach && document.head.appendChild(script);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const sdkImportCache = /* @__PURE__ */ new Map();
|
|
159
|
+
function importNodeModule(name) {
|
|
160
|
+
if (!name) throw new Error("import specifier is required");
|
|
161
|
+
if (sdkImportCache.has(name)) return sdkImportCache.get(name);
|
|
162
|
+
const promise = new Function("name", `return import(name)`)(name).then((res) => res).catch((error2) => {
|
|
163
|
+
console.error(`Error importing module ${name}:`, error2);
|
|
164
|
+
sdkImportCache.delete(name);
|
|
165
|
+
throw error2;
|
|
166
|
+
});
|
|
167
|
+
sdkImportCache.set(name, promise);
|
|
168
|
+
return promise;
|
|
169
|
+
}
|
|
170
|
+
const loadNodeFetch = async () => {
|
|
171
|
+
const fetchModule = await importNodeModule("node-fetch");
|
|
172
|
+
return fetchModule.default || fetchModule;
|
|
173
|
+
};
|
|
174
|
+
const lazyLoaderHookFetch = async (input, init, loaderHook) => {
|
|
175
|
+
const hook = (url, init2) => {
|
|
176
|
+
return loaderHook.lifecycle.fetch.emit(url, init2);
|
|
177
|
+
};
|
|
178
|
+
const res = await hook(input, init || {});
|
|
179
|
+
if (!res || !(res instanceof Response)) return (typeof fetch === "undefined" ? await loadNodeFetch() : fetch)(input, init || {});
|
|
180
|
+
return res;
|
|
181
|
+
};
|
|
182
|
+
const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
|
|
183
|
+
if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
|
|
184
|
+
const hookResult = loaderHook.createScriptHook(url);
|
|
185
|
+
if (hookResult && typeof hookResult === "object" && "url" in hookResult) url = hookResult.url;
|
|
186
|
+
}
|
|
187
|
+
let urlObj;
|
|
188
|
+
try {
|
|
189
|
+
urlObj = new URL(url);
|
|
190
|
+
} catch (e) {
|
|
191
|
+
console.error("Error constructing URL:", e);
|
|
192
|
+
cb(/* @__PURE__ */ new Error(`Invalid URL: ${e}`));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const getFetch = async () => {
|
|
196
|
+
if (loaderHook == null ? void 0 : loaderHook.fetch) return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
197
|
+
return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
|
|
198
|
+
};
|
|
199
|
+
const handleScriptFetch = async (f, urlObj2) => {
|
|
200
|
+
var _a;
|
|
201
|
+
try {
|
|
202
|
+
const res = await f(urlObj2.href);
|
|
203
|
+
const data = await res.text();
|
|
204
|
+
const [path, vm] = await Promise.all([importNodeModule("path"), importNodeModule("vm")]);
|
|
205
|
+
const scriptContext = {
|
|
206
|
+
exports: {},
|
|
207
|
+
module: { exports: {} }
|
|
208
|
+
};
|
|
209
|
+
const urlDirname = urlObj2.pathname.split("/").slice(0, -1).join("/");
|
|
210
|
+
const filename = path.basename(urlObj2.pathname);
|
|
211
|
+
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
|
|
212
|
+
})`, {
|
|
213
|
+
filename,
|
|
214
|
+
importModuleDynamically: ((_a = vm.constants) == null ? void 0 : _a.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
|
|
215
|
+
});
|
|
216
|
+
let requireFn;
|
|
217
|
+
requireFn = (await importNodeModule("node:module")).createRequire(urlObj2.protocol === "file:" || urlObj2.protocol === "node:" ? urlObj2.href : path.join(process.cwd(), "__mf_require_base__.js"));
|
|
218
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, requireFn, urlDirname, filename);
|
|
219
|
+
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
220
|
+
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
221
|
+
cb(void 0, exportedInterface[attrs["globalName"]] || exportedInterface);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
cb(void 0, exportedInterface);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
getFetch().then(async (f) => {
|
|
230
|
+
if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") return loadModule(urlObj.href, {
|
|
231
|
+
fetch: f,
|
|
232
|
+
vm: await importNodeModule("vm")
|
|
233
|
+
}).then(async (module) => {
|
|
234
|
+
await module.evaluate();
|
|
235
|
+
cb(void 0, module.namespace);
|
|
236
|
+
}).catch((e) => {
|
|
237
|
+
cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
|
|
238
|
+
});
|
|
239
|
+
handleScriptFetch(f, urlObj);
|
|
240
|
+
}).catch((err) => {
|
|
241
|
+
cb(err);
|
|
242
|
+
});
|
|
243
|
+
} : (url, cb, attrs, loaderHook) => {
|
|
244
|
+
cb(/* @__PURE__ */ new Error("createScriptNode is disabled in non-Node.js environment"));
|
|
245
|
+
};
|
|
246
|
+
const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, info) => {
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
createScriptNode(url, (error2, scriptContext) => {
|
|
249
|
+
var _a, _b;
|
|
250
|
+
if (error2) reject(error2);
|
|
251
|
+
else {
|
|
252
|
+
const remoteEntryKey = ((_a = info == null ? void 0 : info.attrs) == null ? void 0 : _a["globalName"]) || `__FEDERATION_${(_b = info == null ? void 0 : info.attrs) == null ? void 0 : _b["name"]}:custom__`;
|
|
253
|
+
resolve(globalThis[remoteEntryKey] = scriptContext);
|
|
254
|
+
}
|
|
255
|
+
}, info.attrs, info.loaderHook);
|
|
256
|
+
});
|
|
257
|
+
} : (url, info) => {
|
|
258
|
+
throw new Error("loadScriptNode is disabled in non-Node.js environment");
|
|
259
|
+
};
|
|
260
|
+
const esmModuleCache = /* @__PURE__ */ new Map();
|
|
261
|
+
async function loadModule(url, options) {
|
|
262
|
+
if (esmModuleCache.has(url)) return esmModuleCache.get(url);
|
|
263
|
+
const { fetch: fetch2, vm } = options;
|
|
264
|
+
const code = await (await fetch2(url)).text();
|
|
265
|
+
const module = new vm.SourceTextModule(code, { importModuleDynamically: async (specifier, script) => {
|
|
266
|
+
const resolvedUrl = new URL(specifier, url).href;
|
|
267
|
+
return loadModule(resolvedUrl, options);
|
|
268
|
+
} });
|
|
269
|
+
esmModuleCache.set(url, module);
|
|
270
|
+
await module.link(async (specifier) => {
|
|
271
|
+
const resolvedUrl = new URL(specifier, url).href;
|
|
272
|
+
return await loadModule(resolvedUrl, options);
|
|
273
|
+
});
|
|
274
|
+
return module;
|
|
275
|
+
}
|
|
3
276
|
const dataFetchFunction = async function(options) {
|
|
4
277
|
var _a, _b;
|
|
5
278
|
const [id, data, downgrade] = options;
|
|
@@ -75,50 +348,13 @@ function injectDataFetch() {
|
|
|
75
348
|
globalThis[FS_HREF] = window.location.href;
|
|
76
349
|
dataFetch.push = dataFetchFunction;
|
|
77
350
|
}
|
|
78
|
-
const RUNTIME_001 = "RUNTIME-001";
|
|
79
|
-
const RUNTIME_002 = "RUNTIME-002";
|
|
80
|
-
const RUNTIME_003 = "RUNTIME-003";
|
|
81
|
-
const RUNTIME_004 = "RUNTIME-004";
|
|
82
|
-
const RUNTIME_005 = "RUNTIME-005";
|
|
83
|
-
const RUNTIME_006 = "RUNTIME-006";
|
|
84
|
-
const RUNTIME_007 = "RUNTIME-007";
|
|
85
|
-
const RUNTIME_008 = "RUNTIME-008";
|
|
86
|
-
const RUNTIME_009 = "RUNTIME-009";
|
|
87
|
-
const getDocsUrl = (errorCode) => {
|
|
88
|
-
const type = errorCode.split("-")[0].toLowerCase();
|
|
89
|
-
return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${type}#${errorCode.toLowerCase()}`;
|
|
90
|
-
};
|
|
91
|
-
const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
|
|
92
|
-
const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
|
|
93
|
-
args && msg.push(`args: ${JSON.stringify(args)}`);
|
|
94
|
-
msg.push(getDocsUrl(errorCode));
|
|
95
|
-
return msg.join("\n");
|
|
96
|
-
};
|
|
97
|
-
const runtimeDescMap = {
|
|
98
|
-
[RUNTIME_001]: "Failed to get remoteEntry exports.",
|
|
99
|
-
[RUNTIME_002]: 'The remote entry interface does not contain "init"',
|
|
100
|
-
[RUNTIME_003]: "Failed to get manifest.",
|
|
101
|
-
[RUNTIME_004]: "Failed to locate remote.",
|
|
102
|
-
[RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
|
|
103
|
-
[RUNTIME_006]: "Invalid loadShareSync function call from runtime",
|
|
104
|
-
[RUNTIME_007]: "Failed to get remote snapshot.",
|
|
105
|
-
[RUNTIME_008]: "Failed to load script resources.",
|
|
106
|
-
[RUNTIME_009]: "Please call createInstance first."
|
|
107
|
-
};
|
|
108
|
-
({
|
|
109
|
-
...runtimeDescMap
|
|
110
|
-
});
|
|
111
351
|
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
112
352
|
function assert(condition, msg) {
|
|
113
|
-
if (!condition)
|
|
114
|
-
error(msg);
|
|
115
|
-
}
|
|
353
|
+
if (!condition) error(msg);
|
|
116
354
|
}
|
|
117
355
|
function error(msg) {
|
|
118
356
|
if (msg instanceof Error) {
|
|
119
|
-
if (!msg.message.startsWith(LOG_CATEGORY)) {
|
|
120
|
-
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
121
|
-
}
|
|
357
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
122
358
|
throw msg;
|
|
123
359
|
}
|
|
124
360
|
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
@@ -141,15 +377,11 @@ function definePropertyGlobalVal(target, key, val) {
|
|
|
141
377
|
function includeOwnProperty(target, key) {
|
|
142
378
|
return Object.hasOwnProperty.call(target, key);
|
|
143
379
|
}
|
|
144
|
-
if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) {
|
|
145
|
-
definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
|
|
146
|
-
}
|
|
380
|
+
if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
|
|
147
381
|
const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
148
382
|
function setGlobalDefaultVal(target) {
|
|
149
383
|
var _a, _b, _c, _d, _e, _f;
|
|
150
|
-
if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__"))
|
|
151
|
-
definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
|
|
152
|
-
}
|
|
384
|
+
if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
|
|
153
385
|
if (!includeOwnProperty(target, "__FEDERATION__")) {
|
|
154
386
|
definePropertyGlobalVal(target, "__FEDERATION__", {
|
|
155
387
|
__GLOBAL_PLUGIN__: [],
|
|
@@ -172,10 +404,9 @@ setGlobalDefaultVal(CurrentGlobal);
|
|
|
172
404
|
setGlobalDefaultVal(nativeGlobal);
|
|
173
405
|
const getRemoteEntryExports = (name, globalName) => {
|
|
174
406
|
const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
|
|
175
|
-
const entryExports = CurrentGlobal[remoteEntryKey];
|
|
176
407
|
return {
|
|
177
408
|
remoteEntryKey,
|
|
178
|
-
entryExports
|
|
409
|
+
entryExports: CurrentGlobal[remoteEntryKey]
|
|
179
410
|
};
|
|
180
411
|
};
|
|
181
412
|
const DEFAULT_SCOPE = "default";
|
|
@@ -193,13 +424,11 @@ function matchRemoteWithNameAndExpose(remotes, id) {
|
|
|
193
424
|
expose,
|
|
194
425
|
remote
|
|
195
426
|
};
|
|
196
|
-
} else if (expose === "") {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
};
|
|
202
|
-
}
|
|
427
|
+
} else if (expose === "") return {
|
|
428
|
+
pkgNameOrAlias: remote.name,
|
|
429
|
+
expose: ".",
|
|
430
|
+
remote
|
|
431
|
+
};
|
|
203
432
|
}
|
|
204
433
|
const isAliasMatched = remote.alias && id.startsWith(remote.alias);
|
|
205
434
|
let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
|
|
@@ -212,37 +441,59 @@ function matchRemoteWithNameAndExpose(remotes, id) {
|
|
|
212
441
|
expose: exposeWithAlias,
|
|
213
442
|
remote
|
|
214
443
|
};
|
|
215
|
-
} else if (exposeWithAlias === "") {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
};
|
|
221
|
-
}
|
|
444
|
+
} else if (exposeWithAlias === "") return {
|
|
445
|
+
pkgNameOrAlias: remote.alias,
|
|
446
|
+
expose: ".",
|
|
447
|
+
remote
|
|
448
|
+
};
|
|
222
449
|
}
|
|
223
450
|
}
|
|
224
|
-
return;
|
|
225
451
|
}
|
|
452
|
+
const RUNTIME_001 = "RUNTIME-001";
|
|
453
|
+
const RUNTIME_002 = "RUNTIME-002";
|
|
454
|
+
const RUNTIME_003 = "RUNTIME-003";
|
|
455
|
+
const RUNTIME_004 = "RUNTIME-004";
|
|
456
|
+
const RUNTIME_005 = "RUNTIME-005";
|
|
457
|
+
const RUNTIME_006 = "RUNTIME-006";
|
|
458
|
+
const RUNTIME_007 = "RUNTIME-007";
|
|
459
|
+
const RUNTIME_008 = "RUNTIME-008";
|
|
460
|
+
const RUNTIME_009 = "RUNTIME-009";
|
|
461
|
+
const RUNTIME_010 = "RUNTIME-010";
|
|
462
|
+
const getDocsUrl = (errorCode) => {
|
|
463
|
+
return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split("-")[0].toLowerCase()}#${errorCode.toLowerCase()}`;
|
|
464
|
+
};
|
|
465
|
+
const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
|
|
466
|
+
const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
|
|
467
|
+
args && msg.push(`args: ${JSON.stringify(args)}`);
|
|
468
|
+
msg.push(getDocsUrl(errorCode));
|
|
469
|
+
return msg.join("\n");
|
|
470
|
+
};
|
|
471
|
+
const runtimeDescMap = {
|
|
472
|
+
[RUNTIME_001]: "Failed to get remoteEntry exports.",
|
|
473
|
+
[RUNTIME_002]: 'The remote entry interface does not contain "init"',
|
|
474
|
+
[RUNTIME_003]: "Failed to get manifest.",
|
|
475
|
+
[RUNTIME_004]: "Failed to locate remote.",
|
|
476
|
+
[RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
|
|
477
|
+
[RUNTIME_006]: "Invalid loadShareSync function call from runtime",
|
|
478
|
+
[RUNTIME_007]: "Failed to get remote snapshot.",
|
|
479
|
+
[RUNTIME_008]: "Failed to load script resources.",
|
|
480
|
+
[RUNTIME_009]: "Please call createInstance first.",
|
|
481
|
+
[RUNTIME_010]: 'The name option cannot be changed after initialization. If you want to create a new instance with a different name, please use "createInstance" api.'
|
|
482
|
+
};
|
|
483
|
+
({
|
|
484
|
+
...runtimeDescMap
|
|
485
|
+
});
|
|
226
486
|
const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
|
|
227
487
|
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
228
488
|
return new Promise((resolve, reject) => {
|
|
229
489
|
try {
|
|
230
|
-
if (!remoteEntryExports) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
import(
|
|
238
|
-
/* webpackIgnore: true */
|
|
239
|
-
/* @vite-ignore */
|
|
240
|
-
entry
|
|
241
|
-
).then(resolve).catch(reject);
|
|
242
|
-
}
|
|
243
|
-
} else {
|
|
244
|
-
resolve(remoteEntryExports);
|
|
245
|
-
}
|
|
490
|
+
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${entry}")${importCallback}`)([resolve, reject]);
|
|
491
|
+
else import(
|
|
492
|
+
/* webpackIgnore: true */
|
|
493
|
+
/* @vite-ignore */
|
|
494
|
+
entry
|
|
495
|
+
).then(resolve).catch(reject);
|
|
496
|
+
else resolve(remoteEntryExports);
|
|
246
497
|
} catch (e) {
|
|
247
498
|
reject(e);
|
|
248
499
|
}
|
|
@@ -251,15 +502,9 @@ async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
|
251
502
|
async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
252
503
|
return new Promise((resolve, reject) => {
|
|
253
504
|
try {
|
|
254
|
-
if (!remoteEntryExports)
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
} else {
|
|
258
|
-
new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
resolve(remoteEntryExports);
|
|
262
|
-
}
|
|
505
|
+
if (!remoteEntryExports) if (typeof __system_context__ === "undefined") System.import(entry).then(resolve).catch(reject);
|
|
506
|
+
else new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
|
|
507
|
+
else resolve(remoteEntryExports);
|
|
263
508
|
} catch (e) {
|
|
264
509
|
reject(e);
|
|
265
510
|
}
|
|
@@ -276,23 +521,17 @@ function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
|
276
521
|
}
|
|
277
522
|
async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl }) {
|
|
278
523
|
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
279
|
-
if (remoteEntryExports)
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
const url = getEntryUrl ? getEntryUrl(entry) : entry;
|
|
283
|
-
return loadScript(url, {
|
|
524
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
525
|
+
return loadScript(getEntryUrl ? getEntryUrl(entry) : entry, {
|
|
284
526
|
attrs: {},
|
|
285
|
-
createScriptHook: (
|
|
286
|
-
const res = loaderHook.lifecycle.createScript.emit({
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if ("script" in res || "timeout" in res)
|
|
293
|
-
return res;
|
|
294
|
-
}
|
|
295
|
-
return;
|
|
527
|
+
createScriptHook: (url, attrs) => {
|
|
528
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
529
|
+
url,
|
|
530
|
+
attrs
|
|
531
|
+
});
|
|
532
|
+
if (!res) return;
|
|
533
|
+
if (res instanceof HTMLScriptElement) return res;
|
|
534
|
+
if ("script" in res || "timeout" in res) return res;
|
|
296
535
|
}
|
|
297
536
|
}).then(() => {
|
|
298
537
|
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
@@ -309,9 +548,15 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEnt
|
|
|
309
548
|
switch (type) {
|
|
310
549
|
case "esm":
|
|
311
550
|
case "module":
|
|
312
|
-
return loadEsmEntry({
|
|
551
|
+
return loadEsmEntry({
|
|
552
|
+
entry,
|
|
553
|
+
remoteEntryExports
|
|
554
|
+
});
|
|
313
555
|
case "system":
|
|
314
|
-
return loadSystemJsEntry({
|
|
556
|
+
return loadSystemJsEntry({
|
|
557
|
+
entry,
|
|
558
|
+
remoteEntryExports
|
|
559
|
+
});
|
|
315
560
|
default:
|
|
316
561
|
return loadEntryScript({
|
|
317
562
|
entry,
|
|
@@ -325,22 +570,21 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEnt
|
|
|
325
570
|
async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
326
571
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
327
572
|
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
328
|
-
if (remoteEntryExports)
|
|
329
|
-
return remoteEntryExports;
|
|
330
|
-
}
|
|
573
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
331
574
|
return loadScriptNode(entry, {
|
|
332
|
-
attrs: {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
575
|
+
attrs: {
|
|
576
|
+
name,
|
|
577
|
+
globalName,
|
|
578
|
+
type
|
|
579
|
+
},
|
|
580
|
+
loaderHook: { createScriptHook: (url, attrs = {}) => {
|
|
581
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
582
|
+
url,
|
|
583
|
+
attrs
|
|
584
|
+
});
|
|
585
|
+
if (!res) return;
|
|
586
|
+
if ("url" in res) return res;
|
|
587
|
+
} }
|
|
344
588
|
}).then(() => {
|
|
345
589
|
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
346
590
|
}).catch((e) => {
|
|
@@ -354,9 +598,7 @@ function getRemoteEntryUniqueKey(remoteInfo) {
|
|
|
354
598
|
async function getRemoteEntry(params) {
|
|
355
599
|
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
|
|
356
600
|
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
357
|
-
if (remoteEntryExports)
|
|
358
|
-
return remoteEntryExports;
|
|
359
|
-
}
|
|
601
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
360
602
|
if (!globalLoading[uniqueKey]) {
|
|
361
603
|
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
362
604
|
const loaderHook = origin.loaderHook;
|
|
@@ -365,22 +607,24 @@ async function getRemoteEntry(params) {
|
|
|
365
607
|
remoteInfo,
|
|
366
608
|
remoteEntryExports
|
|
367
609
|
}).then((res) => {
|
|
368
|
-
if (res)
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
const isWebEnvironment = typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : isBrowserEnv();
|
|
372
|
-
return isWebEnvironment ? loadEntryDom({
|
|
610
|
+
if (res) return res;
|
|
611
|
+
return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : isBrowserEnv()) ? loadEntryDom({
|
|
373
612
|
remoteInfo,
|
|
374
613
|
remoteEntryExports,
|
|
375
614
|
loaderHook,
|
|
376
615
|
getEntryUrl
|
|
377
|
-
}) : loadEntryNode({
|
|
616
|
+
}) : loadEntryNode({
|
|
617
|
+
remoteInfo,
|
|
618
|
+
loaderHook
|
|
619
|
+
});
|
|
378
620
|
}).catch(async (err) => {
|
|
379
621
|
const uniqueKey2 = getRemoteEntryUniqueKey(remoteInfo);
|
|
380
|
-
|
|
381
|
-
if (isScriptLoadError && !_inErrorHandling) {
|
|
622
|
+
if (err instanceof Error && err.message.includes(RUNTIME_008) && !_inErrorHandling) {
|
|
382
623
|
const wrappedGetRemoteEntry = (params2) => {
|
|
383
|
-
return getRemoteEntry({
|
|
624
|
+
return getRemoteEntry({
|
|
625
|
+
...params2,
|
|
626
|
+
_inErrorHandling: true
|
|
627
|
+
});
|
|
384
628
|
};
|
|
385
629
|
const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
386
630
|
getRemoteEntry: wrappedGetRemoteEntry,
|
|
@@ -390,9 +634,7 @@ async function getRemoteEntry(params) {
|
|
|
390
634
|
globalLoading,
|
|
391
635
|
uniqueKey: uniqueKey2
|
|
392
636
|
});
|
|
393
|
-
if (RemoteEntryExports)
|
|
394
|
-
return RemoteEntryExports;
|
|
395
|
-
}
|
|
637
|
+
if (RemoteEntryExports) return RemoteEntryExports;
|
|
396
638
|
}
|
|
397
639
|
throw err;
|
|
398
640
|
});
|
|
@@ -414,19 +656,16 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
|
|
|
414
656
|
entryAssets.forEach((asset) => {
|
|
415
657
|
const { moduleInfo } = asset;
|
|
416
658
|
const module = host.moduleCache.get(remoteInfo.name);
|
|
417
|
-
if (module) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
remoteEntryExports: void 0
|
|
428
|
-
});
|
|
429
|
-
}
|
|
659
|
+
if (module) getRemoteEntry({
|
|
660
|
+
origin: host,
|
|
661
|
+
remoteInfo: moduleInfo,
|
|
662
|
+
remoteEntryExports: module.remoteEntryExports
|
|
663
|
+
});
|
|
664
|
+
else getRemoteEntry({
|
|
665
|
+
origin: host,
|
|
666
|
+
remoteInfo: moduleInfo,
|
|
667
|
+
remoteEntryExports: void 0
|
|
668
|
+
});
|
|
430
669
|
});
|
|
431
670
|
if (useLinkPreload) {
|
|
432
671
|
const defaultAttrs = {
|
|
@@ -444,10 +683,7 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
|
|
|
444
683
|
url,
|
|
445
684
|
attrs
|
|
446
685
|
});
|
|
447
|
-
if (res instanceof HTMLLinkElement)
|
|
448
|
-
return res;
|
|
449
|
-
}
|
|
450
|
-
return;
|
|
686
|
+
if (res instanceof HTMLLinkElement) return res;
|
|
451
687
|
}
|
|
452
688
|
});
|
|
453
689
|
needAttach && document.head.appendChild(cssEl);
|
|
@@ -468,10 +704,7 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
|
|
|
468
704
|
url,
|
|
469
705
|
attrs
|
|
470
706
|
});
|
|
471
|
-
if (res instanceof HTMLLinkElement)
|
|
472
|
-
return res;
|
|
473
|
-
}
|
|
474
|
-
return;
|
|
707
|
+
if (res instanceof HTMLLinkElement) return res;
|
|
475
708
|
},
|
|
476
709
|
needDeleteLink: false
|
|
477
710
|
});
|
|
@@ -494,10 +727,7 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
|
|
|
494
727
|
url,
|
|
495
728
|
attrs
|
|
496
729
|
});
|
|
497
|
-
if (res instanceof HTMLLinkElement)
|
|
498
|
-
return res;
|
|
499
|
-
}
|
|
500
|
-
return;
|
|
730
|
+
if (res instanceof HTMLLinkElement) return res;
|
|
501
731
|
}
|
|
502
732
|
});
|
|
503
733
|
needAttach && document.head.appendChild(linkEl);
|
|
@@ -518,10 +748,7 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
|
|
|
518
748
|
url,
|
|
519
749
|
attrs
|
|
520
750
|
});
|
|
521
|
-
if (res instanceof HTMLScriptElement)
|
|
522
|
-
return res;
|
|
523
|
-
}
|
|
524
|
-
return;
|
|
751
|
+
if (res instanceof HTMLScriptElement) return res;
|
|
525
752
|
},
|
|
526
753
|
needDeleteScript: true
|
|
527
754
|
});
|
|
@@ -530,7 +757,7 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
|
|
|
530
757
|
}
|
|
531
758
|
}
|
|
532
759
|
}
|
|
533
|
-
var
|
|
760
|
+
var helpers_default = {
|
|
534
761
|
utils: {
|
|
535
762
|
matchRemoteWithNameAndExpose,
|
|
536
763
|
preloadAssets,
|
|
@@ -538,6 +765,7 @@ var helpers = {
|
|
|
538
765
|
}
|
|
539
766
|
};
|
|
540
767
|
typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
|
|
768
|
+
const helpers = helpers_default;
|
|
541
769
|
const utils = helpers.utils;
|
|
542
770
|
const runtimeHelpers = {
|
|
543
771
|
utils
|