@module-federation/bridge-react 0.0.0-perf-devtools-20260108034446 → 0.0.0-perf-website-code-usage-20260914033703

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 (161) hide show
  1. package/dist/base.cjs.js +4 -4
  2. package/dist/base.d.ts +8 -311
  3. package/dist/base.es.js +11 -11
  4. package/dist/{bridge-base-CPSTBjEp.mjs → bridge-base-CHnL6Q9P.mjs} +63 -103
  5. package/dist/{bridge-base-RStDxH71.js → bridge-base-DSYKAGGD.js} +63 -102
  6. package/dist/{createHelpers-Ui5pt7je.mjs → createHelpers-D3Sg5lKp.mjs} +32 -17
  7. package/dist/{createHelpers-B_L612IN.js → createHelpers-D6thyyLv.js} +30 -15
  8. package/dist/data-fetch-server-middleware.cjs.js +4 -4
  9. package/dist/data-fetch-server-middleware.d.ts +1 -15
  10. package/dist/data-fetch-server-middleware.es.js +2 -2
  11. package/dist/data-fetch-utils.cjs.js +2 -2
  12. package/dist/data-fetch-utils.d.ts +1 -81
  13. package/dist/data-fetch-utils.es.js +7 -7
  14. package/dist/data-fetch.cjs.js +22 -0
  15. package/dist/data-fetch.d.ts +4 -0
  16. package/dist/data-fetch.es.js +22 -0
  17. package/dist/error-boundary.d.ts +17 -0
  18. package/dist/error-boundary.spec.d.ts +1 -0
  19. package/dist/{index-DyQNwY2M.mjs → index-Bs2NxD2z.mjs} +1 -1
  20. package/dist/{index-DRSBaSu3.js → index-DbjGCKOr.js} +2 -2
  21. package/dist/index.cjs.js +27 -6
  22. package/dist/index.d.ts +12 -299
  23. package/dist/index.es.js +34 -13
  24. package/dist/lazy/AwaitDataFetch.d.ts +24 -0
  25. package/dist/lazy/HydratedStylesheetAssets.d.ts +4 -0
  26. package/dist/lazy/constant.d.ts +26 -0
  27. package/dist/lazy/createLazyComponent.d.ts +28 -0
  28. package/dist/lazy/data-fetch/cache.d.ts +34 -0
  29. package/dist/lazy/data-fetch/cache.spec.d.ts +1 -0
  30. package/dist/lazy/data-fetch/call-data-fetch.d.ts +1 -0
  31. package/dist/lazy/data-fetch/data-fetch-server-middleware.d.ts +3 -0
  32. package/{src/lazy/data-fetch/index.ts → dist/lazy/data-fetch/index.d.ts} +1 -11
  33. package/dist/lazy/data-fetch/inject-data-fetch.d.ts +4 -0
  34. package/dist/lazy/data-fetch/prefetch.d.ts +9 -0
  35. package/dist/lazy/data-fetch/runtime-plugin.d.ts +3 -0
  36. package/dist/lazy/index.d.ts +9 -0
  37. package/dist/lazy/logger.d.ts +2 -0
  38. package/dist/lazy/types.d.ts +60 -0
  39. package/dist/lazy/utils.d.ts +48 -0
  40. package/dist/lazy/wrapNoSSR.d.ts +9 -0
  41. package/dist/{lazy-load-component-plugin-BvnyaA6i.js → lazy-load-component-plugin-DSURjnZ0.js} +170 -44
  42. package/dist/{lazy-load-component-plugin-CVcFMRce.mjs → lazy-load-component-plugin-NZphPG7_.mjs} +174 -48
  43. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  44. package/dist/lazy-load-component-plugin.d.ts +2 -16
  45. package/dist/lazy-load-component-plugin.es.js +2 -2
  46. package/dist/lazy-utils.cjs.js +2 -2
  47. package/dist/lazy-utils.d.ts +1 -149
  48. package/dist/lazy-utils.es.js +19 -19
  49. package/dist/logger-DwWkXsWl.mjs +139 -0
  50. package/dist/logger-Dxblx6P-.js +138 -0
  51. package/dist/plugin.d.ts +2 -22
  52. package/dist/plugins/lazy-load-component-plugin.d.ts +12 -0
  53. package/dist/plugins/lazy-load-component-plugin.spec.d.ts +1 -0
  54. package/dist/prefetch-Bxf6DSx_.js +1477 -0
  55. package/dist/prefetch-TKq_EK_q.mjs +1478 -0
  56. package/dist/provider/context.d.ts +3 -0
  57. package/dist/provider/plugin.d.ts +7 -0
  58. package/dist/provider/versions/bridge-base.d.ts +5 -0
  59. package/dist/provider/versions/legacy.d.ts +26 -0
  60. package/dist/provider/versions/v18.d.ts +19 -0
  61. package/dist/provider/versions/v19.d.ts +21 -0
  62. package/dist/remote/RemoteAppWrapper.d.ts +7 -0
  63. package/dist/remote/base-component/create.d.ts +9 -0
  64. package/dist/remote/base-component/index.d.ts +5 -0
  65. package/dist/remote/createHelpers.d.ts +17 -0
  66. package/dist/remote/router-component/component.d.ts +8 -0
  67. package/dist/remote/router-component/create.d.ts +9 -0
  68. package/dist/remote/router-component/index.d.ts +5 -0
  69. package/dist/router/default.d.ts +7 -0
  70. package/dist/router/v5.d.ts +4 -0
  71. package/dist/router/v6.d.ts +7 -0
  72. package/dist/router/v7.d.ts +6 -0
  73. package/dist/router-v5.cjs.js +5 -3
  74. package/dist/router-v5.d.ts +1 -18
  75. package/dist/router-v5.es.js +5 -3
  76. package/dist/router-v6.cjs.js +1 -1
  77. package/dist/router-v6.d.ts +1 -20
  78. package/dist/router-v6.es.js +1 -1
  79. package/dist/router-v7.cjs.js +5 -3
  80. package/dist/router-v7.d.ts +1 -20
  81. package/dist/router-v7.es.js +5 -3
  82. package/dist/router.cjs.js +1 -1
  83. package/dist/router.d.ts +1 -20
  84. package/dist/router.es.js +1 -1
  85. package/dist/shared/size-limited-cache.d.ts +29 -0
  86. package/dist/shared/size-limited-cache.spec.d.ts +1 -0
  87. package/dist/size-limited-cache.cjs.js +82 -0
  88. package/dist/size-limited-cache.d.ts +1 -0
  89. package/dist/size-limited-cache.es.js +82 -0
  90. package/dist/types.d.ts +137 -0
  91. package/dist/utils/index.d.ts +4 -0
  92. package/dist/utils-5dGErM3C.js +588 -0
  93. package/dist/utils-BBP3hEeV.mjs +589 -0
  94. package/dist/v18.cjs.js +1 -1
  95. package/dist/v18.d.ts +3 -114
  96. package/dist/v18.es.js +1 -1
  97. package/dist/v19.cjs.js +1 -1
  98. package/dist/v19.d.ts +3 -115
  99. package/dist/v19.es.js +1 -1
  100. package/package.json +35 -14
  101. package/CHANGELOG.md +0 -735
  102. package/__tests__/bridge.spec.tsx +0 -160
  103. package/__tests__/createLazyComponent.spec.tsx +0 -209
  104. package/__tests__/prefetch.spec.ts +0 -156
  105. package/__tests__/router.spec.tsx +0 -82
  106. package/__tests__/setupTests.ts +0 -8
  107. package/__tests__/util.ts +0 -36
  108. package/dist/index.esm-BWaKho-8.js +0 -491
  109. package/dist/index.esm-CPwSeCvw.mjs +0 -492
  110. package/dist/prefetch-CK3EZdY4.mjs +0 -1273
  111. package/dist/prefetch-MiXeF8KH.js +0 -1272
  112. package/dist/utils-dUgb9Jkm.mjs +0 -2016
  113. package/dist/utils-tM9yE73c.js +0 -2015
  114. package/jest.config.ts +0 -21
  115. package/project.json +0 -23
  116. package/src/base.ts +0 -50
  117. package/src/index.ts +0 -50
  118. package/src/lazy/AwaitDataFetch.tsx +0 -215
  119. package/src/lazy/constant.ts +0 -30
  120. package/src/lazy/createLazyComponent.tsx +0 -411
  121. package/src/lazy/data-fetch/cache.ts +0 -291
  122. package/src/lazy/data-fetch/call-data-fetch.ts +0 -13
  123. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +0 -196
  124. package/src/lazy/data-fetch/inject-data-fetch.ts +0 -109
  125. package/src/lazy/data-fetch/prefetch.ts +0 -112
  126. package/src/lazy/data-fetch/runtime-plugin.ts +0 -115
  127. package/src/lazy/index.ts +0 -35
  128. package/src/lazy/logger.ts +0 -6
  129. package/src/lazy/types.ts +0 -75
  130. package/src/lazy/utils.ts +0 -372
  131. package/src/lazy/wrapNoSSR.tsx +0 -10
  132. package/src/modern-app-env.d.ts +0 -2
  133. package/src/plugins/lazy-load-component-plugin.spec.ts +0 -21
  134. package/src/plugins/lazy-load-component-plugin.ts +0 -57
  135. package/src/provider/context.tsx +0 -4
  136. package/src/provider/plugin.ts +0 -22
  137. package/src/provider/versions/bridge-base.tsx +0 -150
  138. package/src/provider/versions/legacy.ts +0 -87
  139. package/src/provider/versions/v18.ts +0 -47
  140. package/src/provider/versions/v19.ts +0 -48
  141. package/src/remote/RemoteAppWrapper.tsx +0 -108
  142. package/src/remote/base-component/create.tsx +0 -23
  143. package/src/remote/base-component/index.tsx +0 -10
  144. package/src/remote/createHelpers.tsx +0 -130
  145. package/src/remote/router-component/component.tsx +0 -104
  146. package/src/remote/router-component/create.tsx +0 -23
  147. package/src/remote/router-component/index.tsx +0 -10
  148. package/src/router/default.tsx +0 -73
  149. package/src/router/v5.tsx +0 -43
  150. package/src/router/v6.tsx +0 -74
  151. package/src/router/v7.tsx +0 -75
  152. package/src/types.ts +0 -147
  153. package/src/utils/index.ts +0 -44
  154. package/src/v18.ts +0 -9
  155. package/src/v19.ts +0 -9
  156. package/tsconfig.json +0 -42
  157. package/tsconfig.node.json +0 -11
  158. package/tsconfig.spec.json +0 -26
  159. package/vite.config.ts +0 -112
  160. package/vitest.config.ts +0 -27
  161. /package/{src/remote/base-component/component.tsx → dist/remote/base-component/component.d.ts} +0 -0
