@module-federation/bridge-react 0.16.0 → 0.17.1

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