@module-federation/bridge-react 2.0.0 → 2.0.1

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