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