@@ -0,0 +1,1478 @@
1
+ import { B as warn, y as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger, e as getDataFetchMap, i as initDataFetchMap, o as getDataFetchItem, M as MF_DATA_FETCH_STATUS, q as MF_DATA_FETCH_TYPE, G as DOWNGRADE_KEY, H as callAllDowngrade, I as callDowngrade, J as getDowngradeTag, K as composeKeyWithSeparator, N as safeToString, m as getDataFetchInfo, n as getDataFetchMapKey } from "./utils-BBP3hEeV.mjs";
2
+ import { i as isBrowserEnvValue } from "./logger-DwWkXsWl.mjs";
3
+ async function safeWrapper(callback, disableWarn) {
4
+ try {
5
+ return await callback();
6
+ } catch (e) {
7
+ warn(e);
8
+ return;
9
+ }
10
+ }
11
+ function isStaticResourcesEqual(url1, url2) {
12
+ const REG_EXP = /^(https?:)?\/\//i;
13
+ return url1.replace(REG_EXP, "").replace(/\/$/, "") === url2.replace(REG_EXP, "").replace(/\/$/, "");
14
+ }
15
+ function createScript(info) {
16
+ let script = null;
17
+ let needAttach = true;
18
+ let timeout = 2e4;
19
+ let timeoutId;
20
+ const scripts = document.getElementsByTagName("script");
21
+ for (let i = 0; i < scripts.length; i++) {
22
+ const s = scripts[i];
23
+ const scriptSrc = s.getAttribute("src");
24
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
25
+ script = s;
26
+ needAttach = false;
27
+ break;
28
+ }
29
+ }
30
+ if (!script) {
31
+ const attrs = info.attrs;
32
+ script = document.createElement("script");
33
+ script.type = (attrs == null ? void 0 : attrs["type"]) === "module" ? "module" : "text/javascript";
34
+ let createScriptRes = void 0;
35
+ if (info.createScriptHook) {
36
+ createScriptRes = info.createScriptHook(info.url, info.attrs);
37
+ if (createScriptRes instanceof HTMLScriptElement) script = createScriptRes;
38
+ else if (typeof createScriptRes === "object") {
39
+ if ("script" in createScriptRes && createScriptRes.script) script = createScriptRes.script;
40
+ if ("timeout" in createScriptRes && createScriptRes.timeout) timeout = createScriptRes.timeout;
41
+ }
42
+ }
43
+ if (!script.src) script.src = info.url;
44
+ if (attrs && !createScriptRes) Object.keys(attrs).forEach((name) => {
45
+ if (script) {
46
+ if (name === "async" || name === "defer") script[name] = attrs[name];
47
+ else if (!script.getAttribute(name)) script.setAttribute(name, attrs[name]);
48
+ }
49
+ });
50
+ }
51
+ let executionError = null;
52
+ const executionErrorHandler = typeof window !== "undefined" ? (evt) => {
53
+ if (evt.filename && isStaticResourcesEqual(evt.filename, info.url)) {
54
+ 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})`);
55
+ err.name = "ScriptExecutionError";
56
+ executionError = err;
57
+ }
58
+ } : null;
59
+ if (executionErrorHandler) window.addEventListener("error", executionErrorHandler);
60
+ const onScriptComplete = async (prev, event) => {
61
+ clearTimeout(timeoutId);
62
+ if (executionErrorHandler) window.removeEventListener("error", executionErrorHandler);
63
+ const onScriptCompleteCallback = () => {
64
+ if ((event == null ? void 0 : event.type) === "error") {
65
+ 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.)`);
66
+ networkError.name = "ScriptNetworkError";
67
+ (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(networkError));
68
+ } else if (executionError) (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(executionError));
69
+ else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
70
+ };
71
+ if (script) {
72
+ script.onerror = null;
73
+ script.onload = null;
74
+ safeWrapper(() => {
75
+ const { needDeleteScript = true } = info;
76
+ if (needDeleteScript) (script == null ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
77
+ });
78
+ if (prev && typeof prev === "function") {
79
+ const result = prev(event);
80
+ if (result instanceof Promise) {
81
+ const res = await result;
82
+ onScriptCompleteCallback();
83
+ return res;
84
+ }
85
+ onScriptCompleteCallback();
86
+ return result;
87
+ }
88
+ }
89
+ onScriptCompleteCallback();
90
+ };
91
+ script.onerror = onScriptComplete.bind(null, script.onerror);
92
+ script.onload = onScriptComplete.bind(null, script.onload);
93
+ timeoutId = setTimeout(() => {
94
+ onScriptComplete(null, {
95
+ type: "error",
96
+ isTimeout: true
97
+ });
98
+ }, timeout);
99
+ return {
100
+ script,
101
+ needAttach
102
+ };
103
+ }
104
+ function createLink(info) {
105
+ let link = null;
106
+ let needAttach = true;
107
+ let timeout = 2e4;
108
+ let timeoutId;
109
+ const links = document.getElementsByTagName("link");
110
+ for (let i = 0; i < links.length; i++) {
111
+ const l = links[i];
112
+ const linkHref = l.getAttribute("href");
113
+ const linkRel = l.getAttribute("rel");
114
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
115
+ link = l;
116
+ needAttach = false;
117
+ break;
118
+ }
119
+ }
120
+ if (!link) {
121
+ link = document.createElement("link");
122
+ link.setAttribute("href", info.url);
123
+ let createLinkRes = void 0;
124
+ let shouldApplyAttrs = true;
125
+ const attrs = info.attrs;
126
+ if (info.createLinkHook) {
127
+ createLinkRes = info.createLinkHook(info.url, attrs);
128
+ if (createLinkRes instanceof HTMLLinkElement) {
129
+ link = createLinkRes;
130
+ shouldApplyAttrs = false;
131
+ } else if (typeof createLinkRes === "object") {
132
+ if ("link" in createLinkRes && createLinkRes.link) {
133
+ link = createLinkRes.link;
134
+ shouldApplyAttrs = false;
135
+ }
136
+ if ("timeout" in createLinkRes && createLinkRes.timeout) timeout = createLinkRes.timeout;
137
+ }
138
+ }
139
+ if (attrs && shouldApplyAttrs) Object.keys(attrs).forEach((name) => {
140
+ if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
141
+ });
142
+ }
143
+ if (!needAttach) {
144
+ Promise.resolve().then(() => {
145
+ (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
146
+ });
147
+ return {
148
+ link,
149
+ needAttach
150
+ };
151
+ }
152
+ const onLinkComplete = (prev, event) => {
153
+ if (timeoutId) clearTimeout(timeoutId);
154
+ const onLinkCompleteCallback = () => {
155
+ if ((event == null ? void 0 : event.type) === "error") {
156
+ 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.`);
157
+ linkError.name = "LinkNetworkError";
158
+ (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(linkError));
159
+ } else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
160
+ };
161
+ if (link) {
162
+ link.onerror = null;
163
+ link.onload = null;
164
+ safeWrapper(() => {
165
+ const { needDeleteLink = true } = info;
166
+ if (needDeleteLink) (link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
167
+ });
168
+ if (prev) {
169
+ const res = prev(event);
170
+ onLinkCompleteCallback();
171
+ return res;
172
+ }
173
+ }
174
+ onLinkCompleteCallback();
175
+ };
176
+ link.onerror = onLinkComplete.bind(null, link.onerror);
177
+ link.onload = onLinkComplete.bind(null, link.onload);
178
+ timeoutId = setTimeout(() => {
179
+ onLinkComplete(null, {
180
+ type: "error",
181
+ isTimeout: true
182
+ });
183
+ }, timeout);
184
+ return {
185
+ link,
186
+ needAttach
187
+ };
188
+ }
189
+ function loadScript(url, info) {
190
+ const { attrs = {}, createScriptHook } = info;
191
+ return new Promise((resolve, reject) => {
192
+ const { script, needAttach } = createScript({
193
+ url,
194
+ cb: resolve,
195
+ onErrorCallback: reject,
196
+ attrs: {
197
+ fetchpriority: "high",
198
+ ...attrs
199
+ },
200
+ createScriptHook,
201
+ needDeleteScript: true
202
+ });
203
+ needAttach && document.head.appendChild(script);
204
+ });
205
+ }
206
+ const sdkImportCache = /* @__PURE__ */ new Map();
207
+ function importNodeModule(name) {
208
+ if (!name) throw new Error("import specifier is required");
209
+ if (sdkImportCache.has(name)) return sdkImportCache.get(name);
210
+ const promise = new Function("name", `return import(name)`)(name).then((res) => res).catch((error2) => {
211
+ console.error(`Error importing module ${name}:`, error2);
212
+ sdkImportCache.delete(name);
213
+ throw error2;
214
+ });
215
+ sdkImportCache.set(name, promise);
216
+ return promise;
217
+ }
218
+ const lazyLoaderHookFetch = async (input, init, loaderHook) => {
219
+ const hook = (url, init2) => {
220
+ return loaderHook.lifecycle.fetch.emit(url, init2);
221
+ };
222
+ const res = await hook(input, init || {});
223
+ if (!res || !(res instanceof Response)) return fetch(input, init || {});
224
+ return res;
225
+ };
226
+ const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
227
+ if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
228
+ const hookResult = loaderHook.createScriptHook(url);
229
+ if (hookResult && typeof hookResult === "object" && "url" in hookResult) url = hookResult.url;
230
+ }
231
+ let urlObj;
232
+ try {
233
+ urlObj = new URL(url);
234
+ } catch (e) {
235
+ console.error("Error constructing URL:", e);
236
+ cb(/* @__PURE__ */ new Error(`Invalid URL: ${e}`));
237
+ return;
238
+ }
239
+ const getFetch = async () => {
240
+ if (loaderHook == null ? void 0 : loaderHook.fetch) return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
241
+ return fetch;
242
+ };
243
+ const handleScriptFetch = async (f, urlObj2) => {
244
+ var _a;
245
+ try {
246
+ const res = await f(urlObj2.href);
247
+ const data = await res.text();
248
+ const [path, vm] = await Promise.all([importNodeModule("path"), importNodeModule("vm")]);
249
+ const scriptContext = {
250
+ exports: {},
251
+ module: { exports: {} }
252
+ };
253
+ const urlDirname = urlObj2.pathname.split("/").slice(0, -1).join("/");
254
+ const filename = path.basename(urlObj2.pathname);
255
+ const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
256
+ })`, {
257
+ filename,
258
+ importModuleDynamically: ((_a = vm.constants) == null ? void 0 : _a.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
259
+ });
260
+ let requireFn;
261
+ requireFn = (await importNodeModule("node:module")).createRequire(urlObj2.protocol === "file:" || urlObj2.protocol === "node:" ? urlObj2.href : path.join(process.cwd(), "__mf_require_base__.js"));
262
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, requireFn, urlDirname, filename);
263
+ const exportedInterface = scriptContext.module.exports || scriptContext.exports;
264
+ if (attrs && exportedInterface && attrs["globalName"]) {
265
+ cb(void 0, exportedInterface[attrs["globalName"]] || exportedInterface);
266
+ return;
267
+ }
268
+ cb(void 0, exportedInterface);
269
+ } catch (e) {
270
+ cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
271
+ }
272
+ };
273
+ getFetch().then(async (f) => {
274
+ if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") return loadModule(urlObj.href, {
275
+ fetch: f,
276
+ vm: await importNodeModule("vm")
277
+ }).then(async (module) => {
278
+ await module.evaluate();
279
+ cb(void 0, module.namespace);
280
+ }).catch((e) => {
281
+ cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
282
+ });
283
+ handleScriptFetch(f, urlObj);
284
+ }).catch((err) => {
285
+ cb(err);
286
+ });
287
+ } : (url, cb, attrs, loaderHook) => {
288
+ cb(/* @__PURE__ */ new Error("createScriptNode is disabled in non-Node.js environment"));
289
+ };
290
+ const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, info) => {
291
+ return new Promise((resolve, reject) => {
292
+ createScriptNode(url, (error2, scriptContext) => {
293
+ var _a, _b;
294
+ if (error2) reject(error2);
295
+ else {
296
+ 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__`;
297
+ resolve(globalThis[remoteEntryKey] = scriptContext);
298
+ }
299
+ }, info.attrs, info.loaderHook);
300
+ });
301
+ } : (url, info) => {
302
+ throw new Error("loadScriptNode is disabled in non-Node.js environment");
303
+ };
304
+ const esmModuleCache = /* @__PURE__ */ new Map();
305
+ const isFetchableRemoteModuleUrl = (url) => url.startsWith("http:") || url.startsWith("https:");
306
+ const isBareModuleSpecifier = (specifier) => !specifier.startsWith("./") && !specifier.startsWith("../") && !specifier.startsWith("/") && !specifier.includes(":");
307
+ function encodeRemoteModulePath(url) {
308
+ const remoteUrl = new URL(url);
309
+ const encodedProtocol = encodeURIComponent(remoteUrl.protocol.slice(0, -1));
310
+ const encodedHost = encodeURIComponent(remoteUrl.host);
311
+ const encodedPathname = remoteUrl.pathname.split("/").map((segment) => encodeURIComponent(segment)).join("/");
312
+ const encodedSearchHash = encodeURIComponent(`${remoteUrl.search}${remoteUrl.hash}`);
313
+ return `/${encodedProtocol}/${encodedHost}${encodedPathname}${encodedSearchHash ? `/${encodedSearchHash}` : ""}`;
314
+ }
315
+ function createImportMetaUrl(url, baseFileUrl) {
316
+ const baseUrl = baseFileUrl.endsWith("/") ? baseFileUrl : `${baseFileUrl}/`;
317
+ return new URL(`__module_federation_remote__${encodeRemoteModulePath(url)}`, baseUrl).href;
318
+ }
319
+ async function isNodeBuiltinSpecifier(specifier) {
320
+ if (specifier.startsWith("node:")) return true;
321
+ if (!isBareModuleSpecifier(specifier)) return false;
322
+ return (await importNodeModule("node:module")).builtinModules.includes(specifier);
323
+ }
324
+ function getSyntheticModuleExports(moduleExports) {
325
+ const namespaceObject = moduleExports && (typeof moduleExports === "object" || typeof moduleExports === "function") ? moduleExports : { default: moduleExports };
326
+ const effectiveExports = { ...namespaceObject };
327
+ if (!Object.prototype.hasOwnProperty.call(effectiveExports, "default")) effectiveExports.default = namespaceObject;
328
+ return effectiveExports;
329
+ }
330
+ async function createSyntheticModuleFromExports(identifier, moduleExports, vm) {
331
+ if (typeof vm.SyntheticModule !== "function") throw new Error("vm.SyntheticModule is required to load Node.js built-in modules in ESM remote entries.");
332
+ const effectiveExports = getSyntheticModuleExports(moduleExports);
333
+ const exportNames = Object.keys(effectiveExports);
334
+ const syntheticModule = new vm.SyntheticModule(exportNames, function setSyntheticModuleExports() {
335
+ for (const name of exportNames) this.setExport(name, effectiveExports[name]);
336
+ }, { identifier });
337
+ esmModuleCache.set(identifier, syntheticModule);
338
+ await syntheticModule.link(async () => {
339
+ throw new Error(`Node.js built-in module "${identifier}" should not request child modules.`);
340
+ });
341
+ await syntheticModule.evaluate();
342
+ return syntheticModule;
343
+ }
344
+ async function loadNodeBuiltinModule(specifier, vm) {
345
+ const cacheKey = `node-builtin:${specifier}`;
346
+ if (esmModuleCache.has(cacheKey)) return esmModuleCache.get(cacheKey);
347
+ return createSyntheticModuleFromExports(cacheKey, await importNodeModule(specifier), vm);
348
+ }
349
+ async function loadResolvedModule(specifier, parentUrl, options) {
350
+ if (await isNodeBuiltinSpecifier(specifier)) return loadNodeBuiltinModule(specifier, options.vm);
351
+ 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.`);
352
+ const resolvedUrl = new URL(specifier, parentUrl).href;
353
+ 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.`);
354
+ return loadModule(resolvedUrl, options);
355
+ }
356
+ async function evaluateDynamicModule(module) {
357
+ if (module.status === "linked") await module.evaluate();
358
+ if (module.status === "errored") throw module.error;
359
+ return module;
360
+ }
361
+ async function loadModule(url, options) {
362
+ if (esmModuleCache.has(url)) return esmModuleCache.get(url);
363
+ const { fetch: fetch2, vm } = options;
364
+ if (!isFetchableRemoteModuleUrl(url)) throw new Error(`Unsupported ESM module URL "${url}". Only http(s) remote modules and Node.js built-in modules are supported.`);
365
+ const code = await (await fetch2(url)).text();
366
+ const cwdFileUrl = (await importNodeModule("node:url")).pathToFileURL(process.cwd()).href;
367
+ const sourceTextModule = new vm.SourceTextModule(code, {
368
+ identifier: url,
369
+ initializeImportMeta: (meta) => {
370
+ meta.url = createImportMetaUrl(url, cwdFileUrl);
371
+ },
372
+ importModuleDynamically: async (specifier) => {
373
+ return evaluateDynamicModule(await loadResolvedModule(specifier, url, options));
374
+ }
375
+ });
376
+ esmModuleCache.set(url, sourceTextModule);
377
+ await sourceTextModule.link(async (specifier) => {
378
+ return loadResolvedModule(specifier, url, options);
379
+ });
380
+ return sourceTextModule;
381
+ }
382
+ const dataFetchFunction = async function(options) {
383
+ var _a, _b;
384
+ const [id, data, downgrade] = options;
385
+ logger.debug("==========call data fetch function!");
386
+ if (data) {
387
+ if (!id) {
388
+ throw new Error("id is required!");
389
+ }
390
+ if (!getDataFetchMap()) {
391
+ initDataFetchMap();
392
+ }
393
+ const dataFetchItem = getDataFetchItem(id);
394
+ if (dataFetchItem) {
395
+ (_b = (_a = dataFetchItem[1]) == null ? void 0 : _a[1]) == null ? void 0 : _b.call(_a, data);
396
+ dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
397
+ return;
398
+ }
399
+ if (!dataFetchItem) {
400
+ const dataFetchMap = getDataFetchMap();
401
+ let res;
402
+ let rej;
403
+ const p = new Promise((resolve, reject) => {
404
+ res = resolve;
405
+ rej = reject;
406
+ });
407
+ dataFetchMap[id] = [
408
+ [
409
+ async () => async () => {
410
+ return "";
411
+ },
412
+ MF_DATA_FETCH_TYPE.FETCH_SERVER
413
+ ],
414
+ [p, res, rej],
415
+ MF_DATA_FETCH_STATUS.LOADED
416
+ ];
417
+ res && res(data);
418
+ return;
419
+ }
420
+ }
421
+ if (downgrade) {
422
+ const mfDowngrade2 = getDowngradeTag();
423
+ if (!mfDowngrade2) {
424
+ globalThis[DOWNGRADE_KEY] = id ? [id] : true;
425
+ } else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
426
+ mfDowngrade2.push(id);
427
+ }
428
+ }
429
+ const mfDowngrade = getDowngradeTag();
430
+ if (typeof mfDowngrade === "boolean") {
431
+ return callAllDowngrade();
432
+ }
433
+ if (Array.isArray(mfDowngrade)) {
434
+ if (!id) {
435
+ globalThis[DOWNGRADE_KEY] = true;
436
+ return callAllDowngrade();
437
+ }
438
+ if (!mfDowngrade.includes(id)) {
439
+ mfDowngrade.push(id);
440
+ }
441
+ return callDowngrade(id);
442
+ }
443
+ };
444
+ function injectDataFetch() {
445
+ var _a;
446
+ globalThis[_a = DATA_FETCH_FUNCTION] || (globalThis[_a] = []);
447
+ const dataFetch = globalThis[DATA_FETCH_FUNCTION];
448
+ if (dataFetch.push === dataFetchFunction) {
449
+ return;
450
+ }
451
+ if (typeof window === "undefined") {
452
+ return;
453
+ }
454
+ globalThis[FS_HREF] = window.location.href;
455
+ dataFetch.push = dataFetchFunction;
456
+ }
457
+ const getDocsUrl = (errorCode) => {
458
+ return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split("-")[0].toLowerCase()}#${errorCode.toLowerCase()}`;
459
+ };
460
+ const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
461
+ const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
462
+ args && msg.push(`args: ${JSON.stringify(args)}`);
463
+ msg.push(getDocsUrl(errorCode));
464
+ originalErrorMsg && msg.push(`Original Error Message:
465
+ ${originalErrorMsg}`);
466
+ return msg.join("\n");
467
+ };
468
+ function logAndReport(code, descMap, args, logger2, originalErrorMsg, context) {
469
+ return logger2(getShortErrorMsg(code, descMap, args, originalErrorMsg));
470
+ }
471
+ const LOG_CATEGORY = "[ Federation Runtime ]";
472
+ function assert(condition, msgOrCode, descMap, args, context) {
473
+ if (!condition) error(msgOrCode);
474
+ }
475
+ function error(msgOrCode, descMap, args, originalErrorMsg, context) {
476
+ if (descMap !== void 0) return logAndReport(msgOrCode, descMap, args ?? {}, (msg2) => {
477
+ throw new Error(`${LOG_CATEGORY}: ${msg2}`);
478
+ }, originalErrorMsg);
479
+ const msg = msgOrCode;
480
+ if (msg instanceof Error) {
481
+ if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
482
+ throw msg;
483
+ }
484
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
485
+ }
486
+ const processModuleAlias = (name, subPath) => {
487
+ let moduleName;
488
+ if (name.endsWith("/")) moduleName = name.slice(0, -1);
489
+ else moduleName = name;
490
+ if (subPath.startsWith(".")) subPath = subPath.slice(1);
491
+ moduleName = moduleName + subPath;
492
+ return moduleName;
493
+ };
494
+ const MAX_PRELOADED_ASSETS = 2e3;
495
+ const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
496
+ const nativeGlobal = (() => {
497
+ try {
498
+ return document.defaultView;
499
+ } catch {
500
+ return CurrentGlobal;
501
+ }
502
+ })();
503
+ function definePropertyGlobalVal(target, key, val) {
504
+ Object.defineProperty(target, key, {
505
+ value: val,
506
+ configurable: false,
507
+ writable: true
508
+ });
509
+ }
510
+ function includeOwnProperty(target, key) {
511
+ return Object.hasOwnProperty.call(target, key);
512
+ }
513
+ if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
514
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
515
+ function setGlobalDefaultVal(target) {
516
+ var _a, _b, _c, _d, _e, _f, _g;
517
+ if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
518
+ if (!includeOwnProperty(target, "__FEDERATION__")) {
519
+ definePropertyGlobalVal(target, "__FEDERATION__", {
520
+ __GLOBAL_PLUGIN__: [],
521
+ __INSTANCES__: [],
522
+ moduleInfo: {},
523
+ __SHARE__: {},
524
+ __MANIFEST_LOADING__: {},
525
+ __PRELOADED_MAP__: /* @__PURE__ */ new Map(),
526
+ __PRELOADED_ASSETS__: /* @__PURE__ */ new Set()
527
+ });
528
+ definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
529
+ }
530
+ (_a = target.__FEDERATION__).__GLOBAL_PLUGIN__ ?? (_a.__GLOBAL_PLUGIN__ = []);
531
+ (_b = target.__FEDERATION__).__INSTANCES__ ?? (_b.__INSTANCES__ = []);
532
+ (_c = target.__FEDERATION__).moduleInfo ?? (_c.moduleInfo = {});
533
+ (_d = target.__FEDERATION__).__SHARE__ ?? (_d.__SHARE__ = {});
534
+ (_e = target.__FEDERATION__).__MANIFEST_LOADING__ ?? (_e.__MANIFEST_LOADING__ = {});
535
+ (_f = target.__FEDERATION__).__PRELOADED_MAP__ ?? (_f.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
536
+ (_g = target.__FEDERATION__).__PRELOADED_ASSETS__ ?? (_g.__PRELOADED_ASSETS__ = /* @__PURE__ */ new Set());
537
+ }
538
+ setGlobalDefaultVal(CurrentGlobal);
539
+ setGlobalDefaultVal(nativeGlobal);
540
+ const getRemoteEntryExports = (name, globalName) => {
541
+ const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
542
+ return {
543
+ remoteEntryKey,
544
+ entryExports: CurrentGlobal[remoteEntryKey]
545
+ };
546
+ };
547
+ const getPreloadedAsset = (url) => CurrentGlobal.__FEDERATION__.__PRELOADED_ASSETS__.has(url);
548
+ const setPreloadedAsset = (url) => {
549
+ const preloadedAssets = CurrentGlobal.__FEDERATION__.__PRELOADED_ASSETS__;
550
+ preloadedAssets.add(url);
551
+ if (preloadedAssets.size > MAX_PRELOADED_ASSETS) {
552
+ const oldestUrl = preloadedAssets.values().next().value;
553
+ if (oldestUrl !== void 0) preloadedAssets.delete(oldestUrl);
554
+ }
555
+ };
556
+ const DEFAULT_SCOPE = "default";
557
+ const DEFAULT_REMOTE_TYPE = "global";
558
+ function composeRemoteRequestId(remoteName, expose) {
559
+ if (!expose || expose === ".") return remoteName;
560
+ return `${remoteName}/${expose.replace(/^\.\//, "")}`;
561
+ }
562
+ function matchRemoteWithNameAndExpose(remotes, id) {
563
+ for (const remote of remotes) {
564
+ const isNameMatched = id.startsWith(remote.name);
565
+ let expose = id.replace(remote.name, "");
566
+ if (isNameMatched) {
567
+ if (expose.startsWith("/")) {
568
+ const pkgNameOrAlias = remote.name;
569
+ expose = `.${expose}`;
570
+ return {
571
+ pkgNameOrAlias,
572
+ expose,
573
+ remote
574
+ };
575
+ } else if (expose === "") return {
576
+ pkgNameOrAlias: remote.name,
577
+ expose: ".",
578
+ remote
579
+ };
580
+ }
581
+ const isAliasMatched = remote.alias && id.startsWith(remote.alias);
582
+ let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
583
+ if (remote.alias && isAliasMatched) {
584
+ if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
585
+ const pkgNameOrAlias = remote.alias;
586
+ exposeWithAlias = `.${exposeWithAlias}`;
587
+ return {
588
+ pkgNameOrAlias,
589
+ expose: exposeWithAlias,
590
+ remote
591
+ };
592
+ } else if (exposeWithAlias === "") return {
593
+ pkgNameOrAlias: remote.alias,
594
+ expose: ".",
595
+ remote
596
+ };
597
+ }
598
+ }
599
+ }
600
+ const RUNTIME_001 = "RUNTIME-001";
601
+ const RUNTIME_002 = "RUNTIME-002";
602
+ const RUNTIME_003 = "RUNTIME-003";
603
+ const RUNTIME_004 = "RUNTIME-004";
604
+ const RUNTIME_005 = "RUNTIME-005";
605
+ const RUNTIME_006 = "RUNTIME-006";
606
+ const RUNTIME_007 = "RUNTIME-007";
607
+ const RUNTIME_008 = "RUNTIME-008";
608
+ const RUNTIME_009 = "RUNTIME-009";
609
+ const RUNTIME_010 = "RUNTIME-010";
610
+ const RUNTIME_011 = "RUNTIME-011";
611
+ const RUNTIME_012 = "RUNTIME-012";
612
+ const RUNTIME_013 = "RUNTIME-013";
613
+ const RUNTIME_014 = "RUNTIME-014";
614
+ const RUNTIME_015 = "RUNTIME-015";
615
+ const runtimeDescMap = {
616
+ [RUNTIME_001]: "Failed to get remoteEntry exports.",
617
+ [RUNTIME_002]: 'The remote entry interface does not contain "init"',
618
+ [RUNTIME_003]: "Failed to get manifest.",
619
+ [RUNTIME_004]: "Failed to locate remote.",
620
+ [RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
621
+ [RUNTIME_006]: "Invalid loadShareSync function call from runtime",
622
+ [RUNTIME_007]: "Failed to get remote snapshot.",
623
+ [RUNTIME_008]: "Failed to load script resources.",
624
+ [RUNTIME_009]: "Please call createInstance first.",
625
+ [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.',
626
+ [RUNTIME_011]: "The remoteEntry URL is missing from the remote snapshot.",
627
+ [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.',
628
+ [RUNTIME_013]: "The manifest is not a valid Module Federation manifest.",
629
+ [RUNTIME_014]: "The remote does not expose the requested module.",
630
+ [RUNTIME_015]: "Remote container initialization failed."
631
+ };
632
+ ({
633
+ ...runtimeDescMap
634
+ });
635
+ const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
636
+ const remoteEntryLoadingOrigins = /* @__PURE__ */ new WeakMap();
637
+ const esmRemoteEntryLoadErrorMessages = [
638
+ "Failed to fetch dynamically imported module",
639
+ "Importing a module script failed",
640
+ "error loading dynamically imported module"
641
+ ];
642
+ function isEsmRemoteEntryLoadError(err) {
643
+ if (!(err instanceof TypeError)) return false;
644
+ return esmRemoteEntryLoadErrorMessages.some((loadErrorMessage) => err.message.includes(loadErrorMessage));
645
+ }
646
+ function isEsmRemoteType(type) {
647
+ return type === "esm" || type === "module";
648
+ }
649
+ async function loadEsmEntry({ entry, remoteEntryExports, name, getEntryUrl }) {
650
+ return new Promise((resolve, reject) => {
651
+ const rejectEntry = (loadError) => {
652
+ if (isEsmRemoteEntryLoadError(loadError)) {
653
+ const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
654
+ try {
655
+ error(RUNTIME_008, runtimeDescMap, {
656
+ remoteName: name,
657
+ resourceUrl: url
658
+ }, originalMsg);
659
+ } catch (runtimeError) {
660
+ reject(runtimeError);
661
+ return;
662
+ }
663
+ }
664
+ reject(loadError);
665
+ };
666
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
667
+ try {
668
+ if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${url}")${importCallback}`)([resolve, rejectEntry]);
669
+ else import(
670
+ /* webpackIgnore: true */
671
+ /* @vite-ignore */
672
+ url
673
+ ).then(resolve).catch(rejectEntry);
674
+ else resolve(remoteEntryExports);
675
+ } catch (e) {
676
+ error(`Failed to load ESM entry from "${url}". ${e instanceof Error ? e.message : String(e)}`);
677
+ }
678
+ });
679
+ }
680
+ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
681
+ return new Promise((resolve, reject) => {
682
+ try {
683
+ if (!remoteEntryExports) if (typeof __system_context__ === "undefined") System.import(entry).then(resolve).catch(reject);
684
+ else new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
685
+ else resolve(remoteEntryExports);
686
+ } catch (e) {
687
+ error(`Failed to load SystemJS entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
688
+ }
689
+ });
690
+ }
691
+ function handleRemoteEntryLoaded(name, globalName, entry) {
692
+ const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
693
+ if (!entryExports) error(RUNTIME_001, runtimeDescMap, {
694
+ remoteName: name,
695
+ remoteEntryUrl: entry,
696
+ remoteEntryKey
697
+ });
698
+ return entryExports;
699
+ }
700
+ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook, getEntryUrl, resourceContext }) {
701
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
702
+ if (remoteEntryExports) return remoteEntryExports;
703
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
704
+ return loadScript(url, {
705
+ attrs: {},
706
+ createScriptHook: (url2, attrs) => {
707
+ const res = loaderHook.lifecycle.createScript.emit({
708
+ url: url2,
709
+ attrs,
710
+ remoteInfo,
711
+ resourceContext: resourceContext ? {
712
+ ...resourceContext,
713
+ url: url2
714
+ } : void 0
715
+ });
716
+ if (!res) return;
717
+ if (res instanceof HTMLScriptElement) return res;
718
+ if ("script" in res || "timeout" in res) return res;
719
+ }
720
+ }).then(() => {
721
+ return handleRemoteEntryLoaded(name, globalName, entry);
722
+ }, (loadError) => {
723
+ const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
724
+ error(RUNTIME_008, runtimeDescMap, {
725
+ remoteName: name,
726
+ resourceUrl: url
727
+ }, originalMsg);
728
+ });
729
+ }
730
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, resourceContext }) {
731
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
732
+ if (isEsmRemoteType(type)) return loadEsmEntry({
733
+ entry,
734
+ remoteEntryExports,
735
+ name,
736
+ getEntryUrl
737
+ });
738
+ if (type === "system") return loadSystemJsEntry({
739
+ entry,
740
+ remoteEntryExports
741
+ });
742
+ return loadEntryScript({
743
+ entry,
744
+ globalName,
745
+ name,
746
+ remoteInfo,
747
+ loaderHook,
748
+ getEntryUrl,
749
+ resourceContext
750
+ });
751
+ }
752
+ async function loadEntryNode({ remoteInfo, loaderHook, resourceContext }) {
753
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
754
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
755
+ if (remoteEntryExports) return remoteEntryExports;
756
+ return loadScriptNode(entry, {
757
+ attrs: {
758
+ name,
759
+ globalName,
760
+ type
761
+ },
762
+ loaderHook: { createScriptHook: (url, attrs = {}) => {
763
+ const res = loaderHook.lifecycle.createScript.emit({
764
+ url,
765
+ attrs,
766
+ remoteInfo,
767
+ resourceContext: resourceContext ? {
768
+ ...resourceContext,
769
+ url
770
+ } : void 0
771
+ });
772
+ if (!res) return;
773
+ if ("url" in res) return res;
774
+ } }
775
+ }).then(() => {
776
+ return handleRemoteEntryLoaded(name, globalName, entry);
777
+ }).catch((e) => {
778
+ error(`Failed to load Node.js entry for remote "${name}" from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
779
+ });
780
+ }
781
+ function getRemoteEntryUniqueKey(remoteInfo) {
782
+ const { entry, name } = remoteInfo;
783
+ return composeKeyWithSeparator(name, entry);
784
+ }
785
+ async function getRemoteEntry(params) {
786
+ const { origin, remoteEntryExports, remoteInfo, getEntryUrl, resourceContext, _inErrorHandling = false } = params;
787
+ const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
788
+ if (remoteEntryExports) {
789
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
790
+ origin,
791
+ remoteInfo,
792
+ remoteEntryExports,
793
+ resourceContext,
794
+ cached: true
795
+ });
796
+ return remoteEntryExports;
797
+ }
798
+ if (!globalLoading[uniqueKey]) {
799
+ const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
800
+ const loaderHook = origin.loaderHook;
801
+ const loading = loadEntryHook.emit({
802
+ origin,
803
+ loaderHook,
804
+ remoteInfo,
805
+ remoteEntryExports,
806
+ resourceContext
807
+ }).then((res) => {
808
+ if (res) return res;
809
+ return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : isBrowserEnvValue) ? loadEntryDom({
810
+ remoteInfo,
811
+ remoteEntryExports,
812
+ loaderHook,
813
+ getEntryUrl,
814
+ resourceContext
815
+ }) : loadEntryNode({
816
+ remoteInfo,
817
+ loaderHook,
818
+ resourceContext
819
+ });
820
+ }).then(async (res) => {
821
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
822
+ origin,
823
+ remoteInfo,
824
+ remoteEntryExports: res,
825
+ resourceContext
826
+ });
827
+ return res;
828
+ }).catch(async (loadError) => {
829
+ const isScriptExecutionError = loadError instanceof Error && loadError.message.includes("ScriptExecutionError");
830
+ if (loadError instanceof Error && loadError.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
831
+ const wrappedGetRemoteEntry = (params2) => {
832
+ return getRemoteEntry({
833
+ ...params2,
834
+ _inErrorHandling: true
835
+ });
836
+ };
837
+ const recoveredRemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
838
+ getRemoteEntry: wrappedGetRemoteEntry,
839
+ origin,
840
+ remoteInfo,
841
+ remoteEntryExports,
842
+ globalLoading,
843
+ uniqueKey
844
+ });
845
+ if (recoveredRemoteEntryExports) {
846
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
847
+ origin,
848
+ remoteInfo,
849
+ remoteEntryExports: recoveredRemoteEntryExports,
850
+ resourceContext,
851
+ error: loadError,
852
+ recovered: true
853
+ });
854
+ return recoveredRemoteEntryExports;
855
+ }
856
+ }
857
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
858
+ origin,
859
+ remoteInfo,
860
+ resourceContext,
861
+ error: loadError
862
+ });
863
+ throw loadError;
864
+ });
865
+ globalLoading[uniqueKey] = loading;
866
+ loading.then(void 0, () => {
867
+ if (globalLoading[uniqueKey] === loading) delete globalLoading[uniqueKey];
868
+ });
869
+ remoteEntryLoadingOrigins.set(loading, origin);
870
+ }
871
+ const remoteEntryLoading = globalLoading[uniqueKey];
872
+ if (remoteEntryLoadingOrigins.get(remoteEntryLoading) !== origin) try {
873
+ const result = await remoteEntryLoading;
874
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
875
+ origin,
876
+ remoteInfo,
877
+ remoteEntryExports: result,
878
+ resourceContext
879
+ });
880
+ return result;
881
+ } catch (loadError) {
882
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
883
+ origin,
884
+ remoteInfo,
885
+ resourceContext,
886
+ error: loadError
887
+ });
888
+ throw loadError;
889
+ }
890
+ return remoteEntryLoading;
891
+ }
892
+ function getRemoteInfo(remote) {
893
+ return {
894
+ ...remote,
895
+ entry: "entry" in remote ? remote.entry : "",
896
+ type: remote.type || DEFAULT_REMOTE_TYPE,
897
+ entryGlobalName: remote.entryGlobalName || remote.name,
898
+ shareScope: remote.shareScope || DEFAULT_SCOPE
899
+ };
900
+ }
901
+ function remoteToEntry(r) {
902
+ return {
903
+ name: r.name,
904
+ alias: r.alias,
905
+ entry: "entry" in r ? r.entry : void 0,
906
+ version: "version" in r ? r.version : void 0,
907
+ type: r.type,
908
+ entryGlobalName: r.entryGlobalName,
909
+ shareScope: r.shareScope
910
+ };
911
+ }
912
+ function optionsToMFContext(options) {
913
+ var _a, _b, _c, _d, _e, _f;
914
+ const shared = {};
915
+ for (const [pkgName, versions] of Object.entries(options.shared)) {
916
+ const first = versions[0];
917
+ if (first) shared[pkgName] = {
918
+ version: first.version,
919
+ singleton: (_a = first.shareConfig) == null ? void 0 : _a.singleton,
920
+ requiredVersion: ((_b = first.shareConfig) == null ? void 0 : _b.requiredVersion) === false ? false : (_c = first.shareConfig) == null ? void 0 : _c.requiredVersion,
921
+ eager: first.eager,
922
+ strictVersion: (_d = first.shareConfig) == null ? void 0 : _d.strictVersion
923
+ };
924
+ }
925
+ return {
926
+ project: {
927
+ name: options.name,
928
+ mfRole: ((_e = options.remotes) == null ? void 0 : _e.length) > 0 ? "host" : "unknown"
929
+ },
930
+ mfConfig: {
931
+ name: options.name,
932
+ remotes: ((_f = options.remotes) == null ? void 0 : _f.map(remoteToEntry)) ?? [],
933
+ shared
934
+ }
935
+ };
936
+ }
937
+ function isTimeoutError(error2) {
938
+ if (!(error2 instanceof Error)) return false;
939
+ return error2.message.includes("timed out") || error2.name.includes("Timeout");
940
+ }
941
+ function createAssetResult(context, url, status, error2) {
942
+ return {
943
+ url,
944
+ status,
945
+ resourceType: context.resourceType,
946
+ initiator: context.initiator,
947
+ id: context.id,
948
+ error: error2
949
+ };
950
+ }
951
+ function preloadAssetOnce(context, url, recordPreloadedAssets, preload) {
952
+ if (!recordPreloadedAssets) return preload();
953
+ if (getPreloadedAsset(url)) return Promise.resolve(createAssetResult(context, url, "cached"));
954
+ setPreloadedAsset(url);
955
+ return preload();
956
+ }
957
+ async function waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, context) {
958
+ const cachedRemote = host.moduleCache.get(entryRemoteInfo.name);
959
+ const url = entryRemoteInfo.entry;
960
+ if (cachedRemote == null ? void 0 : cachedRemote.remoteEntryExports) return createAssetResult(context, url, "cached");
961
+ try {
962
+ if (!await getRemoteEntry({
963
+ origin: host,
964
+ remoteInfo: entryRemoteInfo,
965
+ remoteEntryExports: cachedRemote == null ? void 0 : cachedRemote.remoteEntryExports,
966
+ resourceContext: {
967
+ ...context,
968
+ url
969
+ }
970
+ })) throw new Error(`Failed to load remoteEntry "${url}".`);
971
+ return createAssetResult(context, url, "success");
972
+ } catch (error2) {
973
+ return createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2);
974
+ }
975
+ }
976
+ function waitForLinkPreload({ host, remoteInfo, url, attrs, context, needDeleteLink }) {
977
+ return new Promise((resolve) => {
978
+ const { link, needAttach } = createLink({
979
+ url,
980
+ cb: () => {
981
+ resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
982
+ },
983
+ onErrorCallback: (error2) => {
984
+ resolve(createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2));
985
+ },
986
+ attrs,
987
+ createLinkHook: (hookUrl, hookAttrs) => {
988
+ const res = host.loaderHook.lifecycle.createLink.emit({
989
+ url: hookUrl,
990
+ attrs: hookAttrs,
991
+ remoteInfo,
992
+ resourceContext: {
993
+ ...context,
994
+ url: hookUrl
995
+ }
996
+ });
997
+ if (res instanceof HTMLLinkElement) return res;
998
+ return res;
999
+ },
1000
+ needDeleteLink
1001
+ });
1002
+ needAttach && document.head.appendChild(link);
1003
+ });
1004
+ }
1005
+ function waitForScriptPreload({ host, remoteInfo, url, attrs, context }) {
1006
+ return new Promise((resolve) => {
1007
+ const { script, needAttach } = createScript({
1008
+ url,
1009
+ cb: () => {
1010
+ resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
1011
+ },
1012
+ onErrorCallback: (error2) => {
1013
+ resolve(createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2));
1014
+ },
1015
+ attrs,
1016
+ createScriptHook: (hookUrl, hookAttrs) => {
1017
+ const res = host.loaderHook.lifecycle.createScript.emit({
1018
+ url: hookUrl,
1019
+ attrs: hookAttrs,
1020
+ remoteInfo,
1021
+ resourceContext: {
1022
+ ...context,
1023
+ url: hookUrl
1024
+ }
1025
+ });
1026
+ if (res instanceof HTMLScriptElement) return res;
1027
+ return res;
1028
+ },
1029
+ needDeleteScript: true
1030
+ });
1031
+ needAttach && document.head.appendChild(script);
1032
+ });
1033
+ }
1034
+ function createResourceContext(baseContext, resourceType) {
1035
+ return {
1036
+ ...baseContext,
1037
+ resourceType
1038
+ };
1039
+ }
1040
+ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseContext = {
1041
+ initiator: "preloadRemote",
1042
+ id: remoteInfo.name
1043
+ }, recordPreloadedAssets = true) {
1044
+ const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
1045
+ const results = [];
1046
+ if (host.options.inBrowser) {
1047
+ entryAssets.forEach((asset) => {
1048
+ const { moduleInfo: entryRemoteInfo } = asset;
1049
+ results.push(waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, createResourceContext(baseContext, "remoteEntry")));
1050
+ });
1051
+ if (useLinkPreload) {
1052
+ const defaultAttrs2 = {
1053
+ rel: "preload",
1054
+ as: "style"
1055
+ };
1056
+ cssAssets.forEach((cssUrl) => {
1057
+ const context = createResourceContext(baseContext, "css");
1058
+ results.push(preloadAssetOnce(context, cssUrl, recordPreloadedAssets, () => waitForLinkPreload({
1059
+ host,
1060
+ remoteInfo,
1061
+ url: cssUrl,
1062
+ attrs: defaultAttrs2,
1063
+ context
1064
+ })));
1065
+ });
1066
+ } else {
1067
+ const defaultAttrs2 = {
1068
+ rel: "stylesheet",
1069
+ type: "text/css"
1070
+ };
1071
+ cssAssets.forEach((cssUrl) => {
1072
+ const context = createResourceContext(baseContext, "css");
1073
+ results.push(preloadAssetOnce(context, cssUrl, recordPreloadedAssets, () => waitForLinkPreload({
1074
+ host,
1075
+ remoteInfo,
1076
+ url: cssUrl,
1077
+ attrs: defaultAttrs2,
1078
+ needDeleteLink: false,
1079
+ context
1080
+ })));
1081
+ });
1082
+ }
1083
+ let preloadJsAsset = waitForScriptPreload;
1084
+ let defaultAttrs = {
1085
+ fetchpriority: "high",
1086
+ type: "text/javascript"
1087
+ };
1088
+ if (useLinkPreload) {
1089
+ preloadJsAsset = waitForLinkPreload;
1090
+ defaultAttrs = {
1091
+ rel: "preload",
1092
+ as: "script"
1093
+ };
1094
+ } else if (isEsmRemoteType(remoteInfo.type)) {
1095
+ preloadJsAsset = waitForLinkPreload;
1096
+ defaultAttrs = {
1097
+ rel: "modulepreload",
1098
+ fetchpriority: "high"
1099
+ };
1100
+ }
1101
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
1102
+ const context = createResourceContext(baseContext, "js");
1103
+ results.push(preloadAssetOnce(context, jsUrl, recordPreloadedAssets, () => preloadJsAsset({
1104
+ host,
1105
+ remoteInfo,
1106
+ url: jsUrl,
1107
+ attrs: defaultAttrs,
1108
+ context
1109
+ })));
1110
+ });
1111
+ }
1112
+ return Promise.all(results);
1113
+ }
1114
+ var helpers_default = {
1115
+ utils: {
1116
+ matchRemoteWithNameAndExpose,
1117
+ preloadAssets,
1118
+ getRemoteInfo
1119
+ }
1120
+ };
1121
+ function getAvailableExposeNames(remoteSnapshot) {
1122
+ if (!remoteSnapshot || !("modules" in remoteSnapshot) || !Array.isArray(remoteSnapshot.modules)) return;
1123
+ const exposes = remoteSnapshot.modules.map((module) => module.moduleName).filter(Boolean);
1124
+ return exposes.length ? exposes.join(",") : void 0;
1125
+ }
1126
+ function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
1127
+ const localShareScopeMap = hostShareScopeMap;
1128
+ const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
1129
+ if (!shareScopeKeys.length) shareScopeKeys.push("default");
1130
+ shareScopeKeys.forEach((shareScopeKey) => {
1131
+ if (!localShareScopeMap[shareScopeKey]) localShareScopeMap[shareScopeKey] = {};
1132
+ });
1133
+ const remoteEntryInitOptions = {
1134
+ version: remoteInfo.version || "",
1135
+ shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || "default"
1136
+ };
1137
+ Object.defineProperty(remoteEntryInitOptions, "shareScopeMap", {
1138
+ value: localShareScopeMap,
1139
+ enumerable: false
1140
+ });
1141
+ return {
1142
+ remoteEntryInitOptions,
1143
+ shareScope: localShareScopeMap[shareScopeKeys[0]],
1144
+ initScope: rawInitScope ?? []
1145
+ };
1146
+ }
1147
+ var Module$1 = class {
1148
+ constructor({ remoteInfo, host }) {
1149
+ this.inited = false;
1150
+ this.initing = false;
1151
+ this.lib = void 0;
1152
+ this.remoteInfo = remoteInfo;
1153
+ this.host = host;
1154
+ }
1155
+ async getEntry(expose, resourceContext) {
1156
+ const effectiveResourceContext = resourceContext || {
1157
+ initiator: "loadRemote",
1158
+ id: composeRemoteRequestId(this.remoteInfo.name, expose),
1159
+ resourceType: "remoteEntry",
1160
+ url: this.remoteInfo.entry,
1161
+ expose
1162
+ };
1163
+ const remoteEntryExports = await getRemoteEntry({
1164
+ origin: this.host,
1165
+ remoteInfo: this.remoteInfo,
1166
+ remoteEntryExports: this.remoteEntryExports,
1167
+ resourceContext: effectiveResourceContext
1168
+ });
1169
+ assert(remoteEntryExports, `remoteEntryExports is undefined
1170
+ ${safeToString(this.remoteInfo)}`);
1171
+ this.remoteEntryExports = remoteEntryExports;
1172
+ return this.remoteEntryExports;
1173
+ }
1174
+ async init(id, remoteSnapshot, rawInitScope, expose, resourceContext) {
1175
+ const remoteEntryExports = await this.getEntry(expose, resourceContext);
1176
+ if (this.inited) {
1177
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1178
+ id,
1179
+ remoteInfo: this.remoteInfo,
1180
+ remoteSnapshot,
1181
+ remoteEntryExports,
1182
+ cached: true,
1183
+ origin: this.host
1184
+ });
1185
+ return remoteEntryExports;
1186
+ }
1187
+ if (this.initPromise) {
1188
+ try {
1189
+ await this.initPromise;
1190
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1191
+ id,
1192
+ remoteInfo: this.remoteInfo,
1193
+ remoteSnapshot,
1194
+ remoteEntryExports,
1195
+ cached: true,
1196
+ origin: this.host
1197
+ });
1198
+ } catch (initError) {
1199
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1200
+ id,
1201
+ remoteInfo: this.remoteInfo,
1202
+ remoteSnapshot,
1203
+ remoteEntryExports,
1204
+ error: initError,
1205
+ cached: true,
1206
+ origin: this.host
1207
+ });
1208
+ throw initError;
1209
+ }
1210
+ return remoteEntryExports;
1211
+ }
1212
+ this.initing = true;
1213
+ this.initPromise = (async () => {
1214
+ await this.host.loaderHook.lifecycle.beforeInitRemote.emit({
1215
+ id,
1216
+ remoteInfo: this.remoteInfo,
1217
+ remoteSnapshot,
1218
+ origin: this.host
1219
+ });
1220
+ const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
1221
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
1222
+ shareScope,
1223
+ remoteEntryInitOptions,
1224
+ initScope,
1225
+ remoteInfo: this.remoteInfo,
1226
+ origin: this.host
1227
+ });
1228
+ if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === "undefined") error(RUNTIME_002, runtimeDescMap, {
1229
+ hostName: this.host.name,
1230
+ remoteName: this.remoteInfo.name,
1231
+ remoteEntryUrl: this.remoteInfo.entry,
1232
+ remoteEntryKey: this.remoteInfo.entryGlobalName
1233
+ }, void 0, optionsToMFContext(this.host.options));
1234
+ try {
1235
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
1236
+ } catch (initError) {
1237
+ error(RUNTIME_015, runtimeDescMap, {
1238
+ hostName: this.host.name,
1239
+ remoteName: this.remoteInfo.name,
1240
+ remoteEntryUrl: this.remoteInfo.entry,
1241
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
1242
+ shareScope: this.remoteInfo.shareScope
1243
+ }, `${initError}`, optionsToMFContext(this.host.options));
1244
+ }
1245
+ await this.host.hooks.lifecycle.initContainer.emit({
1246
+ ...initContainerOptions,
1247
+ id,
1248
+ remoteSnapshot,
1249
+ remoteEntryExports
1250
+ });
1251
+ this.inited = true;
1252
+ })();
1253
+ try {
1254
+ await this.initPromise;
1255
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1256
+ id,
1257
+ remoteInfo: this.remoteInfo,
1258
+ remoteSnapshot,
1259
+ remoteEntryExports,
1260
+ origin: this.host
1261
+ });
1262
+ } catch (initError) {
1263
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1264
+ id,
1265
+ remoteInfo: this.remoteInfo,
1266
+ remoteSnapshot,
1267
+ remoteEntryExports,
1268
+ error: initError,
1269
+ origin: this.host
1270
+ });
1271
+ throw initError;
1272
+ } finally {
1273
+ this.initing = false;
1274
+ this.initPromise = void 0;
1275
+ }
1276
+ return remoteEntryExports;
1277
+ }
1278
+ async get(id, expose, options, remoteSnapshot) {
1279
+ const { loadFactory = true } = options || { loadFactory: true };
1280
+ const remoteEntryExports = await this.init(id, remoteSnapshot, void 0, expose);
1281
+ this.lib = remoteEntryExports;
1282
+ await this.host.loaderHook.lifecycle.beforeGetExpose.emit({
1283
+ id,
1284
+ expose,
1285
+ moduleInfo: this.remoteInfo,
1286
+ remoteEntryExports,
1287
+ origin: this.host
1288
+ });
1289
+ let moduleFactory;
1290
+ try {
1291
+ const hookModuleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
1292
+ remoteEntryExports,
1293
+ expose,
1294
+ moduleInfo: this.remoteInfo
1295
+ });
1296
+ moduleFactory = typeof hookModuleFactory === "function" ? hookModuleFactory : void 0;
1297
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
1298
+ if (!moduleFactory) error(RUNTIME_014, runtimeDescMap, {
1299
+ hostName: this.host.name,
1300
+ remoteName: this.remoteInfo.name,
1301
+ remoteEntryUrl: this.remoteInfo.entry,
1302
+ expose,
1303
+ requestId: id,
1304
+ availableExposes: getAvailableExposeNames(remoteSnapshot)
1305
+ }, void 0, optionsToMFContext(this.host.options));
1306
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
1307
+ id,
1308
+ expose,
1309
+ moduleInfo: this.remoteInfo,
1310
+ remoteEntryExports,
1311
+ moduleFactory,
1312
+ origin: this.host
1313
+ });
1314
+ } catch (getExposeError) {
1315
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
1316
+ id,
1317
+ expose,
1318
+ moduleInfo: this.remoteInfo,
1319
+ remoteEntryExports,
1320
+ error: getExposeError,
1321
+ origin: this.host
1322
+ });
1323
+ throw getExposeError;
1324
+ }
1325
+ const symbolName = processModuleAlias(this.remoteInfo.name, expose);
1326
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
1327
+ if (!loadFactory) return wrapModuleFactory;
1328
+ await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({
1329
+ id,
1330
+ expose,
1331
+ moduleInfo: this.remoteInfo,
1332
+ loadFactory,
1333
+ origin: this.host
1334
+ });
1335
+ try {
1336
+ const exposeContent = await wrapModuleFactory();
1337
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
1338
+ id,
1339
+ expose,
1340
+ moduleInfo: this.remoteInfo,
1341
+ loadFactory,
1342
+ exposeModule: exposeContent,
1343
+ origin: this.host
1344
+ });
1345
+ return exposeContent;
1346
+ } catch (executeFactoryError) {
1347
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
1348
+ id,
1349
+ expose,
1350
+ moduleInfo: this.remoteInfo,
1351
+ loadFactory,
1352
+ error: executeFactoryError,
1353
+ origin: this.host
1354
+ });
1355
+ throw executeFactoryError;
1356
+ }
1357
+ }
1358
+ wraperFactory(moduleFactory, id) {
1359
+ function defineModuleId(res, id2) {
1360
+ if (res && typeof res === "object" && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for("mf_module_id"))) Object.defineProperty(res, Symbol.for("mf_module_id"), {
1361
+ value: id2,
1362
+ enumerable: false
1363
+ });
1364
+ }
1365
+ return () => {
1366
+ const res = moduleFactory();
1367
+ if (res instanceof Promise) return res.then((asyncRes) => {
1368
+ defineModuleId(asyncRes, id);
1369
+ return asyncRes;
1370
+ });
1371
+ defineModuleId(res, id);
1372
+ return res;
1373
+ };
1374
+ }
1375
+ };
1376
+ const REMOTE_DISABLED_MESSAGE = "Remote loading is disabled by experiments.optimization.disableRemote.";
1377
+ var UnavailableRemoteModule = class {
1378
+ constructor() {
1379
+ throw new Error(REMOTE_DISABLED_MESSAGE);
1380
+ }
1381
+ };
1382
+ typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
1383
+ typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" ? !FEDERATION_OPTIMIZE_NO_REMOTE : true;
1384
+ typeof FEDERATION_OPTIMIZE_NO_SHARED === "boolean" ? !FEDERATION_OPTIMIZE_NO_SHARED : true;
1385
+ const helpers = helpers_default;
1386
+ typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" && FEDERATION_OPTIMIZE_NO_REMOTE ? UnavailableRemoteModule : Module$1;
1387
+ const utils = helpers.utils;
1388
+ const runtimeHelpers = {
1389
+ utils
1390
+ };
1391
+ async function prefetch(options) {
1392
+ const { instance, id, dataFetchParams, preloadComponentResource } = options;
1393
+ if (!id) {
1394
+ logger.error("id is required for prefetch!");
1395
+ return;
1396
+ }
1397
+ if (!instance) {
1398
+ logger.error("instance is required for prefetch!");
1399
+ return;
1400
+ }
1401
+ const matchedRemoteInfo = runtimeHelpers.utils.matchRemoteWithNameAndExpose(
1402
+ instance.options.remotes,
1403
+ id
1404
+ );
1405
+ if (!matchedRemoteInfo) {
1406
+ logger.error(`Can not found '${id}' in instance.options.remotes!`);
1407
+ return;
1408
+ }
1409
+ const { remote, expose } = matchedRemoteInfo;
1410
+ const { remoteSnapshot, globalSnapshot } = await instance.snapshotHandler.loadRemoteSnapshotInfo({
1411
+ moduleInfo: remote,
1412
+ id
1413
+ });
1414
+ if (preloadComponentResource) {
1415
+ const remoteInfo = runtimeHelpers.utils.getRemoteInfo(remote);
1416
+ Promise.resolve(
1417
+ instance.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
1418
+ origin: instance,
1419
+ preloadOptions: {
1420
+ remote,
1421
+ preloadConfig: {
1422
+ nameOrAlias: remote.name,
1423
+ exposes: [expose]
1424
+ }
1425
+ },
1426
+ remote,
1427
+ remoteInfo,
1428
+ globalSnapshot,
1429
+ remoteSnapshot
1430
+ })
1431
+ ).then((assets) => {
1432
+ if (assets) {
1433
+ runtimeHelpers.utils.preloadAssets(remoteInfo, instance, assets);
1434
+ }
1435
+ });
1436
+ }
1437
+ const dataFetchMap = getDataFetchMap();
1438
+ if (!dataFetchMap) {
1439
+ return;
1440
+ }
1441
+ const dataFetchInfo = getDataFetchInfo({
1442
+ name: remote.name,
1443
+ alias: remote.alias,
1444
+ id,
1445
+ remoteSnapshot
1446
+ });
1447
+ const dataFetchMapKey = getDataFetchMapKey(dataFetchInfo, {
1448
+ name: instance.name,
1449
+ version: instance.options.version
1450
+ });
1451
+ if (!dataFetchMapKey) {
1452
+ return;
1453
+ }
1454
+ const dataFetchItem = dataFetchMap[dataFetchMapKey];
1455
+ if (!dataFetchItem) {
1456
+ return;
1457
+ }
1458
+ const [getDataFetchGetter, _type, getDataFetchPromise] = dataFetchItem[0];
1459
+ let _getDataFetchPromise = getDataFetchPromise;
1460
+ if (!getDataFetchPromise) {
1461
+ if (!getDataFetchGetter) {
1462
+ return;
1463
+ }
1464
+ _getDataFetchPromise = getDataFetchGetter();
1465
+ }
1466
+ _getDataFetchPromise.then((dataFetchFn) => {
1467
+ return dataFetchFn({
1468
+ ...dataFetchParams,
1469
+ _id: dataFetchMapKey,
1470
+ isDowngrade: false
1471
+ });
1472
+ });
1473
+ }
1474
+ export {
1475
+ dataFetchFunction as d,
1476
+ injectDataFetch as i,
1477
+ prefetch as p
1478
+ };