@module-federation/bridge-react 0.0.0-next-20250708121428 → 0.0.0-next-20250709032753

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