@module-federation/bridge-react 0.0.0-chore-bump-node-22-20260710161714

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/base.cjs.js +29 -0
  4. package/dist/base.d.ts +311 -0
  5. package/dist/base.es.js +30 -0
  6. package/dist/bridge-base-CIOXqUYV.mjs +214 -0
  7. package/dist/bridge-base-HLp3d7aF.js +229 -0
  8. package/dist/createHelpers-BY5Uj9_Z.mjs +192 -0
  9. package/dist/createHelpers-DNBacpxb.js +191 -0
  10. package/dist/data-fetch-server-middleware.cjs.js +163 -0
  11. package/dist/data-fetch-server-middleware.d.ts +15 -0
  12. package/dist/data-fetch-server-middleware.es.js +164 -0
  13. package/dist/data-fetch-utils.cjs.js +24 -0
  14. package/dist/data-fetch-utils.d.ts +81 -0
  15. package/dist/data-fetch-utils.es.js +26 -0
  16. package/dist/data-fetch.cjs.js +22 -0
  17. package/dist/data-fetch.d.ts +140 -0
  18. package/dist/data-fetch.es.js +22 -0
  19. package/dist/index-Bs2NxD2z.mjs +46 -0
  20. package/dist/index-DbjGCKOr.js +45 -0
  21. package/dist/index.cjs.js +125 -0
  22. package/dist/index.d.ts +299 -0
  23. package/dist/index.es.js +109 -0
  24. package/dist/lazy-load-component-plugin-BjMVNoep.js +521 -0
  25. package/dist/lazy-load-component-plugin-aj97Vt-4.mjs +522 -0
  26. package/dist/lazy-load-component-plugin.cjs.js +6 -0
  27. package/dist/lazy-load-component-plugin.d.ts +16 -0
  28. package/dist/lazy-load-component-plugin.es.js +6 -0
  29. package/dist/lazy-utils.cjs.js +24 -0
  30. package/dist/lazy-utils.d.ts +149 -0
  31. package/dist/lazy-utils.es.js +24 -0
  32. package/dist/logger-DwWkXsWl.mjs +139 -0
  33. package/dist/logger-Dxblx6P-.js +138 -0
  34. package/dist/plugin.cjs.js +14 -0
  35. package/dist/plugin.d.ts +22 -0
  36. package/dist/plugin.es.js +14 -0
  37. package/dist/prefetch-BwRDb4SJ.mjs +1082 -0
  38. package/dist/prefetch-DLhPTofn.js +1081 -0
  39. package/dist/router-v5.cjs.js +57 -0
  40. package/dist/router-v5.d.ts +17 -0
  41. package/dist/router-v5.es.js +34 -0
  42. package/dist/router-v6.cjs.js +84 -0
  43. package/dist/router-v6.d.ts +20 -0
  44. package/dist/router-v6.es.js +61 -0
  45. package/dist/router-v7.cjs.js +85 -0
  46. package/dist/router-v7.d.ts +19 -0
  47. package/dist/router-v7.es.js +63 -0
  48. package/dist/router.cjs.js +82 -0
  49. package/dist/router.d.ts +20 -0
  50. package/dist/router.es.js +60 -0
  51. package/dist/utils-CFTy4LVE.js +2029 -0
  52. package/dist/utils-DGS4pYp8.mjs +2030 -0
  53. package/dist/v18.cjs.js +15 -0
  54. package/dist/v18.d.ts +114 -0
  55. package/dist/v18.es.js +15 -0
  56. package/dist/v19.cjs.js +15 -0
  57. package/dist/v19.d.ts +115 -0
  58. package/dist/v19.es.js +15 -0
  59. package/package.json +189 -0
