@module-federation/bridge-react 0.0.0-feat-support-bridge-react-router-v7-20251015102312

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 (100) hide show
  1. package/CHANGELOG.md +670 -0
  2. package/LICENSE +21 -0
  3. package/README.md +131 -0
  4. package/__tests__/bridge.spec.tsx +160 -0
  5. package/__tests__/createLazyComponent.spec.tsx +209 -0
  6. package/__tests__/prefetch.spec.ts +156 -0
  7. package/__tests__/router.spec.tsx +82 -0
  8. package/__tests__/setupTests.ts +8 -0
  9. package/__tests__/util.ts +36 -0
  10. package/dist/bridge-base-29j7dZKh.mjs +201 -0
  11. package/dist/bridge-base-CTNdBioh.js +216 -0
  12. package/dist/data-fetch-server-middleware.cjs.js +163 -0
  13. package/dist/data-fetch-server-middleware.d.ts +15 -0
  14. package/dist/data-fetch-server-middleware.es.js +164 -0
  15. package/dist/data-fetch-utils.cjs.js +24 -0
  16. package/dist/data-fetch-utils.d.ts +81 -0
  17. package/dist/data-fetch-utils.es.js +26 -0
  18. package/dist/index-Dm-M9ouh.mjs +46 -0
  19. package/dist/index-DqCpgmgH.js +45 -0
  20. package/dist/index.cjs.js +293 -0
  21. package/dist/index.d.ts +274 -0
  22. package/dist/index.es.js +276 -0
  23. package/dist/index.esm-CzoIcLts.js +459 -0
  24. package/dist/index.esm-JLwyxgUK.mjs +460 -0
  25. package/dist/lazy-load-component-plugin-B4fdMQTL.js +521 -0
  26. package/dist/lazy-load-component-plugin-ijw36GA0.mjs +522 -0
  27. package/dist/lazy-load-component-plugin.cjs.js +6 -0
  28. package/dist/lazy-load-component-plugin.d.ts +16 -0
  29. package/dist/lazy-load-component-plugin.es.js +6 -0
  30. package/dist/lazy-utils.cjs.js +24 -0
  31. package/dist/lazy-utils.d.ts +149 -0
  32. package/dist/lazy-utils.es.js +24 -0
  33. package/dist/plugin.cjs.js +14 -0
  34. package/dist/plugin.d.ts +22 -0
  35. package/dist/plugin.es.js +14 -0
  36. package/dist/prefetch-Bgm31z9s.js +1272 -0
  37. package/dist/prefetch-DjeoxOeZ.mjs +1273 -0
  38. package/dist/router-v5.cjs.js +55 -0
  39. package/dist/router-v5.d.ts +18 -0
  40. package/dist/router-v5.es.js +32 -0
  41. package/dist/router-v6.cjs.js +84 -0
  42. package/dist/router-v6.d.ts +20 -0
  43. package/dist/router-v6.es.js +61 -0
  44. package/dist/router-v7.cjs.js +83 -0
  45. package/dist/router-v7.d.ts +20 -0
  46. package/dist/router-v7.es.js +61 -0
  47. package/dist/router.cjs.js +82 -0
  48. package/dist/router.d.ts +20 -0
  49. package/dist/router.es.js +60 -0
  50. package/dist/utils-0HFFqmd4.js +2015 -0
  51. package/dist/utils-BTpxHmva.mjs +2016 -0
  52. package/dist/v18.cjs.js +15 -0
  53. package/dist/v18.d.ts +114 -0
  54. package/dist/v18.es.js +15 -0
  55. package/dist/v19.cjs.js +15 -0
  56. package/dist/v19.d.ts +115 -0
  57. package/dist/v19.es.js +15 -0
  58. package/jest.config.ts +21 -0
  59. package/package.json +144 -0
  60. package/project.json +23 -0
  61. package/src/index.ts +45 -0
  62. package/src/lazy/AwaitDataFetch.tsx +215 -0
  63. package/src/lazy/constant.ts +30 -0
  64. package/src/lazy/createLazyComponent.tsx +411 -0
  65. package/src/lazy/data-fetch/cache.ts +291 -0
  66. package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
  67. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
  68. package/src/lazy/data-fetch/index.ts +16 -0
  69. package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
  70. package/src/lazy/data-fetch/prefetch.ts +112 -0
  71. package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
  72. package/src/lazy/index.ts +35 -0
  73. package/src/lazy/logger.ts +6 -0
  74. package/src/lazy/types.ts +75 -0
  75. package/src/lazy/utils.ts +372 -0
  76. package/src/lazy/wrapNoSSR.tsx +10 -0
  77. package/src/modern-app-env.d.ts +2 -0
  78. package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
  79. package/src/plugins/lazy-load-component-plugin.ts +57 -0
  80. package/src/provider/context.tsx +4 -0
  81. package/src/provider/plugin.ts +22 -0
  82. package/src/provider/versions/bridge-base.tsx +127 -0
  83. package/src/provider/versions/legacy.ts +87 -0
  84. package/src/provider/versions/v18.ts +47 -0
  85. package/src/provider/versions/v19.ts +48 -0
  86. package/src/remote/component.tsx +211 -0
  87. package/src/remote/create.tsx +103 -0
  88. package/src/router/default.tsx +73 -0
  89. package/src/router/v5.tsx +43 -0
  90. package/src/router/v6.tsx +74 -0
  91. package/src/router/v7.tsx +75 -0
  92. package/src/types.ts +147 -0
  93. package/src/utils/index.ts +44 -0
  94. package/src/v18.ts +9 -0
  95. package/src/v19.ts +9 -0
  96. package/tsconfig.json +42 -0
  97. package/tsconfig.node.json +11 -0
  98. package/tsconfig.spec.json +26 -0
  99. package/vite.config.ts +106 -0
  100. package/vitest.config.ts +27 -0
