@module-federation/bridge-react 0.15.0 → 0.17.0

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