@@ -0,0 +1,1081 @@
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((event == null ? void 0 : event.isTimeout) ? `ScriptNetworkError: Script "${info.url}" timed out.` : `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, {
96
+ type: "error",
97
+ isTimeout: true
98
+ });
99
+ }, timeout);
100
+ return {
101
+ script,
102
+ needAttach
103
+ };
104
+ }
105
+ function createLink(info) {
106
+ let link = null;
107
+ let needAttach = true;
108
+ let timeout = 2e4;
109
+ let timeoutId;
110
+ const links = document.getElementsByTagName("link");
111
+ for (let i = 0; i < links.length; i++) {
112
+ const l = links[i];
113
+ const linkHref = l.getAttribute("href");
114
+ const linkRel = l.getAttribute("rel");
115
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
116
+ link = l;
117
+ needAttach = false;
118
+ break;
119
+ }
120
+ }
121
+ if (!link) {
122
+ link = document.createElement("link");
123
+ link.setAttribute("href", info.url);
124
+ let createLinkRes = void 0;
125
+ let shouldApplyAttrs = true;
126
+ const attrs = info.attrs;
127
+ if (info.createLinkHook) {
128
+ createLinkRes = info.createLinkHook(info.url, attrs);
129
+ if (createLinkRes instanceof HTMLLinkElement) {
130
+ link = createLinkRes;
131
+ shouldApplyAttrs = false;
132
+ } else if (typeof createLinkRes === "object") {
133
+ if ("link" in createLinkRes && createLinkRes.link) {
134
+ link = createLinkRes.link;
135
+ shouldApplyAttrs = false;
136
+ }
137
+ if ("timeout" in createLinkRes && createLinkRes.timeout) timeout = createLinkRes.timeout;
138
+ }
139
+ }
140
+ if (attrs && shouldApplyAttrs) Object.keys(attrs).forEach((name) => {
141
+ if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
142
+ });
143
+ }
144
+ if (!needAttach) {
145
+ Promise.resolve().then(() => {
146
+ (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
147
+ });
148
+ return {
149
+ link,
150
+ needAttach
151
+ };
152
+ }
153
+ const onLinkComplete = (prev, event) => {
154
+ if (timeoutId) clearTimeout(timeoutId);
155
+ const onLinkCompleteCallback = () => {
156
+ if ((event == null ? void 0 : event.type) === "error") {
157
+ const linkError = /* @__PURE__ */ new Error((event == null ? void 0 : event.isTimeout) ? `LinkNetworkError: Link "${info.url}" timed out.` : `LinkNetworkError: Failed to load link "${info.url}" - the URL is unreachable or the server returned an error.`);
158
+ linkError.name = "LinkNetworkError";
159
+ (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(linkError));
160
+ } else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
161
+ };
162
+ if (link) {
163
+ link.onerror = null;
164
+ link.onload = null;
165
+ safeWrapper(() => {
166
+ const { needDeleteLink = true } = info;
167
+ if (needDeleteLink) (link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
168
+ });
169
+ if (prev) {
170
+ const res = prev(event);
171
+ onLinkCompleteCallback();
172
+ return res;
173
+ }
174
+ }
175
+ onLinkCompleteCallback();
176
+ };
177
+ link.onerror = onLinkComplete.bind(null, link.onerror);
178
+ link.onload = onLinkComplete.bind(null, link.onload);
179
+ timeoutId = setTimeout(() => {
180
+ onLinkComplete(null, {
181
+ type: "error",
182
+ isTimeout: true
183
+ });
184
+ }, timeout);
185
+ return {
186
+ link,
187
+ needAttach
188
+ };
189
+ }
190
+ function loadScript(url, info) {
191
+ const { attrs = {}, createScriptHook } = info;
192
+ return new Promise((resolve, reject) => {
193
+ const { script, needAttach } = createScript({
194
+ url,
195
+ cb: resolve,
196
+ onErrorCallback: reject,
197
+ attrs: {
198
+ fetchpriority: "high",
199
+ ...attrs
200
+ },
201
+ createScriptHook,
202
+ needDeleteScript: true
203
+ });
204
+ needAttach && document.head.appendChild(script);
205
+ });
206
+ }
207
+ const sdkImportCache = /* @__PURE__ */ new Map();
208
+ function importNodeModule(name) {
209
+ if (!name) throw new Error("import specifier is required");
210
+ if (sdkImportCache.has(name)) return sdkImportCache.get(name);
211
+ const promise = new Function("name", `return import(name)`)(name).then((res) => res).catch((error2) => {
212
+ console.error(`Error importing module ${name}:`, error2);
213
+ sdkImportCache.delete(name);
214
+ throw error2;
215
+ });
216
+ sdkImportCache.set(name, promise);
217
+ return promise;
218
+ }
219
+ const lazyLoaderHookFetch = async (input, init, loaderHook) => {
220
+ const hook = (url, init2) => {
221
+ return loaderHook.lifecycle.fetch.emit(url, init2);
222
+ };
223
+ const res = await hook(input, init || {});
224
+ if (!res || !(res instanceof Response)) return fetch(input, init || {});
225
+ return res;
226
+ };
227
+ const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
228
+ if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
229
+ const hookResult = loaderHook.createScriptHook(url);
230
+ if (hookResult && typeof hookResult === "object" && "url" in hookResult) url = hookResult.url;
231
+ }
232
+ let urlObj;
233
+ try {
234
+ urlObj = new URL(url);
235
+ } catch (e) {
236
+ console.error("Error constructing URL:", e);
237
+ cb(/* @__PURE__ */ new Error(`Invalid URL: ${e}`));
238
+ return;
239
+ }
240
+ const getFetch = async () => {
241
+ if (loaderHook == null ? void 0 : loaderHook.fetch) return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
242
+ return fetch;
243
+ };
244
+ const handleScriptFetch = async (f, urlObj2) => {
245
+ var _a;
246
+ try {
247
+ const res = await f(urlObj2.href);
248
+ const data = await res.text();
249
+ const [path, vm] = await Promise.all([importNodeModule("path"), importNodeModule("vm")]);
250
+ const scriptContext = {
251
+ exports: {},
252
+ module: { exports: {} }
253
+ };
254
+ const urlDirname = urlObj2.pathname.split("/").slice(0, -1).join("/");
255
+ const filename = path.basename(urlObj2.pathname);
256
+ const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
257
+ })`, {
258
+ filename,
259
+ importModuleDynamically: ((_a = vm.constants) == null ? void 0 : _a.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
260
+ });
261
+ let requireFn;
262
+ requireFn = (await importNodeModule("node:module")).createRequire(urlObj2.protocol === "file:" || urlObj2.protocol === "node:" ? urlObj2.href : path.join(process.cwd(), "__mf_require_base__.js"));
263
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, requireFn, urlDirname, filename);
264
+ const exportedInterface = scriptContext.module.exports || scriptContext.exports;
265
+ if (attrs && exportedInterface && attrs["globalName"]) {
266
+ cb(void 0, exportedInterface[attrs["globalName"]] || exportedInterface);
267
+ return;
268
+ }
269
+ cb(void 0, exportedInterface);
270
+ } catch (e) {
271
+ cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
272
+ }
273
+ };
274
+ getFetch().then(async (f) => {
275
+ if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") return loadModule(urlObj.href, {
276
+ fetch: f,
277
+ vm: await importNodeModule("vm")
278
+ }).then(async (module2) => {
279
+ await module2.evaluate();
280
+ cb(void 0, module2.namespace);
281
+ }).catch((e) => {
282
+ cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
283
+ });
284
+ handleScriptFetch(f, urlObj);
285
+ }).catch((err) => {
286
+ cb(err);
287
+ });
288
+ } : (url, cb, attrs, loaderHook) => {
289
+ cb(/* @__PURE__ */ new Error("createScriptNode is disabled in non-Node.js environment"));
290
+ };
291
+ const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, info) => {
292
+ return new Promise((resolve, reject) => {
293
+ createScriptNode(url, (error2, scriptContext) => {
294
+ var _a, _b;
295
+ if (error2) reject(error2);
296
+ else {
297
+ 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__`;
298
+ resolve(globalThis[remoteEntryKey] = scriptContext);
299
+ }
300
+ }, info.attrs, info.loaderHook);
301
+ });
302
+ } : (url, info) => {
303
+ throw new Error("loadScriptNode is disabled in non-Node.js environment");
304
+ };
305
+ const esmModuleCache = /* @__PURE__ */ new Map();
306
+ const isFetchableRemoteModuleUrl = (url) => url.startsWith("http:") || url.startsWith("https:");
307
+ const isBareModuleSpecifier = (specifier) => !specifier.startsWith("./") && !specifier.startsWith("../") && !specifier.startsWith("/") && !specifier.includes(":");
308
+ function encodeRemoteModulePath(url) {
309
+ const remoteUrl = new URL(url);
310
+ const encodedProtocol = encodeURIComponent(remoteUrl.protocol.slice(0, -1));
311
+ const encodedHost = encodeURIComponent(remoteUrl.host);
312
+ const encodedPathname = remoteUrl.pathname.split("/").map((segment) => encodeURIComponent(segment)).join("/");
313
+ const encodedSearchHash = encodeURIComponent(`${remoteUrl.search}${remoteUrl.hash}`);
314
+ return `/${encodedProtocol}/${encodedHost}${encodedPathname}${encodedSearchHash ? `/${encodedSearchHash}` : ""}`;
315
+ }
316
+ function createImportMetaUrl(url, baseFileUrl) {
317
+ const baseUrl = baseFileUrl.endsWith("/") ? baseFileUrl : `${baseFileUrl}/`;
318
+ return new URL(`__module_federation_remote__${encodeRemoteModulePath(url)}`, baseUrl).href;
319
+ }
320
+ async function isNodeBuiltinSpecifier(specifier) {
321
+ if (specifier.startsWith("node:")) return true;
322
+ if (!isBareModuleSpecifier(specifier)) return false;
323
+ return (await importNodeModule("node:module")).builtinModules.includes(specifier);
324
+ }
325
+ function getSyntheticModuleExports(moduleExports) {
326
+ const namespaceObject = moduleExports && (typeof moduleExports === "object" || typeof moduleExports === "function") ? moduleExports : { default: moduleExports };
327
+ const effectiveExports = { ...namespaceObject };
328
+ if (!Object.prototype.hasOwnProperty.call(effectiveExports, "default")) effectiveExports.default = namespaceObject;
329
+ return effectiveExports;
330
+ }
331
+ async function createSyntheticModuleFromExports(identifier, moduleExports, vm) {
332
+ if (typeof vm.SyntheticModule !== "function") throw new Error("vm.SyntheticModule is required to load Node.js built-in modules in ESM remote entries.");
333
+ const effectiveExports = getSyntheticModuleExports(moduleExports);
334
+ const exportNames = Object.keys(effectiveExports);
335
+ const syntheticModule = new vm.SyntheticModule(exportNames, function setSyntheticModuleExports() {
336
+ for (const name of exportNames) this.setExport(name, effectiveExports[name]);
337
+ }, { identifier });
338
+ esmModuleCache.set(identifier, syntheticModule);
339
+ await syntheticModule.link(async () => {
340
+ throw new Error(`Node.js built-in module "${identifier}" should not request child modules.`);
341
+ });
342
+ await syntheticModule.evaluate();
343
+ return syntheticModule;
344
+ }
345
+ async function loadNodeBuiltinModule(specifier, vm) {
346
+ const cacheKey = `node-builtin:${specifier}`;
347
+ if (esmModuleCache.has(cacheKey)) return esmModuleCache.get(cacheKey);
348
+ return createSyntheticModuleFromExports(cacheKey, await importNodeModule(specifier), vm);
349
+ }
350
+ async function loadResolvedModule(specifier, parentUrl, options) {
351
+ if (await isNodeBuiltinSpecifier(specifier)) return loadNodeBuiltinModule(specifier, options.vm);
352
+ if (isBareModuleSpecifier(specifier)) throw new Error(`Unsupported ESM module specifier "${specifier}". Only relative or absolute http(s) remote modules and Node.js built-in modules are supported.`);
353
+ const resolvedUrl = new URL(specifier, parentUrl).href;
354
+ if (!isFetchableRemoteModuleUrl(resolvedUrl)) throw new Error(`Unsupported ESM module specifier "${specifier}" resolved to "${resolvedUrl}". Only http(s) remote modules and Node.js built-in modules are supported.`);
355
+ return loadModule(resolvedUrl, options);
356
+ }
357
+ async function evaluateDynamicModule(module2) {
358
+ if (module2.status === "linked") await module2.evaluate();
359
+ if (module2.status === "errored") throw module2.error;
360
+ return module2;
361
+ }
362
+ async function loadModule(url, options) {
363
+ if (esmModuleCache.has(url)) return esmModuleCache.get(url);
364
+ const { fetch: fetch2, vm } = options;
365
+ if (!isFetchableRemoteModuleUrl(url)) throw new Error(`Unsupported ESM module URL "${url}". Only http(s) remote modules and Node.js built-in modules are supported.`);
366
+ const code = await (await fetch2(url)).text();
367
+ const cwdFileUrl = (await importNodeModule("node:url")).pathToFileURL(process.cwd()).href;
368
+ const sourceTextModule = new vm.SourceTextModule(code, {
369
+ identifier: url,
370
+ initializeImportMeta: (meta) => {
371
+ meta.url = createImportMetaUrl(url, cwdFileUrl);
372
+ },
373
+ importModuleDynamically: async (specifier) => {
374
+ return evaluateDynamicModule(await loadResolvedModule(specifier, url, options));
375
+ }
376
+ });
377
+ esmModuleCache.set(url, sourceTextModule);
378
+ await sourceTextModule.link(async (specifier) => {
379
+ return loadResolvedModule(specifier, url, options);
380
+ });
381
+ return sourceTextModule;
382
+ }
383
+ const dataFetchFunction = async function(options) {
384
+ var _a, _b;
385
+ const [id, data, downgrade] = options;
386
+ lazyUtils.logger.debug("==========call data fetch function!");
387
+ if (data) {
388
+ if (!id) {
389
+ throw new Error("id is required!");
390
+ }
391
+ if (!lazyUtils.getDataFetchMap()) {
392
+ lazyUtils.initDataFetchMap();
393
+ }
394
+ const dataFetchItem = lazyUtils.getDataFetchItem(id);
395
+ if (dataFetchItem) {
396
+ (_b = (_a = dataFetchItem[1]) == null ? void 0 : _a[1]) == null ? void 0 : _b.call(_a, data);
397
+ dataFetchItem[2] = lazyUtils.MF_DATA_FETCH_STATUS.LOADED;
398
+ return;
399
+ }
400
+ if (!dataFetchItem) {
401
+ const dataFetchMap = lazyUtils.getDataFetchMap();
402
+ let res;
403
+ let rej;
404
+ const p = new Promise((resolve, reject) => {
405
+ res = resolve;
406
+ rej = reject;
407
+ });
408
+ dataFetchMap[id] = [
409
+ [
410
+ async () => async () => {
411
+ return "";
412
+ },
413
+ lazyUtils.MF_DATA_FETCH_TYPE.FETCH_SERVER
414
+ ],
415
+ [p, res, rej],
416
+ lazyUtils.MF_DATA_FETCH_STATUS.LOADED
417
+ ];
418
+ res && res(data);
419
+ return;
420
+ }
421
+ }
422
+ if (downgrade) {
423
+ const mfDowngrade2 = lazyUtils.getDowngradeTag();
424
+ if (!mfDowngrade2) {
425
+ globalThis[lazyUtils.DOWNGRADE_KEY] = id ? [id] : true;
426
+ } else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
427
+ mfDowngrade2.push(id);
428
+ }
429
+ }
430
+ const mfDowngrade = lazyUtils.getDowngradeTag();
431
+ if (typeof mfDowngrade === "boolean") {
432
+ return lazyUtils.callAllDowngrade();
433
+ }
434
+ if (Array.isArray(mfDowngrade)) {
435
+ if (!id) {
436
+ globalThis[lazyUtils.DOWNGRADE_KEY] = true;
437
+ return lazyUtils.callAllDowngrade();
438
+ }
439
+ if (!mfDowngrade.includes(id)) {
440
+ mfDowngrade.push(id);
441
+ }
442
+ return lazyUtils.callDowngrade(id);
443
+ }
444
+ };
445
+ function injectDataFetch() {
446
+ var _a;
447
+ globalThis[_a = lazyUtils.DATA_FETCH_FUNCTION] || (globalThis[_a] = []);
448
+ const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
449
+ if (dataFetch.push === dataFetchFunction) {
450
+ return;
451
+ }
452
+ if (typeof window === "undefined") {
453
+ return;
454
+ }
455
+ globalThis[lazyUtils.FS_HREF] = window.location.href;
456
+ dataFetch.push = dataFetchFunction;
457
+ }
458
+ const getDocsUrl = (errorCode) => {
459
+ return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split("-")[0].toLowerCase()}#${errorCode.toLowerCase()}`;
460
+ };
461
+ const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
462
+ const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
463
+ args && msg.push(`args: ${JSON.stringify(args)}`);
464
+ msg.push(getDocsUrl(errorCode));
465
+ originalErrorMsg && msg.push(`Original Error Message:
466
+ ${originalErrorMsg}`);
467
+ return msg.join("\n");
468
+ };
469
+ function logAndReport(code, descMap, args, logger2, originalErrorMsg, context) {
470
+ return logger2(getShortErrorMsg(code, descMap, args, originalErrorMsg));
471
+ }
472
+ const LOG_CATEGORY = "[ Federation Runtime ]";
473
+ function error(msgOrCode, descMap, args, originalErrorMsg, context) {
474
+ if (descMap !== void 0) return logAndReport(msgOrCode, descMap, args ?? {}, (msg2) => {
475
+ throw new Error(`${LOG_CATEGORY}: ${msg2}`);
476
+ }, originalErrorMsg);
477
+ const msg = msgOrCode;
478
+ if (msg instanceof Error) {
479
+ if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
480
+ throw msg;
481
+ }
482
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
483
+ }
484
+ const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
485
+ const nativeGlobal = (() => {
486
+ try {
487
+ return document.defaultView;
488
+ } catch {
489
+ return CurrentGlobal;
490
+ }
491
+ })();
492
+ function definePropertyGlobalVal(target, key, val) {
493
+ Object.defineProperty(target, key, {
494
+ value: val,
495
+ configurable: false,
496
+ writable: true
497
+ });
498
+ }
499
+ function includeOwnProperty(target, key) {
500
+ return Object.hasOwnProperty.call(target, key);
501
+ }
502
+ if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
503
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
504
+ function setGlobalDefaultVal(target) {
505
+ var _a, _b, _c, _d, _e, _f;
506
+ if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
507
+ if (!includeOwnProperty(target, "__FEDERATION__")) {
508
+ definePropertyGlobalVal(target, "__FEDERATION__", {
509
+ __GLOBAL_PLUGIN__: [],
510
+ __INSTANCES__: [],
511
+ moduleInfo: {},
512
+ __SHARE__: {},
513
+ __MANIFEST_LOADING__: {},
514
+ __PRELOADED_MAP__: /* @__PURE__ */ new Map()
515
+ });
516
+ definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
517
+ }
518
+ (_a = target.__FEDERATION__).__GLOBAL_PLUGIN__ ?? (_a.__GLOBAL_PLUGIN__ = []);
519
+ (_b = target.__FEDERATION__).__INSTANCES__ ?? (_b.__INSTANCES__ = []);
520
+ (_c = target.__FEDERATION__).moduleInfo ?? (_c.moduleInfo = {});
521
+ (_d = target.__FEDERATION__).__SHARE__ ?? (_d.__SHARE__ = {});
522
+ (_e = target.__FEDERATION__).__MANIFEST_LOADING__ ?? (_e.__MANIFEST_LOADING__ = {});
523
+ (_f = target.__FEDERATION__).__PRELOADED_MAP__ ?? (_f.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
524
+ }
525
+ setGlobalDefaultVal(CurrentGlobal);
526
+ setGlobalDefaultVal(nativeGlobal);
527
+ const getRemoteEntryExports = (name, globalName) => {
528
+ const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
529
+ return {
530
+ remoteEntryKey,
531
+ entryExports: CurrentGlobal[remoteEntryKey]
532
+ };
533
+ };
534
+ const DEFAULT_SCOPE = "default";
535
+ const DEFAULT_REMOTE_TYPE = "global";
536
+ function matchRemoteWithNameAndExpose(remotes, id) {
537
+ for (const remote of remotes) {
538
+ const isNameMatched = id.startsWith(remote.name);
539
+ let expose = id.replace(remote.name, "");
540
+ if (isNameMatched) {
541
+ if (expose.startsWith("/")) {
542
+ const pkgNameOrAlias = remote.name;
543
+ expose = `.${expose}`;
544
+ return {
545
+ pkgNameOrAlias,
546
+ expose,
547
+ remote
548
+ };
549
+ } else if (expose === "") return {
550
+ pkgNameOrAlias: remote.name,
551
+ expose: ".",
552
+ remote
553
+ };
554
+ }
555
+ const isAliasMatched = remote.alias && id.startsWith(remote.alias);
556
+ let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
557
+ if (remote.alias && isAliasMatched) {
558
+ if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
559
+ const pkgNameOrAlias = remote.alias;
560
+ exposeWithAlias = `.${exposeWithAlias}`;
561
+ return {
562
+ pkgNameOrAlias,
563
+ expose: exposeWithAlias,
564
+ remote
565
+ };
566
+ } else if (exposeWithAlias === "") return {
567
+ pkgNameOrAlias: remote.alias,
568
+ expose: ".",
569
+ remote
570
+ };
571
+ }
572
+ }
573
+ }
574
+ const RUNTIME_001 = "RUNTIME-001";
575
+ const RUNTIME_002 = "RUNTIME-002";
576
+ const RUNTIME_003 = "RUNTIME-003";
577
+ const RUNTIME_004 = "RUNTIME-004";
578
+ const RUNTIME_005 = "RUNTIME-005";
579
+ const RUNTIME_006 = "RUNTIME-006";
580
+ const RUNTIME_007 = "RUNTIME-007";
581
+ const RUNTIME_008 = "RUNTIME-008";
582
+ const RUNTIME_009 = "RUNTIME-009";
583
+ const RUNTIME_010 = "RUNTIME-010";
584
+ const RUNTIME_011 = "RUNTIME-011";
585
+ const RUNTIME_012 = "RUNTIME-012";
586
+ const RUNTIME_013 = "RUNTIME-013";
587
+ const RUNTIME_014 = "RUNTIME-014";
588
+ const RUNTIME_015 = "RUNTIME-015";
589
+ const runtimeDescMap = {
590
+ [RUNTIME_001]: "Failed to get remoteEntry exports.",
591
+ [RUNTIME_002]: 'The remote entry interface does not contain "init"',
592
+ [RUNTIME_003]: "Failed to get manifest.",
593
+ [RUNTIME_004]: "Failed to locate remote.",
594
+ [RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
595
+ [RUNTIME_006]: "Invalid loadShareSync function call from runtime",
596
+ [RUNTIME_007]: "Failed to get remote snapshot.",
597
+ [RUNTIME_008]: "Failed to load script resources.",
598
+ [RUNTIME_009]: "Please call createInstance first.",
599
+ [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.',
600
+ [RUNTIME_011]: "The remoteEntry URL is missing from the remote snapshot.",
601
+ [RUNTIME_012]: 'The getter for the shared module is not a function. This may be caused by setting "shared.import: false" without the host providing the corresponding lib.',
602
+ [RUNTIME_013]: "The manifest is not a valid Module Federation manifest.",
603
+ [RUNTIME_014]: "The remote does not expose the requested module.",
604
+ [RUNTIME_015]: "Remote container initialization failed."
605
+ };
606
+ ({
607
+ ...runtimeDescMap
608
+ });
609
+ const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
610
+ async function loadEsmEntry({ entry, remoteEntryExports }) {
611
+ return new Promise((resolve, reject) => {
612
+ try {
613
+ if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${entry}")${importCallback}`)([resolve, reject]);
614
+ else import(
615
+ /* webpackIgnore: true */
616
+ /* @vite-ignore */
617
+ entry
618
+ ).then(resolve).catch(reject);
619
+ else resolve(remoteEntryExports);
620
+ } catch (e) {
621
+ error(`Failed to load ESM entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
622
+ }
623
+ });
624
+ }
625
+ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
626
+ return new Promise((resolve, reject) => {
627
+ try {
628
+ if (!remoteEntryExports) if (typeof __system_context__ === "undefined") System.import(entry).then(resolve).catch(reject);
629
+ else new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
630
+ else resolve(remoteEntryExports);
631
+ } catch (e) {
632
+ error(`Failed to load SystemJS entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
633
+ }
634
+ });
635
+ }
636
+ function handleRemoteEntryLoaded(name, globalName, entry) {
637
+ const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
638
+ if (!entryExports) error(RUNTIME_001, runtimeDescMap, {
639
+ remoteName: name,
640
+ remoteEntryUrl: entry,
641
+ remoteEntryKey
642
+ });
643
+ return entryExports;
644
+ }
645
+ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook, getEntryUrl, resourceContext }) {
646
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
647
+ if (remoteEntryExports) return remoteEntryExports;
648
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
649
+ return loadScript(url, {
650
+ attrs: {},
651
+ createScriptHook: (url2, attrs) => {
652
+ const res = loaderHook.lifecycle.createScript.emit({
653
+ url: url2,
654
+ attrs,
655
+ remoteInfo,
656
+ resourceContext: resourceContext ? {
657
+ ...resourceContext,
658
+ url: url2
659
+ } : void 0
660
+ });
661
+ if (!res) return;
662
+ if (res instanceof HTMLScriptElement) return res;
663
+ if ("script" in res || "timeout" in res) return res;
664
+ }
665
+ }).then(() => {
666
+ return handleRemoteEntryLoaded(name, globalName, entry);
667
+ }, (loadError) => {
668
+ const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
669
+ error(RUNTIME_008, runtimeDescMap, {
670
+ remoteName: name,
671
+ resourceUrl: url
672
+ }, originalMsg);
673
+ });
674
+ }
675
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, resourceContext }) {
676
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
677
+ switch (type) {
678
+ case "esm":
679
+ case "module":
680
+ return loadEsmEntry({
681
+ entry,
682
+ remoteEntryExports
683
+ });
684
+ case "system":
685
+ return loadSystemJsEntry({
686
+ entry,
687
+ remoteEntryExports
688
+ });
689
+ default:
690
+ return loadEntryScript({
691
+ entry,
692
+ globalName,
693
+ name,
694
+ remoteInfo,
695
+ loaderHook,
696
+ getEntryUrl,
697
+ resourceContext
698
+ });
699
+ }
700
+ }
701
+ async function loadEntryNode({ remoteInfo, loaderHook, resourceContext }) {
702
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
703
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
704
+ if (remoteEntryExports) return remoteEntryExports;
705
+ return loadScriptNode(entry, {
706
+ attrs: {
707
+ name,
708
+ globalName,
709
+ type
710
+ },
711
+ loaderHook: { createScriptHook: (url, attrs = {}) => {
712
+ const res = loaderHook.lifecycle.createScript.emit({
713
+ url,
714
+ attrs,
715
+ remoteInfo,
716
+ resourceContext: resourceContext ? {
717
+ ...resourceContext,
718
+ url
719
+ } : void 0
720
+ });
721
+ if (!res) return;
722
+ if ("url" in res) return res;
723
+ } }
724
+ }).then(() => {
725
+ return handleRemoteEntryLoaded(name, globalName, entry);
726
+ }).catch((e) => {
727
+ error(`Failed to load Node.js entry for remote "${name}" from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
728
+ });
729
+ }
730
+ function getRemoteEntryUniqueKey(remoteInfo) {
731
+ const { entry, name } = remoteInfo;
732
+ return lazyUtils.composeKeyWithSeparator(name, entry);
733
+ }
734
+ async function getRemoteEntry(params) {
735
+ const { origin, remoteEntryExports, remoteInfo, getEntryUrl, resourceContext, _inErrorHandling = false } = params;
736
+ const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
737
+ if (remoteEntryExports) return remoteEntryExports;
738
+ if (!globalLoading[uniqueKey]) {
739
+ const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
740
+ const loaderHook = origin.loaderHook;
741
+ globalLoading[uniqueKey] = loadEntryHook.emit({
742
+ origin,
743
+ loaderHook,
744
+ remoteInfo,
745
+ remoteEntryExports
746
+ }).then((res) => {
747
+ if (res) return res;
748
+ return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : logger.isBrowserEnvValue) ? loadEntryDom({
749
+ remoteInfo,
750
+ remoteEntryExports,
751
+ loaderHook,
752
+ getEntryUrl,
753
+ resourceContext
754
+ }) : loadEntryNode({
755
+ remoteInfo,
756
+ loaderHook,
757
+ resourceContext
758
+ });
759
+ }).then(async (res) => {
760
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
761
+ origin,
762
+ remoteInfo,
763
+ remoteEntryExports: res
764
+ });
765
+ return res;
766
+ }).catch(async (err) => {
767
+ const uniqueKey2 = getRemoteEntryUniqueKey(remoteInfo);
768
+ const isScriptExecutionError = err instanceof Error && err.message.includes("ScriptExecutionError");
769
+ if (err instanceof Error && err.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
770
+ const wrappedGetRemoteEntry = (params2) => {
771
+ return getRemoteEntry({
772
+ ...params2,
773
+ _inErrorHandling: true
774
+ });
775
+ };
776
+ const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
777
+ getRemoteEntry: wrappedGetRemoteEntry,
778
+ origin,
779
+ remoteInfo,
780
+ remoteEntryExports,
781
+ globalLoading,
782
+ uniqueKey: uniqueKey2
783
+ });
784
+ if (RemoteEntryExports) {
785
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
786
+ origin,
787
+ remoteInfo,
788
+ remoteEntryExports: RemoteEntryExports,
789
+ recovered: true
790
+ });
791
+ return RemoteEntryExports;
792
+ }
793
+ }
794
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
795
+ origin,
796
+ remoteInfo,
797
+ error: err
798
+ });
799
+ throw err;
800
+ });
801
+ }
802
+ return globalLoading[uniqueKey];
803
+ }
804
+ function getRemoteInfo(remote) {
805
+ return {
806
+ ...remote,
807
+ entry: "entry" in remote ? remote.entry : "",
808
+ type: remote.type || DEFAULT_REMOTE_TYPE,
809
+ entryGlobalName: remote.entryGlobalName || remote.name,
810
+ shareScope: remote.shareScope || DEFAULT_SCOPE
811
+ };
812
+ }
813
+ function isTimeoutError(error2) {
814
+ if (!(error2 instanceof Error)) return false;
815
+ return error2.message.includes("timed out") || error2.name.includes("Timeout");
816
+ }
817
+ function createAssetResult(context, url, status, error2) {
818
+ return {
819
+ url,
820
+ status,
821
+ resourceType: context.resourceType,
822
+ initiator: context.initiator,
823
+ id: context.id,
824
+ error: error2
825
+ };
826
+ }
827
+ async function waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, context) {
828
+ const cachedRemote = host.moduleCache.get(entryRemoteInfo.name);
829
+ const url = entryRemoteInfo.entry;
830
+ if (cachedRemote == null ? void 0 : cachedRemote.remoteEntryExports) return createAssetResult(context, url, "cached");
831
+ try {
832
+ if (!await getRemoteEntry({
833
+ origin: host,
834
+ remoteInfo: entryRemoteInfo,
835
+ remoteEntryExports: cachedRemote == null ? void 0 : cachedRemote.remoteEntryExports,
836
+ resourceContext: {
837
+ ...context,
838
+ url
839
+ }
840
+ })) throw new Error(`Failed to load remoteEntry "${url}".`);
841
+ return createAssetResult(context, url, "success");
842
+ } catch (error2) {
843
+ return createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2);
844
+ }
845
+ }
846
+ function waitForLinkPreload({ host, remoteInfo, url, attrs, context, needDeleteLink }) {
847
+ return new Promise((resolve) => {
848
+ const { link, needAttach } = createLink({
849
+ url,
850
+ cb: () => {
851
+ resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
852
+ },
853
+ onErrorCallback: (error2) => {
854
+ resolve(createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2));
855
+ },
856
+ attrs,
857
+ createLinkHook: (hookUrl, hookAttrs) => {
858
+ const res = host.loaderHook.lifecycle.createLink.emit({
859
+ url: hookUrl,
860
+ attrs: hookAttrs,
861
+ remoteInfo,
862
+ resourceContext: {
863
+ ...context,
864
+ url: hookUrl
865
+ }
866
+ });
867
+ if (res instanceof HTMLLinkElement) return res;
868
+ return res;
869
+ },
870
+ needDeleteLink
871
+ });
872
+ needAttach && document.head.appendChild(link);
873
+ });
874
+ }
875
+ function waitForScriptPreload({ host, remoteInfo, url, attrs, context }) {
876
+ return new Promise((resolve) => {
877
+ const { script, needAttach } = createScript({
878
+ url,
879
+ cb: () => {
880
+ resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
881
+ },
882
+ onErrorCallback: (error2) => {
883
+ resolve(createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2));
884
+ },
885
+ attrs,
886
+ createScriptHook: (hookUrl, hookAttrs) => {
887
+ const res = host.loaderHook.lifecycle.createScript.emit({
888
+ url: hookUrl,
889
+ attrs: hookAttrs,
890
+ remoteInfo,
891
+ resourceContext: {
892
+ ...context,
893
+ url: hookUrl
894
+ }
895
+ });
896
+ if (res instanceof HTMLScriptElement) return res;
897
+ return res;
898
+ },
899
+ needDeleteScript: true
900
+ });
901
+ needAttach && document.head.appendChild(script);
902
+ });
903
+ }
904
+ function createResourceContext(baseContext, resourceType) {
905
+ return {
906
+ ...baseContext,
907
+ resourceType
908
+ };
909
+ }
910
+ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseContext = {
911
+ initiator: "preloadRemote",
912
+ id: remoteInfo.name
913
+ }) {
914
+ const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
915
+ const results = [];
916
+ if (host.options.inBrowser) {
917
+ entryAssets.forEach((asset) => {
918
+ const { moduleInfo: entryRemoteInfo } = asset;
919
+ results.push(waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, createResourceContext(baseContext, "remoteEntry")));
920
+ });
921
+ if (useLinkPreload) {
922
+ const defaultAttrs = {
923
+ rel: "preload",
924
+ as: "style"
925
+ };
926
+ cssAssets.forEach((cssUrl) => {
927
+ results.push(waitForLinkPreload({
928
+ host,
929
+ remoteInfo,
930
+ url: cssUrl,
931
+ attrs: defaultAttrs,
932
+ context: createResourceContext(baseContext, "css")
933
+ }));
934
+ });
935
+ } else {
936
+ const defaultAttrs = {
937
+ rel: "stylesheet",
938
+ type: "text/css"
939
+ };
940
+ cssAssets.forEach((cssUrl) => {
941
+ results.push(waitForLinkPreload({
942
+ host,
943
+ remoteInfo,
944
+ url: cssUrl,
945
+ attrs: defaultAttrs,
946
+ needDeleteLink: false,
947
+ context: createResourceContext(baseContext, "css")
948
+ }));
949
+ });
950
+ }
951
+ if (useLinkPreload) {
952
+ const defaultAttrs = {
953
+ rel: "preload",
954
+ as: "script"
955
+ };
956
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
957
+ results.push(waitForLinkPreload({
958
+ host,
959
+ remoteInfo,
960
+ url: jsUrl,
961
+ attrs: defaultAttrs,
962
+ context: createResourceContext(baseContext, "js")
963
+ }));
964
+ });
965
+ } else {
966
+ const defaultAttrs = {
967
+ fetchpriority: "high",
968
+ type: (remoteInfo == null ? void 0 : remoteInfo.type) === "module" ? "module" : "text/javascript"
969
+ };
970
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
971
+ results.push(waitForScriptPreload({
972
+ host,
973
+ remoteInfo,
974
+ url: jsUrl,
975
+ attrs: defaultAttrs,
976
+ context: createResourceContext(baseContext, "js")
977
+ }));
978
+ });
979
+ }
980
+ }
981
+ return Promise.all(results);
982
+ }
983
+ var helpers_default = {
984
+ utils: {
985
+ matchRemoteWithNameAndExpose,
986
+ preloadAssets,
987
+ getRemoteInfo
988
+ }
989
+ };
990
+ typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
991
+ const helpers = helpers_default;
992
+ const utils = helpers.utils;
993
+ const runtimeHelpers = {
994
+ utils
995
+ };
996
+ async function prefetch(options) {
997
+ const { instance, id, dataFetchParams, preloadComponentResource } = options;
998
+ if (!id) {
999
+ lazyUtils.logger.error("id is required for prefetch!");
1000
+ return;
1001
+ }
1002
+ if (!instance) {
1003
+ lazyUtils.logger.error("instance is required for prefetch!");
1004
+ return;
1005
+ }
1006
+ const matchedRemoteInfo = runtimeHelpers.utils.matchRemoteWithNameAndExpose(
1007
+ instance.options.remotes,
1008
+ id
1009
+ );
1010
+ if (!matchedRemoteInfo) {
1011
+ lazyUtils.logger.error(`Can not found '${id}' in instance.options.remotes!`);
1012
+ return;
1013
+ }
1014
+ const { remote, expose } = matchedRemoteInfo;
1015
+ const { remoteSnapshot, globalSnapshot } = await instance.snapshotHandler.loadRemoteSnapshotInfo({
1016
+ moduleInfo: remote,
1017
+ id
1018
+ });
1019
+ if (preloadComponentResource) {
1020
+ const remoteInfo = runtimeHelpers.utils.getRemoteInfo(remote);
1021
+ Promise.resolve(
1022
+ instance.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
1023
+ origin: instance,
1024
+ preloadOptions: {
1025
+ remote,
1026
+ preloadConfig: {
1027
+ nameOrAlias: remote.name,
1028
+ exposes: [expose]
1029
+ }
1030
+ },
1031
+ remote,
1032
+ remoteInfo,
1033
+ globalSnapshot,
1034
+ remoteSnapshot
1035
+ })
1036
+ ).then((assets) => {
1037
+ if (assets) {
1038
+ runtimeHelpers.utils.preloadAssets(remoteInfo, instance, assets);
1039
+ }
1040
+ });
1041
+ }
1042
+ const dataFetchMap = lazyUtils.getDataFetchMap();
1043
+ if (!dataFetchMap) {
1044
+ return;
1045
+ }
1046
+ const dataFetchInfo = lazyUtils.getDataFetchInfo({
1047
+ name: remote.name,
1048
+ alias: remote.alias,
1049
+ id,
1050
+ remoteSnapshot
1051
+ });
1052
+ const dataFetchMapKey = lazyUtils.getDataFetchMapKey(dataFetchInfo, {
1053
+ name: instance.name,
1054
+ version: instance.options.version
1055
+ });
1056
+ if (!dataFetchMapKey) {
1057
+ return;
1058
+ }
1059
+ const dataFetchItem = dataFetchMap[dataFetchMapKey];
1060
+ if (!dataFetchItem) {
1061
+ return;
1062
+ }
1063
+ const [getDataFetchGetter, _type, getDataFetchPromise] = dataFetchItem[0];
1064
+ let _getDataFetchPromise = getDataFetchPromise;
1065
+ if (!getDataFetchPromise) {
1066
+ if (!getDataFetchGetter) {
1067
+ return;
1068
+ }
1069
+ _getDataFetchPromise = getDataFetchGetter();
1070
+ }
1071
+ _getDataFetchPromise.then((dataFetchFn) => {
1072
+ return dataFetchFn({
1073
+ ...dataFetchParams,
1074
+ _id: dataFetchMapKey,
1075
+ isDowngrade: false
1076
+ });
1077
+ });
1078
+ }
1079
+ exports.dataFetchFunction = dataFetchFunction;
1080
+ exports.injectDataFetch = injectDataFetch;
1081
+ exports.prefetch = prefetch;