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