@@ -0,0 +1,1273 @@
1
+ import { x as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger$1, g as getDataFetchMap, i as initDataFetchMap, n as getDataFetchItem, M as MF_DATA_FETCH_STATUS, p as MF_DATA_FETCH_TYPE, A as DOWNGRADE_KEY, B as getDowngradeTag, G as callAllDowngrade, H as callDowngrade, k as getDataFetchInfo, m as getDataFetchMapKey } from "./utils-BTpxHmva.mjs";
2
+ import { i as isDebugMode, a as createLink, b as createScript, d as isBrowserEnv, c as createLogger, e as composeKeyWithSeparator, l as loadScriptNode, f as loadScript } from "./index.esm-JLwyxgUK.mjs";
3
+ const dataFetchFunction = async function(options) {
4
+ var _a, _b;
5
+ const [id, data, downgrade] = options;
6
+ logger$1.debug("==========call data fetch function!");
7
+ if (data) {
8
+ if (!id) {
9
+ throw new Error("id is required!");
10
+ }
11
+ if (!getDataFetchMap()) {
12
+ initDataFetchMap();
13
+ }
14
+ const dataFetchItem = getDataFetchItem(id);
15
+ if (dataFetchItem) {
16
+ (_b = (_a = dataFetchItem[1]) == null ? void 0 : _a[1]) == null ? void 0 : _b.call(_a, data);
17
+ dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
18
+ return;
19
+ }
20
+ if (!dataFetchItem) {
21
+ const dataFetchMap = getDataFetchMap();
22
+ let res;
23
+ let rej;
24
+ const p = new Promise((resolve, reject) => {
25
+ res = resolve;
26
+ rej = reject;
27
+ });
28
+ dataFetchMap[id] = [
29
+ [
30
+ async () => async () => {
31
+ return "";
32
+ },
33
+ MF_DATA_FETCH_TYPE.FETCH_SERVER
34
+ ],
35
+ [p, res, rej],
36
+ MF_DATA_FETCH_STATUS.LOADED
37
+ ];
38
+ res && res(data);
39
+ return;
40
+ }
41
+ }
42
+ if (downgrade) {
43
+ const mfDowngrade2 = getDowngradeTag();
44
+ if (!mfDowngrade2) {
45
+ globalThis[DOWNGRADE_KEY] = id ? [id] : true;
46
+ } else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
47
+ mfDowngrade2.push(id);
48
+ }
49
+ }
50
+ const mfDowngrade = getDowngradeTag();
51
+ if (typeof mfDowngrade === "boolean") {
52
+ return callAllDowngrade();
53
+ }
54
+ if (Array.isArray(mfDowngrade)) {
55
+ if (!id) {
56
+ globalThis[DOWNGRADE_KEY] = true;
57
+ return callAllDowngrade();
58
+ }
59
+ if (!mfDowngrade.includes(id)) {
60
+ mfDowngrade.push(id);
61
+ }
62
+ return callDowngrade(id);
63
+ }
64
+ };
65
+ function injectDataFetch() {
66
+ var _a;
67
+ globalThis[_a = DATA_FETCH_FUNCTION] || (globalThis[_a] = []);
68
+ const dataFetch = globalThis[DATA_FETCH_FUNCTION];
69
+ if (dataFetch.push === dataFetchFunction) {
70
+ return;
71
+ }
72
+ if (typeof window === "undefined") {
73
+ return;
74
+ }
75
+ globalThis[FS_HREF] = window.location.href;
76
+ dataFetch.push = dataFetchFunction;
77
+ }
78
+ const RUNTIME_001 = "RUNTIME-001";
79
+ const RUNTIME_002 = "RUNTIME-002";
80
+ const RUNTIME_003 = "RUNTIME-003";
81
+ const RUNTIME_004 = "RUNTIME-004";
82
+ const RUNTIME_005 = "RUNTIME-005";
83
+ const RUNTIME_006 = "RUNTIME-006";
84
+ const RUNTIME_007 = "RUNTIME-007";
85
+ const RUNTIME_008 = "RUNTIME-008";
86
+ const RUNTIME_009 = "RUNTIME-009";
87
+ const getDocsUrl = (errorCode) => {
88
+ const type = errorCode.split("-")[0].toLowerCase();
89
+ return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${type}/${errorCode}`;
90
+ };
91
+ const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
92
+ const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
93
+ args && msg.push(`args: ${JSON.stringify(args)}`);
94
+ msg.push(getDocsUrl(errorCode));
95
+ return msg.join("\n");
96
+ };
97
+ const runtimeDescMap = {
98
+ [RUNTIME_001]: "Failed to get remoteEntry exports.",
99
+ [RUNTIME_002]: 'The remote entry interface does not contain "init"',
100
+ [RUNTIME_003]: "Failed to get manifest.",
101
+ [RUNTIME_004]: "Failed to locate remote.",
102
+ [RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
103
+ [RUNTIME_006]: "Invalid loadShareSync function call from runtime",
104
+ [RUNTIME_007]: "Failed to get remote snapshot.",
105
+ [RUNTIME_008]: "Failed to load script resources.",
106
+ [RUNTIME_009]: "Please call createInstance first."
107
+ };
108
+ ({
109
+ ...runtimeDescMap
110
+ });
111
+ const LOG_CATEGORY = "[ Federation Runtime ]";
112
+ const logger = createLogger(LOG_CATEGORY);
113
+ function assert(condition, msg) {
114
+ if (!condition) {
115
+ error(msg);
116
+ }
117
+ }
118
+ function error(msg) {
119
+ if (msg instanceof Error) {
120
+ if (!msg.message.startsWith(LOG_CATEGORY)) {
121
+ msg.message = `${LOG_CATEGORY}: ${msg.message}`;
122
+ }
123
+ throw msg;
124
+ }
125
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
126
+ }
127
+ function warn(msg) {
128
+ if (msg instanceof Error) {
129
+ if (!msg.message.startsWith(LOG_CATEGORY)) {
130
+ msg.message = `${LOG_CATEGORY}: ${msg.message}`;
131
+ }
132
+ logger.warn(msg);
133
+ } else {
134
+ logger.warn(msg);
135
+ }
136
+ }
137
+ function getFMId(remoteInfo) {
138
+ if ("version" in remoteInfo && remoteInfo.version) {
139
+ return `${remoteInfo.name}:${remoteInfo.version}`;
140
+ } else if ("entry" in remoteInfo && remoteInfo.entry) {
141
+ return `${remoteInfo.name}:${remoteInfo.entry}`;
142
+ } else {
143
+ return `${remoteInfo.name}`;
144
+ }
145
+ }
146
+ const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
147
+ const nativeGlobal = (() => {
148
+ try {
149
+ return document.defaultView;
150
+ } catch {
151
+ return CurrentGlobal;
152
+ }
153
+ })();
154
+ const Global = nativeGlobal;
155
+ function definePropertyGlobalVal(target, key, val) {
156
+ Object.defineProperty(target, key, {
157
+ value: val,
158
+ configurable: false,
159
+ writable: true
160
+ });
161
+ }
162
+ function includeOwnProperty(target, key) {
163
+ return Object.hasOwnProperty.call(target, key);
164
+ }
165
+ if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) {
166
+ definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
167
+ }
168
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
169
+ function setGlobalDefaultVal(target) {
170
+ var _a, _b, _c, _d, _e, _f;
171
+ if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) {
172
+ definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
173
+ }
174
+ if (!includeOwnProperty(target, "__FEDERATION__")) {
175
+ definePropertyGlobalVal(target, "__FEDERATION__", {
176
+ __GLOBAL_PLUGIN__: [],
177
+ __INSTANCES__: [],
178
+ moduleInfo: {},
179
+ __SHARE__: {},
180
+ __MANIFEST_LOADING__: {},
181
+ __PRELOADED_MAP__: /* @__PURE__ */ new Map()
182
+ });
183
+ definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
184
+ }
185
+ (_a = target.__FEDERATION__).__GLOBAL_PLUGIN__ ?? (_a.__GLOBAL_PLUGIN__ = []);
186
+ (_b = target.__FEDERATION__).__INSTANCES__ ?? (_b.__INSTANCES__ = []);
187
+ (_c = target.__FEDERATION__).moduleInfo ?? (_c.moduleInfo = {});
188
+ (_d = target.__FEDERATION__).__SHARE__ ?? (_d.__SHARE__ = {});
189
+ (_e = target.__FEDERATION__).__MANIFEST_LOADING__ ?? (_e.__MANIFEST_LOADING__ = {});
190
+ (_f = target.__FEDERATION__).__PRELOADED_MAP__ ?? (_f.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
191
+ }
192
+ setGlobalDefaultVal(CurrentGlobal);
193
+ setGlobalDefaultVal(nativeGlobal);
194
+ function resetFederationGlobalInfo() {
195
+ CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
196
+ CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];
197
+ CurrentGlobal.__FEDERATION__.moduleInfo = {};
198
+ CurrentGlobal.__FEDERATION__.__SHARE__ = {};
199
+ CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
200
+ Object.keys(globalLoading).forEach((key) => {
201
+ delete globalLoading[key];
202
+ });
203
+ }
204
+ function setGlobalFederationInstance(FederationInstance) {
205
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);
206
+ }
207
+ function getGlobalFederationConstructor() {
208
+ return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
209
+ }
210
+ function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
211
+ if (isDebug) {
212
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
213
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-feat-support-bridge-react-router-v7-20251015102312";
214
+ }
215
+ }
216
+ function getInfoWithoutType(target, key) {
217
+ if (typeof key === "string") {
218
+ const keyRes = target[key];
219
+ if (keyRes) {
220
+ return {
221
+ value: target[key],
222
+ key
223
+ };
224
+ } else {
225
+ const targetKeys = Object.keys(target);
226
+ for (const targetKey of targetKeys) {
227
+ const [targetTypeOrName, _] = targetKey.split(":");
228
+ const nKey = `${targetTypeOrName}:${key}`;
229
+ const typeWithKeyRes = target[nKey];
230
+ if (typeWithKeyRes) {
231
+ return {
232
+ value: typeWithKeyRes,
233
+ key: nKey
234
+ };
235
+ }
236
+ }
237
+ return {
238
+ value: void 0,
239
+ key
240
+ };
241
+ }
242
+ } else {
243
+ throw new Error("key must be string");
244
+ }
245
+ }
246
+ const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo;
247
+ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot) => {
248
+ const moduleKey = getFMId(moduleInfo);
249
+ const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
250
+ if (getModuleInfo && !getModuleInfo.version && "version" in moduleInfo && moduleInfo["version"]) {
251
+ getModuleInfo.version = moduleInfo["version"];
252
+ }
253
+ if (getModuleInfo) {
254
+ return getModuleInfo;
255
+ }
256
+ if ("version" in moduleInfo && moduleInfo["version"]) {
257
+ const { version, ...resModuleInfo } = moduleInfo;
258
+ const moduleKeyWithoutVersion = getFMId(resModuleInfo);
259
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
260
+ if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
261
+ return getModuleInfoWithoutVersion;
262
+ }
263
+ }
264
+ return;
265
+ };
266
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo) => getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
267
+ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo) => {
268
+ const moduleKey = getFMId(remoteInfo);
269
+ nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
270
+ return nativeGlobal.__FEDERATION__.moduleInfo;
271
+ };
272
+ const addGlobalSnapshot = (moduleInfos) => {
273
+ nativeGlobal.__FEDERATION__.moduleInfo = {
274
+ ...nativeGlobal.__FEDERATION__.moduleInfo,
275
+ ...moduleInfos
276
+ };
277
+ return () => {
278
+ const keys = Object.keys(moduleInfos);
279
+ for (const key of keys) {
280
+ delete nativeGlobal.__FEDERATION__.moduleInfo[key];
281
+ }
282
+ };
283
+ };
284
+ const getRemoteEntryExports = (name, globalName) => {
285
+ const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
286
+ const entryExports = CurrentGlobal[remoteEntryKey];
287
+ return {
288
+ remoteEntryKey,
289
+ entryExports
290
+ };
291
+ };
292
+ const registerGlobalPlugins = (plugins) => {
293
+ const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
294
+ plugins.forEach((plugin) => {
295
+ if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) {
296
+ __GLOBAL_PLUGIN__.push(plugin);
297
+ } else {
298
+ warn(`The plugin ${plugin.name} has been registered.`);
299
+ }
300
+ });
301
+ };
302
+ const getGlobalHostPlugins = () => nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
303
+ const getPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
304
+ const setPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
305
+ const DEFAULT_SCOPE = "default";
306
+ const DEFAULT_REMOTE_TYPE = "global";
307
+ const buildIdentifier = "[0-9A-Za-z-]+";
308
+ const build = `(?:\\+(${buildIdentifier}(?:\\.${buildIdentifier})*))`;
309
+ const numericIdentifier = "0|[1-9]\\d*";
310
+ const numericIdentifierLoose = "[0-9]+";
311
+ const nonNumericIdentifier = "\\d*[a-zA-Z-][a-zA-Z0-9-]*";
312
+ const preReleaseIdentifierLoose = `(?:${numericIdentifierLoose}|${nonNumericIdentifier})`;
313
+ const preReleaseLoose = `(?:-?(${preReleaseIdentifierLoose}(?:\\.${preReleaseIdentifierLoose})*))`;
314
+ const preReleaseIdentifier = `(?:${numericIdentifier}|${nonNumericIdentifier})`;
315
+ const preRelease = `(?:-(${preReleaseIdentifier}(?:\\.${preReleaseIdentifier})*))`;
316
+ const xRangeIdentifier = `${numericIdentifier}|x|X|\\*`;
317
+ const xRangePlain = `[v=\\s]*(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:${preRelease})?${build}?)?)?`;
318
+ const hyphenRange = `^\\s*(${xRangePlain})\\s+-\\s+(${xRangePlain})\\s*$`;
319
+ const mainVersionLoose = `(${numericIdentifierLoose})\\.(${numericIdentifierLoose})\\.(${numericIdentifierLoose})`;
320
+ const loosePlain = `[v=\\s]*${mainVersionLoose}${preReleaseLoose}?${build}?`;
321
+ const gtlt = "((?:<|>)?=?)";
322
+ const comparatorTrim = `(\\s*)${gtlt}\\s*(${loosePlain}|${xRangePlain})`;
323
+ const loneTilde = "(?:~>?)";
324
+ const tildeTrim = `(\\s*)${loneTilde}\\s+`;
325
+ const loneCaret = "(?:\\^)";
326
+ const caretTrim = `(\\s*)${loneCaret}\\s+`;
327
+ const star = "(<|>)?=?\\s*\\*";
328
+ const caret = `^${loneCaret}${xRangePlain}$`;
329
+ const mainVersion = `(${numericIdentifier})\\.(${numericIdentifier})\\.(${numericIdentifier})`;
330
+ const fullPlain = `v?${mainVersion}${preRelease}?${build}?`;
331
+ const tilde = `^${loneTilde}${xRangePlain}$`;
332
+ const xRange = `^${gtlt}\\s*${xRangePlain}$`;
333
+ const comparator = `^${gtlt}\\s*(${fullPlain})$|^$`;
334
+ const gte0 = "^\\s*>=\\s*0.0.0\\s*$";
335
+ function parseRegex(source) {
336
+ return new RegExp(source);
337
+ }
338
+ function isXVersion(version) {
339
+ return !version || version.toLowerCase() === "x" || version === "*";
340
+ }
341
+ function pipe(...fns) {
342
+ return (x) => fns.reduce((v, f) => f(v), x);
343
+ }
344
+ function extractComparator(comparatorString) {
345
+ return comparatorString.match(parseRegex(comparator));
346
+ }
347
+ function combineVersion(major, minor, patch, preRelease2) {
348
+ const mainVersion2 = `${major}.${minor}.${patch}`;
349
+ if (preRelease2) {
350
+ return `${mainVersion2}-${preRelease2}`;
351
+ }
352
+ return mainVersion2;
353
+ }
354
+ function parseHyphen(range) {
355
+ return range.replace(parseRegex(hyphenRange), (_range, from, fromMajor, fromMinor, fromPatch, _fromPreRelease, _fromBuild, to, toMajor, toMinor, toPatch, toPreRelease) => {
356
+ if (isXVersion(fromMajor)) {
357
+ from = "";
358
+ } else if (isXVersion(fromMinor)) {
359
+ from = `>=${fromMajor}.0.0`;
360
+ } else if (isXVersion(fromPatch)) {
361
+ from = `>=${fromMajor}.${fromMinor}.0`;
362
+ } else {
363
+ from = `>=${from}`;
364
+ }
365
+ if (isXVersion(toMajor)) {
366
+ to = "";
367
+ } else if (isXVersion(toMinor)) {
368
+ to = `<${Number(toMajor) + 1}.0.0-0`;
369
+ } else if (isXVersion(toPatch)) {
370
+ to = `<${toMajor}.${Number(toMinor) + 1}.0-0`;
371
+ } else if (toPreRelease) {
372
+ to = `<=${toMajor}.${toMinor}.${toPatch}-${toPreRelease}`;
373
+ } else {
374
+ to = `<=${to}`;
375
+ }
376
+ return `${from} ${to}`.trim();
377
+ });
378
+ }
379
+ function parseComparatorTrim(range) {
380
+ return range.replace(parseRegex(comparatorTrim), "$1$2$3");
381
+ }
382
+ function parseTildeTrim(range) {
383
+ return range.replace(parseRegex(tildeTrim), "$1~");
384
+ }
385
+ function parseCaretTrim(range) {
386
+ return range.replace(parseRegex(caretTrim), "$1^");
387
+ }
388
+ function parseCarets(range) {
389
+ return range.trim().split(/\s+/).map((rangeVersion) => rangeVersion.replace(parseRegex(caret), (_, major, minor, patch, preRelease2) => {
390
+ if (isXVersion(major)) {
391
+ return "";
392
+ } else if (isXVersion(minor)) {
393
+ return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
394
+ } else if (isXVersion(patch)) {
395
+ if (major === "0") {
396
+ return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
397
+ } else {
398
+ return `>=${major}.${minor}.0 <${Number(major) + 1}.0.0-0`;
399
+ }
400
+ } else if (preRelease2) {
401
+ if (major === "0") {
402
+ if (minor === "0") {
403
+ return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${minor}.${Number(patch) + 1}-0`;
404
+ } else {
405
+ return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
406
+ }
407
+ } else {
408
+ return `>=${major}.${minor}.${patch}-${preRelease2} <${Number(major) + 1}.0.0-0`;
409
+ }
410
+ } else {
411
+ if (major === "0") {
412
+ if (minor === "0") {
413
+ return `>=${major}.${minor}.${patch} <${major}.${minor}.${Number(patch) + 1}-0`;
414
+ } else {
415
+ return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
416
+ }
417
+ }
418
+ return `>=${major}.${minor}.${patch} <${Number(major) + 1}.0.0-0`;
419
+ }
420
+ })).join(" ");
421
+ }
422
+ function parseTildes(range) {
423
+ return range.trim().split(/\s+/).map((rangeVersion) => rangeVersion.replace(parseRegex(tilde), (_, major, minor, patch, preRelease2) => {
424
+ if (isXVersion(major)) {
425
+ return "";
426
+ } else if (isXVersion(minor)) {
427
+ return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
428
+ } else if (isXVersion(patch)) {
429
+ return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
430
+ } else if (preRelease2) {
431
+ return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
432
+ }
433
+ return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
434
+ })).join(" ");
435
+ }
436
+ function parseXRanges(range) {
437
+ return range.split(/\s+/).map((rangeVersion) => rangeVersion.trim().replace(parseRegex(xRange), (ret, gtlt2, major, minor, patch, preRelease2) => {
438
+ const isXMajor = isXVersion(major);
439
+ const isXMinor = isXMajor || isXVersion(minor);
440
+ const isXPatch = isXMinor || isXVersion(patch);
441
+ if (gtlt2 === "=" && isXPatch) {
442
+ gtlt2 = "";
443
+ }
444
+ preRelease2 = "";
445
+ if (isXMajor) {
446
+ if (gtlt2 === ">" || gtlt2 === "<") {
447
+ return "<0.0.0-0";
448
+ } else {
449
+ return "*";
450
+ }
451
+ } else if (gtlt2 && isXPatch) {
452
+ if (isXMinor) {
453
+ minor = 0;
454
+ }
455
+ patch = 0;
456
+ if (gtlt2 === ">") {
457
+ gtlt2 = ">=";
458
+ if (isXMinor) {
459
+ major = Number(major) + 1;
460
+ minor = 0;
461
+ patch = 0;
462
+ } else {
463
+ minor = Number(minor) + 1;
464
+ patch = 0;
465
+ }
466
+ } else if (gtlt2 === "<=") {
467
+ gtlt2 = "<";
468
+ if (isXMinor) {
469
+ major = Number(major) + 1;
470
+ } else {
471
+ minor = Number(minor) + 1;
472
+ }
473
+ }
474
+ if (gtlt2 === "<") {
475
+ preRelease2 = "-0";
476
+ }
477
+ return `${gtlt2 + major}.${minor}.${patch}${preRelease2}`;
478
+ } else if (isXMinor) {
479
+ return `>=${major}.0.0${preRelease2} <${Number(major) + 1}.0.0-0`;
480
+ } else if (isXPatch) {
481
+ return `>=${major}.${minor}.0${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
482
+ }
483
+ return ret;
484
+ })).join(" ");
485
+ }
486
+ function parseStar(range) {
487
+ return range.trim().replace(parseRegex(star), "");
488
+ }
489
+ function parseGTE0(comparatorString) {
490
+ return comparatorString.trim().replace(parseRegex(gte0), "");
491
+ }
492
+ function compareAtom(rangeAtom, versionAtom) {
493
+ rangeAtom = Number(rangeAtom) || rangeAtom;
494
+ versionAtom = Number(versionAtom) || versionAtom;
495
+ if (rangeAtom > versionAtom) {
496
+ return 1;
497
+ }
498
+ if (rangeAtom === versionAtom) {
499
+ return 0;
500
+ }
501
+ return -1;
502
+ }
503
+ function comparePreRelease(rangeAtom, versionAtom) {
504
+ const { preRelease: rangePreRelease } = rangeAtom;
505
+ const { preRelease: versionPreRelease } = versionAtom;
506
+ if (rangePreRelease === void 0 && Boolean(versionPreRelease)) {
507
+ return 1;
508
+ }
509
+ if (Boolean(rangePreRelease) && versionPreRelease === void 0) {
510
+ return -1;
511
+ }
512
+ if (rangePreRelease === void 0 && versionPreRelease === void 0) {
513
+ return 0;
514
+ }
515
+ for (let i = 0, n = rangePreRelease.length; i <= n; i++) {
516
+ const rangeElement = rangePreRelease[i];
517
+ const versionElement = versionPreRelease[i];
518
+ if (rangeElement === versionElement) {
519
+ continue;
520
+ }
521
+ if (rangeElement === void 0 && versionElement === void 0) {
522
+ return 0;
523
+ }
524
+ if (!rangeElement) {
525
+ return 1;
526
+ }
527
+ if (!versionElement) {
528
+ return -1;
529
+ }
530
+ return compareAtom(rangeElement, versionElement);
531
+ }
532
+ return 0;
533
+ }
534
+ function compareVersion(rangeAtom, versionAtom) {
535
+ return compareAtom(rangeAtom.major, versionAtom.major) || compareAtom(rangeAtom.minor, versionAtom.minor) || compareAtom(rangeAtom.patch, versionAtom.patch) || comparePreRelease(rangeAtom, versionAtom);
536
+ }
537
+ function eq(rangeAtom, versionAtom) {
538
+ return rangeAtom.version === versionAtom.version;
539
+ }
540
+ function compare(rangeAtom, versionAtom) {
541
+ switch (rangeAtom.operator) {
542
+ case "":
543
+ case "=":
544
+ return eq(rangeAtom, versionAtom);
545
+ case ">":
546
+ return compareVersion(rangeAtom, versionAtom) < 0;
547
+ case ">=":
548
+ return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0;
549
+ case "<":
550
+ return compareVersion(rangeAtom, versionAtom) > 0;
551
+ case "<=":
552
+ return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0;
553
+ case void 0: {
554
+ return true;
555
+ }
556
+ default:
557
+ return false;
558
+ }
559
+ }
560
+ function parseComparatorString(range) {
561
+ return pipe(
562
+ // handle caret
563
+ // ^ --> * (any, kinda silly)
564
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
565
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
566
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
567
+ // ^1.2.3 --> >=1.2.3 <2.0.0-0
568
+ // ^1.2.0 --> >=1.2.0 <2.0.0-0
569
+ parseCarets,
570
+ // handle tilde
571
+ // ~, ~> --> * (any, kinda silly)
572
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
573
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
574
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
575
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
576
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
577
+ parseTildes,
578
+ parseXRanges,
579
+ parseStar
580
+ )(range);
581
+ }
582
+ function parseRange(range) {
583
+ return pipe(
584
+ // handle hyphenRange
585
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
586
+ parseHyphen,
587
+ // handle trim comparator
588
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
589
+ parseComparatorTrim,
590
+ // handle trim tilde
591
+ // `~ 1.2.3` => `~1.2.3`
592
+ parseTildeTrim,
593
+ // handle trim caret
594
+ // `^ 1.2.3` => `^1.2.3`
595
+ parseCaretTrim
596
+ )(range.trim()).split(/\s+/).join(" ");
597
+ }
598
+ function satisfy(version, range) {
599
+ if (!version) {
600
+ return false;
601
+ }
602
+ const extractedVersion = extractComparator(version);
603
+ if (!extractedVersion) {
604
+ return false;
605
+ }
606
+ const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease] = extractedVersion;
607
+ const versionAtom = {
608
+ operator: versionOperator,
609
+ version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease),
610
+ // exclude build atom
611
+ major: versionMajor,
612
+ minor: versionMinor,
613
+ patch: versionPatch,
614
+ preRelease: versionPreRelease == null ? void 0 : versionPreRelease.split(".")
615
+ };
616
+ const orRanges = range.split("||");
617
+ for (const orRange of orRanges) {
618
+ const trimmedOrRange = orRange.trim();
619
+ if (!trimmedOrRange) {
620
+ return true;
621
+ }
622
+ if (trimmedOrRange === "*" || trimmedOrRange === "x") {
623
+ return true;
624
+ }
625
+ try {
626
+ const parsedSubRange = parseRange(trimmedOrRange);
627
+ if (!parsedSubRange.trim()) {
628
+ return true;
629
+ }
630
+ const parsedComparatorString = parsedSubRange.split(" ").map((rangeVersion) => parseComparatorString(rangeVersion)).join(" ");
631
+ if (!parsedComparatorString.trim()) {
632
+ return true;
633
+ }
634
+ const comparators = parsedComparatorString.split(/\s+/).map((comparator2) => parseGTE0(comparator2)).filter(Boolean);
635
+ if (comparators.length === 0) {
636
+ continue;
637
+ }
638
+ let subRangeSatisfied = true;
639
+ for (const comparator2 of comparators) {
640
+ const extractedComparator = extractComparator(comparator2);
641
+ if (!extractedComparator) {
642
+ subRangeSatisfied = false;
643
+ break;
644
+ }
645
+ const [, rangeOperator, , rangeMajor, rangeMinor, rangePatch, rangePreRelease] = extractedComparator;
646
+ const rangeAtom = {
647
+ operator: rangeOperator,
648
+ version: combineVersion(rangeMajor, rangeMinor, rangePatch, rangePreRelease),
649
+ major: rangeMajor,
650
+ minor: rangeMinor,
651
+ patch: rangePatch,
652
+ preRelease: rangePreRelease == null ? void 0 : rangePreRelease.split(".")
653
+ };
654
+ if (!compare(rangeAtom, versionAtom)) {
655
+ subRangeSatisfied = false;
656
+ break;
657
+ }
658
+ }
659
+ if (subRangeSatisfied) {
660
+ return true;
661
+ }
662
+ } catch (e) {
663
+ console.error(`[semver] Error processing range part "${trimmedOrRange}":`, e);
664
+ continue;
665
+ }
666
+ }
667
+ return false;
668
+ }
669
+ function versionLt(a, b) {
670
+ const transformInvalidVersion = (version) => {
671
+ const isNumberVersion = !Number.isNaN(Number(version));
672
+ if (isNumberVersion) {
673
+ const splitArr = version.split(".");
674
+ let validVersion = version;
675
+ for (let i = 0; i < 3 - splitArr.length; i++) {
676
+ validVersion += ".0";
677
+ }
678
+ return validVersion;
679
+ }
680
+ return version;
681
+ };
682
+ if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
683
+ return true;
684
+ } else {
685
+ return false;
686
+ }
687
+ }
688
+ const findVersion = (shareVersionMap, cb) => {
689
+ const callback = cb || function(prev, cur) {
690
+ return versionLt(prev, cur);
691
+ };
692
+ return Object.keys(shareVersionMap).reduce((prev, cur) => {
693
+ if (!prev) {
694
+ return cur;
695
+ }
696
+ if (callback(prev, cur)) {
697
+ return cur;
698
+ }
699
+ if (prev === "0") {
700
+ return cur;
701
+ }
702
+ return prev;
703
+ }, 0);
704
+ };
705
+ const isLoaded = (shared) => {
706
+ return Boolean(shared.loaded) || typeof shared.lib === "function";
707
+ };
708
+ const isLoading = (shared) => {
709
+ return Boolean(shared.loading);
710
+ };
711
+ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
712
+ const versions = shareScopeMap[scope][pkgName];
713
+ const callback = function(prev, cur) {
714
+ return !isLoaded(versions[prev]) && versionLt(prev, cur);
715
+ };
716
+ return findVersion(shareScopeMap[scope][pkgName], callback);
717
+ }
718
+ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
719
+ const versions = shareScopeMap[scope][pkgName];
720
+ const callback = function(prev, cur) {
721
+ const isLoadingOrLoaded = (shared) => {
722
+ return isLoaded(shared) || isLoading(shared);
723
+ };
724
+ if (isLoadingOrLoaded(versions[cur])) {
725
+ if (isLoadingOrLoaded(versions[prev])) {
726
+ return Boolean(versionLt(prev, cur));
727
+ } else {
728
+ return true;
729
+ }
730
+ }
731
+ if (isLoadingOrLoaded(versions[prev])) {
732
+ return false;
733
+ }
734
+ return versionLt(prev, cur);
735
+ };
736
+ return findVersion(shareScopeMap[scope][pkgName], callback);
737
+ }
738
+ function getFindShareFunction(strategy) {
739
+ if (strategy === "loaded-first") {
740
+ return findSingletonVersionOrderByLoaded;
741
+ }
742
+ return findSingletonVersionOrderByVersion;
743
+ }
744
+ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
745
+ if (!localShareScopeMap) {
746
+ return;
747
+ }
748
+ const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
749
+ const scopes = Array.isArray(scope) ? scope : [scope];
750
+ for (const sc of scopes) {
751
+ if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
752
+ const { requiredVersion } = shareConfig;
753
+ const findShareFunction = getFindShareFunction(strategy);
754
+ const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
755
+ const defaultResolver = () => {
756
+ if (shareConfig.singleton) {
757
+ if (typeof requiredVersion === "string" && !satisfy(maxOrSingletonVersion, requiredVersion)) {
758
+ const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
759
+ if (shareConfig.strictVersion) {
760
+ error(msg);
761
+ } else {
762
+ warn(msg);
763
+ }
764
+ }
765
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
766
+ } else {
767
+ if (requiredVersion === false || requiredVersion === "*") {
768
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
769
+ }
770
+ if (satisfy(maxOrSingletonVersion, requiredVersion)) {
771
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
772
+ }
773
+ for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])) {
774
+ if (satisfy(versionKey, requiredVersion)) {
775
+ return versionValue;
776
+ }
777
+ }
778
+ }
779
+ };
780
+ const params = {
781
+ shareScopeMap: localShareScopeMap,
782
+ scope: sc,
783
+ pkgName,
784
+ version: maxOrSingletonVersion,
785
+ GlobalFederation: Global.__FEDERATION__,
786
+ resolver: defaultResolver
787
+ };
788
+ const resolveShared = resolveShare.emit(params) || params;
789
+ return resolveShared.resolver();
790
+ }
791
+ }
792
+ }
793
+ function getGlobalShareScope() {
794
+ return Global.__FEDERATION__.__SHARE__;
795
+ }
796
+ function matchRemoteWithNameAndExpose(remotes, id) {
797
+ for (const remote of remotes) {
798
+ const isNameMatched = id.startsWith(remote.name);
799
+ let expose = id.replace(remote.name, "");
800
+ if (isNameMatched) {
801
+ if (expose.startsWith("/")) {
802
+ const pkgNameOrAlias = remote.name;
803
+ expose = `.${expose}`;
804
+ return {
805
+ pkgNameOrAlias,
806
+ expose,
807
+ remote
808
+ };
809
+ } else if (expose === "") {
810
+ return {
811
+ pkgNameOrAlias: remote.name,
812
+ expose: ".",
813
+ remote
814
+ };
815
+ }
816
+ }
817
+ const isAliasMatched = remote.alias && id.startsWith(remote.alias);
818
+ let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
819
+ if (remote.alias && isAliasMatched) {
820
+ if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
821
+ const pkgNameOrAlias = remote.alias;
822
+ exposeWithAlias = `.${exposeWithAlias}`;
823
+ return {
824
+ pkgNameOrAlias,
825
+ expose: exposeWithAlias,
826
+ remote
827
+ };
828
+ } else if (exposeWithAlias === "") {
829
+ return {
830
+ pkgNameOrAlias: remote.alias,
831
+ expose: ".",
832
+ remote
833
+ };
834
+ }
835
+ }
836
+ }
837
+ return;
838
+ }
839
+ const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
840
+ async function loadEsmEntry({ entry, remoteEntryExports }) {
841
+ return new Promise((resolve, reject) => {
842
+ try {
843
+ if (!remoteEntryExports) {
844
+ if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") {
845
+ new Function("callbacks", `import("${entry}")${importCallback}`)([
846
+ resolve,
847
+ reject
848
+ ]);
849
+ } else {
850
+ import(
851
+ /* webpackIgnore: true */
852
+ /* @vite-ignore */
853
+ entry
854
+ ).then(resolve).catch(reject);
855
+ }
856
+ } else {
857
+ resolve(remoteEntryExports);
858
+ }
859
+ } catch (e) {
860
+ reject(e);
861
+ }
862
+ });
863
+ }
864
+ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
865
+ return new Promise((resolve, reject) => {
866
+ try {
867
+ if (!remoteEntryExports) {
868
+ if (typeof __system_context__ === "undefined") {
869
+ System.import(entry).then(resolve).catch(reject);
870
+ } else {
871
+ new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
872
+ }
873
+ } else {
874
+ resolve(remoteEntryExports);
875
+ }
876
+ } catch (e) {
877
+ reject(e);
878
+ }
879
+ });
880
+ }
881
+ function handleRemoteEntryLoaded(name, globalName, entry) {
882
+ const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
883
+ assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
884
+ remoteName: name,
885
+ remoteEntryUrl: entry,
886
+ remoteEntryKey
887
+ }));
888
+ return entryExports;
889
+ }
890
+ async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl }) {
891
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
892
+ if (remoteEntryExports) {
893
+ return remoteEntryExports;
894
+ }
895
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
896
+ return loadScript(url, {
897
+ attrs: {},
898
+ createScriptHook: (url2, attrs) => {
899
+ const res = loaderHook.lifecycle.createScript.emit({ url: url2, attrs });
900
+ if (!res)
901
+ return;
902
+ if (res instanceof HTMLScriptElement) {
903
+ return res;
904
+ }
905
+ if ("script" in res || "timeout" in res) {
906
+ return res;
907
+ }
908
+ return;
909
+ }
910
+ }).then(() => {
911
+ return handleRemoteEntryLoaded(name, globalName, entry);
912
+ }).catch((e) => {
913
+ assert(void 0, getShortErrorMsg(RUNTIME_008, runtimeDescMap, {
914
+ remoteName: name,
915
+ resourceUrl: entry
916
+ }));
917
+ throw e;
918
+ });
919
+ }
920
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
921
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
922
+ switch (type) {
923
+ case "esm":
924
+ case "module":
925
+ return loadEsmEntry({ entry, remoteEntryExports });
926
+ case "system":
927
+ return loadSystemJsEntry({ entry, remoteEntryExports });
928
+ default:
929
+ return loadEntryScript({
930
+ entry,
931
+ globalName,
932
+ name,
933
+ loaderHook,
934
+ getEntryUrl
935
+ });
936
+ }
937
+ }
938
+ async function loadEntryNode({ remoteInfo, loaderHook }) {
939
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
940
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
941
+ if (remoteEntryExports) {
942
+ return remoteEntryExports;
943
+ }
944
+ return loadScriptNode(entry, {
945
+ attrs: { name, globalName, type },
946
+ loaderHook: {
947
+ createScriptHook: (url, attrs = {}) => {
948
+ const res = loaderHook.lifecycle.createScript.emit({ url, attrs });
949
+ if (!res)
950
+ return;
951
+ if ("url" in res) {
952
+ return res;
953
+ }
954
+ return;
955
+ }
956
+ }
957
+ }).then(() => {
958
+ return handleRemoteEntryLoaded(name, globalName, entry);
959
+ }).catch((e) => {
960
+ throw e;
961
+ });
962
+ }
963
+ function getRemoteEntryUniqueKey(remoteInfo) {
964
+ const { entry, name } = remoteInfo;
965
+ return composeKeyWithSeparator(name, entry);
966
+ }
967
+ async function getRemoteEntry(params) {
968
+ const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
969
+ const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
970
+ if (remoteEntryExports) {
971
+ return remoteEntryExports;
972
+ }
973
+ if (!globalLoading[uniqueKey]) {
974
+ const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
975
+ const loaderHook = origin.loaderHook;
976
+ globalLoading[uniqueKey] = loadEntryHook.emit({
977
+ loaderHook,
978
+ remoteInfo,
979
+ remoteEntryExports
980
+ }).then((res) => {
981
+ if (res) {
982
+ return res;
983
+ }
984
+ const isWebEnvironment = typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : isBrowserEnv();
985
+ return isWebEnvironment ? loadEntryDom({
986
+ remoteInfo,
987
+ remoteEntryExports,
988
+ loaderHook,
989
+ getEntryUrl
990
+ }) : loadEntryNode({ remoteInfo, loaderHook });
991
+ }).catch(async (err) => {
992
+ const uniqueKey2 = getRemoteEntryUniqueKey(remoteInfo);
993
+ const isScriptLoadError = err instanceof Error && err.message.includes(RUNTIME_008);
994
+ if (isScriptLoadError && !_inErrorHandling) {
995
+ const wrappedGetRemoteEntry = (params2) => {
996
+ return getRemoteEntry({ ...params2, _inErrorHandling: true });
997
+ };
998
+ const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
999
+ getRemoteEntry: wrappedGetRemoteEntry,
1000
+ origin,
1001
+ remoteInfo,
1002
+ remoteEntryExports,
1003
+ globalLoading,
1004
+ uniqueKey: uniqueKey2
1005
+ });
1006
+ if (RemoteEntryExports) {
1007
+ return RemoteEntryExports;
1008
+ }
1009
+ }
1010
+ throw err;
1011
+ });
1012
+ }
1013
+ return globalLoading[uniqueKey];
1014
+ }
1015
+ function getRemoteInfo(remote) {
1016
+ return {
1017
+ ...remote,
1018
+ entry: "entry" in remote ? remote.entry : "",
1019
+ type: remote.type || DEFAULT_REMOTE_TYPE,
1020
+ entryGlobalName: remote.entryGlobalName || remote.name,
1021
+ shareScope: remote.shareScope || DEFAULT_SCOPE
1022
+ };
1023
+ }
1024
+ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
1025
+ const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
1026
+ if (host.options.inBrowser) {
1027
+ entryAssets.forEach((asset) => {
1028
+ const { moduleInfo } = asset;
1029
+ const module = host.moduleCache.get(remoteInfo.name);
1030
+ if (module) {
1031
+ getRemoteEntry({
1032
+ origin: host,
1033
+ remoteInfo: moduleInfo,
1034
+ remoteEntryExports: module.remoteEntryExports
1035
+ });
1036
+ } else {
1037
+ getRemoteEntry({
1038
+ origin: host,
1039
+ remoteInfo: moduleInfo,
1040
+ remoteEntryExports: void 0
1041
+ });
1042
+ }
1043
+ });
1044
+ if (useLinkPreload) {
1045
+ const defaultAttrs = {
1046
+ rel: "preload",
1047
+ as: "style"
1048
+ };
1049
+ cssAssets.forEach((cssUrl) => {
1050
+ const { link: cssEl, needAttach } = createLink({
1051
+ url: cssUrl,
1052
+ cb: () => {
1053
+ },
1054
+ attrs: defaultAttrs,
1055
+ createLinkHook: (url, attrs) => {
1056
+ const res = host.loaderHook.lifecycle.createLink.emit({
1057
+ url,
1058
+ attrs
1059
+ });
1060
+ if (res instanceof HTMLLinkElement) {
1061
+ return res;
1062
+ }
1063
+ return;
1064
+ }
1065
+ });
1066
+ needAttach && document.head.appendChild(cssEl);
1067
+ });
1068
+ } else {
1069
+ const defaultAttrs = {
1070
+ rel: "stylesheet",
1071
+ type: "text/css"
1072
+ };
1073
+ cssAssets.forEach((cssUrl) => {
1074
+ const { link: cssEl, needAttach } = createLink({
1075
+ url: cssUrl,
1076
+ cb: () => {
1077
+ },
1078
+ attrs: defaultAttrs,
1079
+ createLinkHook: (url, attrs) => {
1080
+ const res = host.loaderHook.lifecycle.createLink.emit({
1081
+ url,
1082
+ attrs
1083
+ });
1084
+ if (res instanceof HTMLLinkElement) {
1085
+ return res;
1086
+ }
1087
+ return;
1088
+ },
1089
+ needDeleteLink: false
1090
+ });
1091
+ needAttach && document.head.appendChild(cssEl);
1092
+ });
1093
+ }
1094
+ if (useLinkPreload) {
1095
+ const defaultAttrs = {
1096
+ rel: "preload",
1097
+ as: "script"
1098
+ };
1099
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
1100
+ const { link: linkEl, needAttach } = createLink({
1101
+ url: jsUrl,
1102
+ cb: () => {
1103
+ },
1104
+ attrs: defaultAttrs,
1105
+ createLinkHook: (url, attrs) => {
1106
+ const res = host.loaderHook.lifecycle.createLink.emit({
1107
+ url,
1108
+ attrs
1109
+ });
1110
+ if (res instanceof HTMLLinkElement) {
1111
+ return res;
1112
+ }
1113
+ return;
1114
+ }
1115
+ });
1116
+ needAttach && document.head.appendChild(linkEl);
1117
+ });
1118
+ } else {
1119
+ const defaultAttrs = {
1120
+ fetchpriority: "high",
1121
+ type: (remoteInfo == null ? void 0 : remoteInfo.type) === "module" ? "module" : "text/javascript"
1122
+ };
1123
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
1124
+ const { script: scriptEl, needAttach } = createScript({
1125
+ url: jsUrl,
1126
+ cb: () => {
1127
+ },
1128
+ attrs: defaultAttrs,
1129
+ createScriptHook: (url, attrs) => {
1130
+ const res = host.loaderHook.lifecycle.createScript.emit({
1131
+ url,
1132
+ attrs
1133
+ });
1134
+ if (res instanceof HTMLScriptElement) {
1135
+ return res;
1136
+ }
1137
+ return;
1138
+ },
1139
+ needDeleteScript: true
1140
+ });
1141
+ needAttach && document.head.appendChild(scriptEl);
1142
+ });
1143
+ }
1144
+ }
1145
+ }
1146
+ const ShareUtils = {
1147
+ getRegisteredShare,
1148
+ getGlobalShareScope
1149
+ };
1150
+ const GlobalUtils = {
1151
+ Global,
1152
+ nativeGlobal,
1153
+ resetFederationGlobalInfo,
1154
+ setGlobalFederationInstance,
1155
+ getGlobalFederationConstructor,
1156
+ setGlobalFederationConstructor,
1157
+ getInfoWithoutType,
1158
+ getGlobalSnapshot,
1159
+ getTargetSnapshotInfoByModuleInfo,
1160
+ getGlobalSnapshotInfoByModuleInfo,
1161
+ setGlobalSnapshotInfoByModuleInfo,
1162
+ addGlobalSnapshot,
1163
+ getRemoteEntryExports,
1164
+ registerGlobalPlugins,
1165
+ getGlobalHostPlugins,
1166
+ getPreloaded,
1167
+ setPreloaded
1168
+ };
1169
+ var helpers$1 = {
1170
+ global: GlobalUtils,
1171
+ share: ShareUtils,
1172
+ utils: {
1173
+ matchRemoteWithNameAndExpose,
1174
+ preloadAssets,
1175
+ getRemoteInfo
1176
+ }
1177
+ };
1178
+ typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
1179
+ var helpers = {
1180
+ ...helpers$1,
1181
+ global: {
1182
+ ...helpers$1.global
1183
+ }
1184
+ };
1185
+ async function prefetch(options) {
1186
+ const { instance, id, dataFetchParams, preloadComponentResource } = options;
1187
+ if (!id) {
1188
+ logger$1.error("id is required for prefetch!");
1189
+ return;
1190
+ }
1191
+ if (!instance) {
1192
+ logger$1.error("instance is required for prefetch!");
1193
+ return;
1194
+ }
1195
+ const matchedRemoteInfo = helpers.utils.matchRemoteWithNameAndExpose(
1196
+ instance.options.remotes,
1197
+ id
1198
+ );
1199
+ if (!matchedRemoteInfo) {
1200
+ logger$1.error(`Can not found '${id}' in instance.options.remotes!`);
1201
+ return;
1202
+ }
1203
+ const { remote, expose } = matchedRemoteInfo;
1204
+ const { remoteSnapshot, globalSnapshot } = await instance.snapshotHandler.loadRemoteSnapshotInfo({
1205
+ moduleInfo: remote,
1206
+ id,
1207
+ expose
1208
+ });
1209
+ if (preloadComponentResource) {
1210
+ const remoteInfo = helpers.utils.getRemoteInfo(remote);
1211
+ Promise.resolve(
1212
+ instance.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
1213
+ origin: instance,
1214
+ preloadOptions: {
1215
+ remote,
1216
+ preloadConfig: {
1217
+ nameOrAlias: remote.name,
1218
+ exposes: [expose]
1219
+ }
1220
+ },
1221
+ remote,
1222
+ remoteInfo,
1223
+ globalSnapshot,
1224
+ remoteSnapshot
1225
+ })
1226
+ ).then((assets) => {
1227
+ if (assets) {
1228
+ helpers.utils.preloadAssets(remoteInfo, instance, assets);
1229
+ }
1230
+ });
1231
+ }
1232
+ const dataFetchMap = getDataFetchMap();
1233
+ if (!dataFetchMap) {
1234
+ return;
1235
+ }
1236
+ const dataFetchInfo = getDataFetchInfo({
1237
+ name: remote.name,
1238
+ alias: remote.alias,
1239
+ id,
1240
+ remoteSnapshot
1241
+ });
1242
+ const dataFetchMapKey = getDataFetchMapKey(dataFetchInfo, {
1243
+ name: instance.name,
1244
+ version: instance.options.version
1245
+ });
1246
+ if (!dataFetchMapKey) {
1247
+ return;
1248
+ }
1249
+ const dataFetchItem = dataFetchMap[dataFetchMapKey];
1250
+ if (!dataFetchItem) {
1251
+ return;
1252
+ }
1253
+ const [getDataFetchGetter, _type, getDataFetchPromise] = dataFetchItem[0];
1254
+ let _getDataFetchPromise = getDataFetchPromise;
1255
+ if (!getDataFetchPromise) {
1256
+ if (!getDataFetchGetter) {
1257
+ return;
1258
+ }
1259
+ _getDataFetchPromise = getDataFetchGetter();
1260
+ }
1261
+ _getDataFetchPromise.then((dataFetchFn) => {
1262
+ return dataFetchFn({
1263
+ ...dataFetchParams,
1264
+ _id: dataFetchMapKey,
1265
+ isDowngrade: false
1266
+ });
1267
+ });
1268
+ }
1269
+ export {
1270
+ dataFetchFunction as d,
1271
+ injectDataFetch as i,
1272
+ prefetch as p
1273
+ };