@module-federation/bridge-react 0.0.0-next-20250707074728 → 0.0.0-next-20250708033956

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