@module-federation/bridge-react 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/.turbo/turbo-build.log +85 -0
- package/CHANGELOG.md +22 -3
- package/dist/base.cjs.js +4 -4
- package/dist/base.es.js +5 -5
- package/dist/{bridge-base-BVX0EbsV.mjs → bridge-base-EnVXD4Hr.mjs} +1 -1
- package/dist/{bridge-base-vSCG9ebE.js → bridge-base-IlvdqYIj.js} +1 -1
- package/dist/{createHelpers-12yCVhCu.js → createHelpers-9B0ttrN_.js} +2 -2
- package/dist/{createHelpers-CGhHhtAd.mjs → createHelpers-D77sECmY.mjs} +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-Bs2NxD2z.mjs} +1 -1
- package/dist/{index-DhFNWacm.js → index-DbjGCKOr.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-0-2dETvt.js} +2 -2
- package/dist/{lazy-load-component-plugin-CrSLH5YP.mjs → lazy-load-component-plugin-ChXiUL6x.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-DwWkXsWl.mjs +139 -0
- package/dist/logger-Dxblx6P-.js +138 -0
- package/dist/prefetch-BIuiJePI.js +884 -0
- package/dist/prefetch-DLfc6h__.mjs +885 -0
- 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-CFTy4LVE.js} +18 -4
- package/dist/{utils-DpoLOH_j.mjs → utils-D4k5eixv.mjs} +22 -8
- 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 +8 -7
- package/src/lazy/utils.ts +5 -2
- package/vitest.config.ts +2 -2
- package/dist/index.esm-BvTtsZnu.mjs +0 -491
- package/dist/index.esm-CYiGJfQW.js +0 -490
- package/dist/prefetch-CFRpPfZQ.js +0 -632
- package/dist/prefetch-DMJyBeIs.mjs +0 -633
- package/project.json +0 -23
|
@@ -0,0 +1,884 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const lazyUtils = require("./utils-CFTy4LVE.js");
|
|
3
|
+
const logger = require("./logger-Dxblx6P-.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
|
+
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 == null ? void 0 : 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 == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(networkError));
|
|
69
|
+
} else if (executionError) (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(executionError));
|
|
70
|
+
else (info == null ? void 0 : info.cb) && (info == null ? void 0 : 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 == null ? void 0 : 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 == null ? void 0 : event.type) === "error") (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
132
|
+
else (info == null ? void 0 : info.cb) && (info == null ? void 0 : 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 == null ? void 0 : 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
|
+
const sdkImportCache = /* @__PURE__ */ new Map();
|
|
174
|
+
function importNodeModule(name) {
|
|
175
|
+
if (!name) throw new Error("import specifier is required");
|
|
176
|
+
if (sdkImportCache.has(name)) return sdkImportCache.get(name);
|
|
177
|
+
const promise = new Function("name", `return import(name)`)(name).then((res) => res).catch((error2) => {
|
|
178
|
+
console.error(`Error importing module ${name}:`, error2);
|
|
179
|
+
sdkImportCache.delete(name);
|
|
180
|
+
throw error2;
|
|
181
|
+
});
|
|
182
|
+
sdkImportCache.set(name, promise);
|
|
183
|
+
return promise;
|
|
184
|
+
}
|
|
185
|
+
const loadNodeFetch = async () => {
|
|
186
|
+
const fetchModule = await importNodeModule("node-fetch");
|
|
187
|
+
return fetchModule.default || fetchModule;
|
|
188
|
+
};
|
|
189
|
+
const lazyLoaderHookFetch = async (input, init, loaderHook) => {
|
|
190
|
+
const hook = (url, init2) => {
|
|
191
|
+
return loaderHook.lifecycle.fetch.emit(url, init2);
|
|
192
|
+
};
|
|
193
|
+
const res = await hook(input, init || {});
|
|
194
|
+
if (!res || !(res instanceof Response)) return (typeof fetch === "undefined" ? await loadNodeFetch() : fetch)(input, init || {});
|
|
195
|
+
return res;
|
|
196
|
+
};
|
|
197
|
+
const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
|
|
198
|
+
if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
|
|
199
|
+
const hookResult = loaderHook.createScriptHook(url);
|
|
200
|
+
if (hookResult && typeof hookResult === "object" && "url" in hookResult) url = hookResult.url;
|
|
201
|
+
}
|
|
202
|
+
let urlObj;
|
|
203
|
+
try {
|
|
204
|
+
urlObj = new URL(url);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
console.error("Error constructing URL:", e);
|
|
207
|
+
cb(/* @__PURE__ */ new Error(`Invalid URL: ${e}`));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const getFetch = async () => {
|
|
211
|
+
if (loaderHook == null ? void 0 : loaderHook.fetch) return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
212
|
+
return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
|
|
213
|
+
};
|
|
214
|
+
const handleScriptFetch = async (f, urlObj2) => {
|
|
215
|
+
var _a;
|
|
216
|
+
try {
|
|
217
|
+
const res = await f(urlObj2.href);
|
|
218
|
+
const data = await res.text();
|
|
219
|
+
const [path, vm] = await Promise.all([importNodeModule("path"), importNodeModule("vm")]);
|
|
220
|
+
const scriptContext = {
|
|
221
|
+
exports: {},
|
|
222
|
+
module: { exports: {} }
|
|
223
|
+
};
|
|
224
|
+
const urlDirname = urlObj2.pathname.split("/").slice(0, -1).join("/");
|
|
225
|
+
const filename = path.basename(urlObj2.pathname);
|
|
226
|
+
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
|
|
227
|
+
})`, {
|
|
228
|
+
filename,
|
|
229
|
+
importModuleDynamically: ((_a = vm.constants) == null ? void 0 : _a.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
|
|
230
|
+
});
|
|
231
|
+
let requireFn;
|
|
232
|
+
requireFn = (await importNodeModule("node:module")).createRequire(urlObj2.protocol === "file:" || urlObj2.protocol === "node:" ? urlObj2.href : path.join(process.cwd(), "__mf_require_base__.js"));
|
|
233
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, requireFn, urlDirname, filename);
|
|
234
|
+
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
235
|
+
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
236
|
+
cb(void 0, exportedInterface[attrs["globalName"]] || exportedInterface);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
cb(void 0, exportedInterface);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
getFetch().then(async (f) => {
|
|
245
|
+
if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") return loadModule(urlObj.href, {
|
|
246
|
+
fetch: f,
|
|
247
|
+
vm: await importNodeModule("vm")
|
|
248
|
+
}).then(async (module2) => {
|
|
249
|
+
await module2.evaluate();
|
|
250
|
+
cb(void 0, module2.namespace);
|
|
251
|
+
}).catch((e) => {
|
|
252
|
+
cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
|
|
253
|
+
});
|
|
254
|
+
handleScriptFetch(f, urlObj);
|
|
255
|
+
}).catch((err) => {
|
|
256
|
+
cb(err);
|
|
257
|
+
});
|
|
258
|
+
} : (url, cb, attrs, loaderHook) => {
|
|
259
|
+
cb(/* @__PURE__ */ new Error("createScriptNode is disabled in non-Node.js environment"));
|
|
260
|
+
};
|
|
261
|
+
const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, info) => {
|
|
262
|
+
return new Promise((resolve, reject) => {
|
|
263
|
+
createScriptNode(url, (error2, scriptContext) => {
|
|
264
|
+
var _a, _b;
|
|
265
|
+
if (error2) reject(error2);
|
|
266
|
+
else {
|
|
267
|
+
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__`;
|
|
268
|
+
resolve(globalThis[remoteEntryKey] = scriptContext);
|
|
269
|
+
}
|
|
270
|
+
}, info.attrs, info.loaderHook);
|
|
271
|
+
});
|
|
272
|
+
} : (url, info) => {
|
|
273
|
+
throw new Error("loadScriptNode is disabled in non-Node.js environment");
|
|
274
|
+
};
|
|
275
|
+
const esmModuleCache = /* @__PURE__ */ new Map();
|
|
276
|
+
async function loadModule(url, options) {
|
|
277
|
+
if (esmModuleCache.has(url)) return esmModuleCache.get(url);
|
|
278
|
+
const { fetch: fetch2, vm } = options;
|
|
279
|
+
const code = await (await fetch2(url)).text();
|
|
280
|
+
const module2 = new vm.SourceTextModule(code, { importModuleDynamically: async (specifier, script) => {
|
|
281
|
+
const resolvedUrl = new URL(specifier, url).href;
|
|
282
|
+
return loadModule(resolvedUrl, options);
|
|
283
|
+
} });
|
|
284
|
+
esmModuleCache.set(url, module2);
|
|
285
|
+
await module2.link(async (specifier) => {
|
|
286
|
+
const resolvedUrl = new URL(specifier, url).href;
|
|
287
|
+
return await loadModule(resolvedUrl, options);
|
|
288
|
+
});
|
|
289
|
+
return module2;
|
|
290
|
+
}
|
|
291
|
+
const dataFetchFunction = async function(options) {
|
|
292
|
+
var _a, _b;
|
|
293
|
+
const [id, data, downgrade] = options;
|
|
294
|
+
lazyUtils.logger.debug("==========call data fetch function!");
|
|
295
|
+
if (data) {
|
|
296
|
+
if (!id) {
|
|
297
|
+
throw new Error("id is required!");
|
|
298
|
+
}
|
|
299
|
+
if (!lazyUtils.getDataFetchMap()) {
|
|
300
|
+
lazyUtils.initDataFetchMap();
|
|
301
|
+
}
|
|
302
|
+
const dataFetchItem = lazyUtils.getDataFetchItem(id);
|
|
303
|
+
if (dataFetchItem) {
|
|
304
|
+
(_b = (_a = dataFetchItem[1]) == null ? void 0 : _a[1]) == null ? void 0 : _b.call(_a, data);
|
|
305
|
+
dataFetchItem[2] = lazyUtils.MF_DATA_FETCH_STATUS.LOADED;
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (!dataFetchItem) {
|
|
309
|
+
const dataFetchMap = lazyUtils.getDataFetchMap();
|
|
310
|
+
let res;
|
|
311
|
+
let rej;
|
|
312
|
+
const p = new Promise((resolve, reject) => {
|
|
313
|
+
res = resolve;
|
|
314
|
+
rej = reject;
|
|
315
|
+
});
|
|
316
|
+
dataFetchMap[id] = [
|
|
317
|
+
[
|
|
318
|
+
async () => async () => {
|
|
319
|
+
return "";
|
|
320
|
+
},
|
|
321
|
+
lazyUtils.MF_DATA_FETCH_TYPE.FETCH_SERVER
|
|
322
|
+
],
|
|
323
|
+
[p, res, rej],
|
|
324
|
+
lazyUtils.MF_DATA_FETCH_STATUS.LOADED
|
|
325
|
+
];
|
|
326
|
+
res && res(data);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (downgrade) {
|
|
331
|
+
const mfDowngrade2 = lazyUtils.getDowngradeTag();
|
|
332
|
+
if (!mfDowngrade2) {
|
|
333
|
+
globalThis[lazyUtils.DOWNGRADE_KEY] = id ? [id] : true;
|
|
334
|
+
} else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
|
|
335
|
+
mfDowngrade2.push(id);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const mfDowngrade = lazyUtils.getDowngradeTag();
|
|
339
|
+
if (typeof mfDowngrade === "boolean") {
|
|
340
|
+
return lazyUtils.callAllDowngrade();
|
|
341
|
+
}
|
|
342
|
+
if (Array.isArray(mfDowngrade)) {
|
|
343
|
+
if (!id) {
|
|
344
|
+
globalThis[lazyUtils.DOWNGRADE_KEY] = true;
|
|
345
|
+
return lazyUtils.callAllDowngrade();
|
|
346
|
+
}
|
|
347
|
+
if (!mfDowngrade.includes(id)) {
|
|
348
|
+
mfDowngrade.push(id);
|
|
349
|
+
}
|
|
350
|
+
return lazyUtils.callDowngrade(id);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
function injectDataFetch() {
|
|
354
|
+
var _a;
|
|
355
|
+
globalThis[_a = lazyUtils.DATA_FETCH_FUNCTION] || (globalThis[_a] = []);
|
|
356
|
+
const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
|
|
357
|
+
if (dataFetch.push === dataFetchFunction) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (typeof window === "undefined") {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
globalThis[lazyUtils.FS_HREF] = window.location.href;
|
|
364
|
+
dataFetch.push = dataFetchFunction;
|
|
365
|
+
}
|
|
366
|
+
const getDocsUrl = (errorCode) => {
|
|
367
|
+
return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split("-")[0].toLowerCase()}#${errorCode.toLowerCase()}`;
|
|
368
|
+
};
|
|
369
|
+
const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
|
|
370
|
+
const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
|
|
371
|
+
args && msg.push(`args: ${JSON.stringify(args)}`);
|
|
372
|
+
msg.push(getDocsUrl(errorCode));
|
|
373
|
+
originalErrorMsg && msg.push(`Original Error Message:
|
|
374
|
+
${originalErrorMsg}`);
|
|
375
|
+
return msg.join("\n");
|
|
376
|
+
};
|
|
377
|
+
function logAndReport(code, descMap, args, logger2, originalErrorMsg, context) {
|
|
378
|
+
return logger2(getShortErrorMsg(code, descMap, args, originalErrorMsg));
|
|
379
|
+
}
|
|
380
|
+
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
381
|
+
function error(msgOrCode, descMap, args, originalErrorMsg, context) {
|
|
382
|
+
if (descMap !== void 0) return logAndReport(msgOrCode, descMap, args ?? {}, (msg2) => {
|
|
383
|
+
throw new Error(`${LOG_CATEGORY}: ${msg2}`);
|
|
384
|
+
}, originalErrorMsg);
|
|
385
|
+
const msg = msgOrCode;
|
|
386
|
+
if (msg instanceof Error) {
|
|
387
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
388
|
+
throw msg;
|
|
389
|
+
}
|
|
390
|
+
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
391
|
+
}
|
|
392
|
+
const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
|
|
393
|
+
const nativeGlobal = (() => {
|
|
394
|
+
try {
|
|
395
|
+
return document.defaultView;
|
|
396
|
+
} catch {
|
|
397
|
+
return CurrentGlobal;
|
|
398
|
+
}
|
|
399
|
+
})();
|
|
400
|
+
function definePropertyGlobalVal(target, key, val) {
|
|
401
|
+
Object.defineProperty(target, key, {
|
|
402
|
+
value: val,
|
|
403
|
+
configurable: false,
|
|
404
|
+
writable: true
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
function includeOwnProperty(target, key) {
|
|
408
|
+
return Object.hasOwnProperty.call(target, key);
|
|
409
|
+
}
|
|
410
|
+
if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
|
|
411
|
+
const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
412
|
+
function setGlobalDefaultVal(target) {
|
|
413
|
+
var _a, _b, _c, _d, _e, _f;
|
|
414
|
+
if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
|
|
415
|
+
if (!includeOwnProperty(target, "__FEDERATION__")) {
|
|
416
|
+
definePropertyGlobalVal(target, "__FEDERATION__", {
|
|
417
|
+
__GLOBAL_PLUGIN__: [],
|
|
418
|
+
__INSTANCES__: [],
|
|
419
|
+
moduleInfo: {},
|
|
420
|
+
__SHARE__: {},
|
|
421
|
+
__MANIFEST_LOADING__: {},
|
|
422
|
+
__PRELOADED_MAP__: /* @__PURE__ */ new Map()
|
|
423
|
+
});
|
|
424
|
+
definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
|
|
425
|
+
}
|
|
426
|
+
(_a = target.__FEDERATION__).__GLOBAL_PLUGIN__ ?? (_a.__GLOBAL_PLUGIN__ = []);
|
|
427
|
+
(_b = target.__FEDERATION__).__INSTANCES__ ?? (_b.__INSTANCES__ = []);
|
|
428
|
+
(_c = target.__FEDERATION__).moduleInfo ?? (_c.moduleInfo = {});
|
|
429
|
+
(_d = target.__FEDERATION__).__SHARE__ ?? (_d.__SHARE__ = {});
|
|
430
|
+
(_e = target.__FEDERATION__).__MANIFEST_LOADING__ ?? (_e.__MANIFEST_LOADING__ = {});
|
|
431
|
+
(_f = target.__FEDERATION__).__PRELOADED_MAP__ ?? (_f.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
|
|
432
|
+
}
|
|
433
|
+
setGlobalDefaultVal(CurrentGlobal);
|
|
434
|
+
setGlobalDefaultVal(nativeGlobal);
|
|
435
|
+
const getRemoteEntryExports = (name, globalName) => {
|
|
436
|
+
const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
|
|
437
|
+
return {
|
|
438
|
+
remoteEntryKey,
|
|
439
|
+
entryExports: CurrentGlobal[remoteEntryKey]
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
const DEFAULT_SCOPE = "default";
|
|
443
|
+
const DEFAULT_REMOTE_TYPE = "global";
|
|
444
|
+
function matchRemoteWithNameAndExpose(remotes, id) {
|
|
445
|
+
for (const remote of remotes) {
|
|
446
|
+
const isNameMatched = id.startsWith(remote.name);
|
|
447
|
+
let expose = id.replace(remote.name, "");
|
|
448
|
+
if (isNameMatched) {
|
|
449
|
+
if (expose.startsWith("/")) {
|
|
450
|
+
const pkgNameOrAlias = remote.name;
|
|
451
|
+
expose = `.${expose}`;
|
|
452
|
+
return {
|
|
453
|
+
pkgNameOrAlias,
|
|
454
|
+
expose,
|
|
455
|
+
remote
|
|
456
|
+
};
|
|
457
|
+
} else if (expose === "") return {
|
|
458
|
+
pkgNameOrAlias: remote.name,
|
|
459
|
+
expose: ".",
|
|
460
|
+
remote
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
const isAliasMatched = remote.alias && id.startsWith(remote.alias);
|
|
464
|
+
let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
|
|
465
|
+
if (remote.alias && isAliasMatched) {
|
|
466
|
+
if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
|
|
467
|
+
const pkgNameOrAlias = remote.alias;
|
|
468
|
+
exposeWithAlias = `.${exposeWithAlias}`;
|
|
469
|
+
return {
|
|
470
|
+
pkgNameOrAlias,
|
|
471
|
+
expose: exposeWithAlias,
|
|
472
|
+
remote
|
|
473
|
+
};
|
|
474
|
+
} else if (exposeWithAlias === "") return {
|
|
475
|
+
pkgNameOrAlias: remote.alias,
|
|
476
|
+
expose: ".",
|
|
477
|
+
remote
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const RUNTIME_001 = "RUNTIME-001";
|
|
483
|
+
const RUNTIME_002 = "RUNTIME-002";
|
|
484
|
+
const RUNTIME_003 = "RUNTIME-003";
|
|
485
|
+
const RUNTIME_004 = "RUNTIME-004";
|
|
486
|
+
const RUNTIME_005 = "RUNTIME-005";
|
|
487
|
+
const RUNTIME_006 = "RUNTIME-006";
|
|
488
|
+
const RUNTIME_007 = "RUNTIME-007";
|
|
489
|
+
const RUNTIME_008 = "RUNTIME-008";
|
|
490
|
+
const RUNTIME_009 = "RUNTIME-009";
|
|
491
|
+
const RUNTIME_010 = "RUNTIME-010";
|
|
492
|
+
const RUNTIME_011 = "RUNTIME-011";
|
|
493
|
+
const runtimeDescMap = {
|
|
494
|
+
[RUNTIME_001]: "Failed to get remoteEntry exports.",
|
|
495
|
+
[RUNTIME_002]: 'The remote entry interface does not contain "init"',
|
|
496
|
+
[RUNTIME_003]: "Failed to get manifest.",
|
|
497
|
+
[RUNTIME_004]: "Failed to locate remote.",
|
|
498
|
+
[RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
|
|
499
|
+
[RUNTIME_006]: "Invalid loadShareSync function call from runtime",
|
|
500
|
+
[RUNTIME_007]: "Failed to get remote snapshot.",
|
|
501
|
+
[RUNTIME_008]: "Failed to load script resources.",
|
|
502
|
+
[RUNTIME_009]: "Please call createInstance first.",
|
|
503
|
+
[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.',
|
|
504
|
+
[RUNTIME_011]: "The remoteEntry URL is missing from the remote snapshot."
|
|
505
|
+
};
|
|
506
|
+
({
|
|
507
|
+
...runtimeDescMap
|
|
508
|
+
});
|
|
509
|
+
const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
|
|
510
|
+
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
511
|
+
return new Promise((resolve, reject) => {
|
|
512
|
+
try {
|
|
513
|
+
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${entry}")${importCallback}`)([resolve, reject]);
|
|
514
|
+
else import(
|
|
515
|
+
/* webpackIgnore: true */
|
|
516
|
+
/* @vite-ignore */
|
|
517
|
+
entry
|
|
518
|
+
).then(resolve).catch(reject);
|
|
519
|
+
else resolve(remoteEntryExports);
|
|
520
|
+
} catch (e) {
|
|
521
|
+
error(`Failed to load ESM entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
526
|
+
return new Promise((resolve, reject) => {
|
|
527
|
+
try {
|
|
528
|
+
if (!remoteEntryExports) if (typeof __system_context__ === "undefined") System.import(entry).then(resolve).catch(reject);
|
|
529
|
+
else new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
|
|
530
|
+
else resolve(remoteEntryExports);
|
|
531
|
+
} catch (e) {
|
|
532
|
+
error(`Failed to load SystemJS entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
537
|
+
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
538
|
+
if (!entryExports) error(RUNTIME_001, runtimeDescMap, {
|
|
539
|
+
remoteName: name,
|
|
540
|
+
remoteEntryUrl: entry,
|
|
541
|
+
remoteEntryKey
|
|
542
|
+
});
|
|
543
|
+
return entryExports;
|
|
544
|
+
}
|
|
545
|
+
async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl }) {
|
|
546
|
+
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
547
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
548
|
+
const url = getEntryUrl ? getEntryUrl(entry) : entry;
|
|
549
|
+
return loadScript(url, {
|
|
550
|
+
attrs: {},
|
|
551
|
+
createScriptHook: (url2, attrs) => {
|
|
552
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
553
|
+
url: url2,
|
|
554
|
+
attrs
|
|
555
|
+
});
|
|
556
|
+
if (!res) return;
|
|
557
|
+
if (res instanceof HTMLScriptElement) return res;
|
|
558
|
+
if ("script" in res || "timeout" in res) return res;
|
|
559
|
+
}
|
|
560
|
+
}).then(() => {
|
|
561
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
562
|
+
}, (loadError) => {
|
|
563
|
+
const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
|
|
564
|
+
error(RUNTIME_008, runtimeDescMap, {
|
|
565
|
+
remoteName: name,
|
|
566
|
+
resourceUrl: url
|
|
567
|
+
}, originalMsg);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
|
|
571
|
+
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
572
|
+
switch (type) {
|
|
573
|
+
case "esm":
|
|
574
|
+
case "module":
|
|
575
|
+
return loadEsmEntry({
|
|
576
|
+
entry,
|
|
577
|
+
remoteEntryExports
|
|
578
|
+
});
|
|
579
|
+
case "system":
|
|
580
|
+
return loadSystemJsEntry({
|
|
581
|
+
entry,
|
|
582
|
+
remoteEntryExports
|
|
583
|
+
});
|
|
584
|
+
default:
|
|
585
|
+
return loadEntryScript({
|
|
586
|
+
entry,
|
|
587
|
+
globalName,
|
|
588
|
+
name,
|
|
589
|
+
loaderHook,
|
|
590
|
+
getEntryUrl
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
595
|
+
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
596
|
+
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
597
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
598
|
+
return loadScriptNode(entry, {
|
|
599
|
+
attrs: {
|
|
600
|
+
name,
|
|
601
|
+
globalName,
|
|
602
|
+
type
|
|
603
|
+
},
|
|
604
|
+
loaderHook: { createScriptHook: (url, attrs = {}) => {
|
|
605
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
606
|
+
url,
|
|
607
|
+
attrs
|
|
608
|
+
});
|
|
609
|
+
if (!res) return;
|
|
610
|
+
if ("url" in res) return res;
|
|
611
|
+
} }
|
|
612
|
+
}).then(() => {
|
|
613
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
614
|
+
}).catch((e) => {
|
|
615
|
+
error(`Failed to load Node.js entry for remote "${name}" from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
619
|
+
const { entry, name } = remoteInfo;
|
|
620
|
+
return lazyUtils.composeKeyWithSeparator(name, entry);
|
|
621
|
+
}
|
|
622
|
+
async function getRemoteEntry(params) {
|
|
623
|
+
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
|
|
624
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
625
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
626
|
+
if (!globalLoading[uniqueKey]) {
|
|
627
|
+
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
628
|
+
const loaderHook = origin.loaderHook;
|
|
629
|
+
globalLoading[uniqueKey] = loadEntryHook.emit({
|
|
630
|
+
loaderHook,
|
|
631
|
+
remoteInfo,
|
|
632
|
+
remoteEntryExports
|
|
633
|
+
}).then((res) => {
|
|
634
|
+
if (res) return res;
|
|
635
|
+
return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : logger.isBrowserEnvValue) ? loadEntryDom({
|
|
636
|
+
remoteInfo,
|
|
637
|
+
remoteEntryExports,
|
|
638
|
+
loaderHook,
|
|
639
|
+
getEntryUrl
|
|
640
|
+
}) : loadEntryNode({
|
|
641
|
+
remoteInfo,
|
|
642
|
+
loaderHook
|
|
643
|
+
});
|
|
644
|
+
}).catch(async (err) => {
|
|
645
|
+
const uniqueKey2 = getRemoteEntryUniqueKey(remoteInfo);
|
|
646
|
+
const isScriptExecutionError = err instanceof Error && err.message.includes("ScriptExecutionError");
|
|
647
|
+
if (err instanceof Error && err.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
|
|
648
|
+
const wrappedGetRemoteEntry = (params2) => {
|
|
649
|
+
return getRemoteEntry({
|
|
650
|
+
...params2,
|
|
651
|
+
_inErrorHandling: true
|
|
652
|
+
});
|
|
653
|
+
};
|
|
654
|
+
const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
655
|
+
getRemoteEntry: wrappedGetRemoteEntry,
|
|
656
|
+
origin,
|
|
657
|
+
remoteInfo,
|
|
658
|
+
remoteEntryExports,
|
|
659
|
+
globalLoading,
|
|
660
|
+
uniqueKey: uniqueKey2
|
|
661
|
+
});
|
|
662
|
+
if (RemoteEntryExports) return RemoteEntryExports;
|
|
663
|
+
}
|
|
664
|
+
throw err;
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
return globalLoading[uniqueKey];
|
|
668
|
+
}
|
|
669
|
+
function getRemoteInfo(remote) {
|
|
670
|
+
return {
|
|
671
|
+
...remote,
|
|
672
|
+
entry: "entry" in remote ? remote.entry : "",
|
|
673
|
+
type: remote.type || DEFAULT_REMOTE_TYPE,
|
|
674
|
+
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
675
|
+
shareScope: remote.shareScope || DEFAULT_SCOPE
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
|
|
679
|
+
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
680
|
+
if (host.options.inBrowser) {
|
|
681
|
+
entryAssets.forEach((asset) => {
|
|
682
|
+
const { moduleInfo } = asset;
|
|
683
|
+
const module2 = host.moduleCache.get(remoteInfo.name);
|
|
684
|
+
if (module2) getRemoteEntry({
|
|
685
|
+
origin: host,
|
|
686
|
+
remoteInfo: moduleInfo,
|
|
687
|
+
remoteEntryExports: module2.remoteEntryExports
|
|
688
|
+
});
|
|
689
|
+
else getRemoteEntry({
|
|
690
|
+
origin: host,
|
|
691
|
+
remoteInfo: moduleInfo,
|
|
692
|
+
remoteEntryExports: void 0
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
if (useLinkPreload) {
|
|
696
|
+
const defaultAttrs = {
|
|
697
|
+
rel: "preload",
|
|
698
|
+
as: "style"
|
|
699
|
+
};
|
|
700
|
+
cssAssets.forEach((cssUrl) => {
|
|
701
|
+
const { link: cssEl, needAttach } = createLink({
|
|
702
|
+
url: cssUrl,
|
|
703
|
+
cb: () => {
|
|
704
|
+
},
|
|
705
|
+
attrs: defaultAttrs,
|
|
706
|
+
createLinkHook: (url, attrs) => {
|
|
707
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
708
|
+
url,
|
|
709
|
+
attrs
|
|
710
|
+
});
|
|
711
|
+
if (res instanceof HTMLLinkElement) return res;
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
needAttach && document.head.appendChild(cssEl);
|
|
715
|
+
});
|
|
716
|
+
} else {
|
|
717
|
+
const defaultAttrs = {
|
|
718
|
+
rel: "stylesheet",
|
|
719
|
+
type: "text/css"
|
|
720
|
+
};
|
|
721
|
+
cssAssets.forEach((cssUrl) => {
|
|
722
|
+
const { link: cssEl, needAttach } = createLink({
|
|
723
|
+
url: cssUrl,
|
|
724
|
+
cb: () => {
|
|
725
|
+
},
|
|
726
|
+
attrs: defaultAttrs,
|
|
727
|
+
createLinkHook: (url, attrs) => {
|
|
728
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
729
|
+
url,
|
|
730
|
+
attrs
|
|
731
|
+
});
|
|
732
|
+
if (res instanceof HTMLLinkElement) return res;
|
|
733
|
+
},
|
|
734
|
+
needDeleteLink: false
|
|
735
|
+
});
|
|
736
|
+
needAttach && document.head.appendChild(cssEl);
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
if (useLinkPreload) {
|
|
740
|
+
const defaultAttrs = {
|
|
741
|
+
rel: "preload",
|
|
742
|
+
as: "script"
|
|
743
|
+
};
|
|
744
|
+
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
745
|
+
const { link: linkEl, needAttach } = createLink({
|
|
746
|
+
url: jsUrl,
|
|
747
|
+
cb: () => {
|
|
748
|
+
},
|
|
749
|
+
attrs: defaultAttrs,
|
|
750
|
+
createLinkHook: (url, attrs) => {
|
|
751
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
752
|
+
url,
|
|
753
|
+
attrs
|
|
754
|
+
});
|
|
755
|
+
if (res instanceof HTMLLinkElement) return res;
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
needAttach && document.head.appendChild(linkEl);
|
|
759
|
+
});
|
|
760
|
+
} else {
|
|
761
|
+
const defaultAttrs = {
|
|
762
|
+
fetchpriority: "high",
|
|
763
|
+
type: (remoteInfo == null ? void 0 : remoteInfo.type) === "module" ? "module" : "text/javascript"
|
|
764
|
+
};
|
|
765
|
+
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
766
|
+
const { script: scriptEl, needAttach } = createScript({
|
|
767
|
+
url: jsUrl,
|
|
768
|
+
cb: () => {
|
|
769
|
+
},
|
|
770
|
+
attrs: defaultAttrs,
|
|
771
|
+
createScriptHook: (url, attrs) => {
|
|
772
|
+
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
773
|
+
url,
|
|
774
|
+
attrs
|
|
775
|
+
});
|
|
776
|
+
if (res instanceof HTMLScriptElement) return res;
|
|
777
|
+
},
|
|
778
|
+
needDeleteScript: true
|
|
779
|
+
});
|
|
780
|
+
needAttach && document.head.appendChild(scriptEl);
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
var helpers_default = {
|
|
786
|
+
utils: {
|
|
787
|
+
matchRemoteWithNameAndExpose,
|
|
788
|
+
preloadAssets,
|
|
789
|
+
getRemoteInfo
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
|
|
793
|
+
const helpers = helpers_default;
|
|
794
|
+
const utils = helpers.utils;
|
|
795
|
+
const runtimeHelpers = {
|
|
796
|
+
utils
|
|
797
|
+
};
|
|
798
|
+
async function prefetch(options) {
|
|
799
|
+
const { instance, id, dataFetchParams, preloadComponentResource } = options;
|
|
800
|
+
if (!id) {
|
|
801
|
+
lazyUtils.logger.error("id is required for prefetch!");
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (!instance) {
|
|
805
|
+
lazyUtils.logger.error("instance is required for prefetch!");
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
const matchedRemoteInfo = runtimeHelpers.utils.matchRemoteWithNameAndExpose(
|
|
809
|
+
instance.options.remotes,
|
|
810
|
+
id
|
|
811
|
+
);
|
|
812
|
+
if (!matchedRemoteInfo) {
|
|
813
|
+
lazyUtils.logger.error(`Can not found '${id}' in instance.options.remotes!`);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
const { remote, expose } = matchedRemoteInfo;
|
|
817
|
+
const { remoteSnapshot, globalSnapshot } = await instance.snapshotHandler.loadRemoteSnapshotInfo({
|
|
818
|
+
moduleInfo: remote,
|
|
819
|
+
id,
|
|
820
|
+
expose
|
|
821
|
+
});
|
|
822
|
+
if (preloadComponentResource) {
|
|
823
|
+
const remoteInfo = runtimeHelpers.utils.getRemoteInfo(remote);
|
|
824
|
+
Promise.resolve(
|
|
825
|
+
instance.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
|
|
826
|
+
origin: instance,
|
|
827
|
+
preloadOptions: {
|
|
828
|
+
remote,
|
|
829
|
+
preloadConfig: {
|
|
830
|
+
nameOrAlias: remote.name,
|
|
831
|
+
exposes: [expose]
|
|
832
|
+
}
|
|
833
|
+
},
|
|
834
|
+
remote,
|
|
835
|
+
remoteInfo,
|
|
836
|
+
globalSnapshot,
|
|
837
|
+
remoteSnapshot
|
|
838
|
+
})
|
|
839
|
+
).then((assets) => {
|
|
840
|
+
if (assets) {
|
|
841
|
+
runtimeHelpers.utils.preloadAssets(remoteInfo, instance, assets);
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
const dataFetchMap = lazyUtils.getDataFetchMap();
|
|
846
|
+
if (!dataFetchMap) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
const dataFetchInfo = lazyUtils.getDataFetchInfo({
|
|
850
|
+
name: remote.name,
|
|
851
|
+
alias: remote.alias,
|
|
852
|
+
id,
|
|
853
|
+
remoteSnapshot
|
|
854
|
+
});
|
|
855
|
+
const dataFetchMapKey = lazyUtils.getDataFetchMapKey(dataFetchInfo, {
|
|
856
|
+
name: instance.name,
|
|
857
|
+
version: instance.options.version
|
|
858
|
+
});
|
|
859
|
+
if (!dataFetchMapKey) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
const dataFetchItem = dataFetchMap[dataFetchMapKey];
|
|
863
|
+
if (!dataFetchItem) {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
const [getDataFetchGetter, _type, getDataFetchPromise] = dataFetchItem[0];
|
|
867
|
+
let _getDataFetchPromise = getDataFetchPromise;
|
|
868
|
+
if (!getDataFetchPromise) {
|
|
869
|
+
if (!getDataFetchGetter) {
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
_getDataFetchPromise = getDataFetchGetter();
|
|
873
|
+
}
|
|
874
|
+
_getDataFetchPromise.then((dataFetchFn) => {
|
|
875
|
+
return dataFetchFn({
|
|
876
|
+
...dataFetchParams,
|
|
877
|
+
_id: dataFetchMapKey,
|
|
878
|
+
isDowngrade: false
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
exports.dataFetchFunction = dataFetchFunction;
|
|
883
|
+
exports.injectDataFetch = injectDataFetch;
|
|
884
|
+
exports.prefetch = prefetch;
|