@module-federation/runtime-core 0.0.0-feat-support-bridge-react-router-v7-20251015102312

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 (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/LICENSE +21 -0
  4. package/dist/index.cjs.cjs +3240 -0
  5. package/dist/index.cjs.cjs.map +1 -0
  6. package/dist/index.cjs.d.ts +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.esm.js +3216 -0
  9. package/dist/index.esm.js.map +1 -0
  10. package/dist/src/constant.d.ts +2 -0
  11. package/dist/src/core.d.ts +115 -0
  12. package/dist/src/global.d.ts +42 -0
  13. package/dist/src/helpers.d.ts +38 -0
  14. package/dist/src/index.d.ts +14 -0
  15. package/dist/src/module/index.d.ts +21 -0
  16. package/dist/src/plugins/generate-preload-assets.d.ts +8 -0
  17. package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +60 -0
  18. package/dist/src/plugins/snapshot/index.d.ts +5 -0
  19. package/dist/src/remote/index.d.ts +109 -0
  20. package/dist/src/shared/index.d.ts +66 -0
  21. package/dist/src/type/config.d.ts +115 -0
  22. package/dist/src/type/index.d.ts +3 -0
  23. package/dist/src/type/plugin.d.ts +35 -0
  24. package/dist/src/type/preload.d.ts +26 -0
  25. package/dist/src/types.d.ts +1 -0
  26. package/dist/src/utils/env.d.ts +3 -0
  27. package/dist/src/utils/hooks/asyncHook.d.ts +6 -0
  28. package/dist/src/utils/hooks/asyncWaterfallHooks.d.ts +10 -0
  29. package/dist/src/utils/hooks/index.d.ts +6 -0
  30. package/dist/src/utils/hooks/pluginSystem.d.ts +16 -0
  31. package/dist/src/utils/hooks/syncHook.d.ts +12 -0
  32. package/dist/src/utils/hooks/syncWaterfallHook.d.ts +9 -0
  33. package/dist/src/utils/index.d.ts +6 -0
  34. package/dist/src/utils/load.d.ts +11 -0
  35. package/dist/src/utils/logger.d.ts +6 -0
  36. package/dist/src/utils/manifest.d.ts +7 -0
  37. package/dist/src/utils/plugin.d.ts +3 -0
  38. package/dist/src/utils/preload.d.ts +6 -0
  39. package/dist/src/utils/semver/compare.d.ts +9 -0
  40. package/dist/src/utils/semver/constants.d.ts +10 -0
  41. package/dist/src/utils/semver/index.d.ts +2 -0
  42. package/dist/src/utils/semver/parser.d.ts +9 -0
  43. package/dist/src/utils/semver/utils.d.ts +11 -0
  44. package/dist/src/utils/share.d.ts +27 -0
  45. package/dist/src/utils/tool.d.ts +18 -0
  46. package/dist/types.cjs.cjs +3 -0
  47. package/dist/types.cjs.cjs.map +1 -0
  48. package/dist/types.cjs.d.ts +1 -0
  49. package/dist/types.d.ts +1 -0
  50. package/dist/types.esm.js +2 -0
  51. package/dist/types.esm.js.map +1 -0
  52. package/package.json +58 -0
@@ -0,0 +1,3240 @@
1
+ 'use strict';
2
+
3
+ var sdk = require('@module-federation/sdk');
4
+ var errorCodes = require('@module-federation/error-codes');
5
+
6
+ const LOG_CATEGORY = '[ Federation Runtime ]';
7
+ // FIXME: pre-bundle ?
8
+ const logger = sdk.createLogger(LOG_CATEGORY);
9
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
10
+ function assert(condition, msg) {
11
+ if (!condition) {
12
+ error(msg);
13
+ }
14
+ }
15
+ function error(msg) {
16
+ if (msg instanceof Error) {
17
+ // Check if the message already starts with the log category to avoid duplication
18
+ if (!msg.message.startsWith(LOG_CATEGORY)) {
19
+ msg.message = `${LOG_CATEGORY}: ${msg.message}`;
20
+ }
21
+ throw msg;
22
+ }
23
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
24
+ }
25
+ function warn(msg) {
26
+ if (msg instanceof Error) {
27
+ // Check if the message already starts with the log category to avoid duplication
28
+ if (!msg.message.startsWith(LOG_CATEGORY)) {
29
+ msg.message = `${LOG_CATEGORY}: ${msg.message}`;
30
+ }
31
+ logger.warn(msg);
32
+ }
33
+ else {
34
+ logger.warn(msg);
35
+ }
36
+ }
37
+
38
+ function addUniqueItem(arr, item) {
39
+ if (arr.findIndex((name) => name === item) === -1) {
40
+ arr.push(item);
41
+ }
42
+ return arr;
43
+ }
44
+ function getFMId(remoteInfo) {
45
+ if ('version' in remoteInfo && remoteInfo.version) {
46
+ return `${remoteInfo.name}:${remoteInfo.version}`;
47
+ }
48
+ else if ('entry' in remoteInfo && remoteInfo.entry) {
49
+ return `${remoteInfo.name}:${remoteInfo.entry}`;
50
+ }
51
+ else {
52
+ return `${remoteInfo.name}`;
53
+ }
54
+ }
55
+ function isRemoteInfoWithEntry(remote) {
56
+ return typeof remote.entry !== 'undefined';
57
+ }
58
+ function isPureRemoteEntry(remote) {
59
+ return !remote.entry.includes('.json');
60
+ }
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ async function safeWrapper(callback, disableWarn) {
63
+ try {
64
+ const res = await callback();
65
+ return res;
66
+ }
67
+ catch (e) {
68
+ !disableWarn && warn(e);
69
+ return;
70
+ }
71
+ }
72
+ function isObject(val) {
73
+ return val && typeof val === 'object';
74
+ }
75
+ const objectToString = Object.prototype.toString;
76
+ // eslint-disable-next-line @typescript-eslint/ban-types
77
+ function isPlainObject(val) {
78
+ return objectToString.call(val) === '[object Object]';
79
+ }
80
+ function isStaticResourcesEqual(url1, url2) {
81
+ const REG_EXP = /^(https?:)?\/\//i;
82
+ // Transform url1 and url2 into relative paths
83
+ const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
84
+ const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
85
+ // Check if the relative paths are identical
86
+ return relativeUrl1 === relativeUrl2;
87
+ }
88
+ function arrayOptions(options) {
89
+ return Array.isArray(options) ? options : [options];
90
+ }
91
+ function getRemoteEntryInfoFromSnapshot(snapshot) {
92
+ const defaultRemoteEntryInfo = {
93
+ url: '',
94
+ type: 'global',
95
+ globalName: '',
96
+ };
97
+ if (sdk.isBrowserEnv() || sdk.isReactNativeEnv()) {
98
+ return 'remoteEntry' in snapshot
99
+ ? {
100
+ url: snapshot.remoteEntry,
101
+ type: snapshot.remoteEntryType,
102
+ globalName: snapshot.globalName,
103
+ }
104
+ : defaultRemoteEntryInfo;
105
+ }
106
+ if ('ssrRemoteEntry' in snapshot) {
107
+ return {
108
+ url: snapshot.ssrRemoteEntry || defaultRemoteEntryInfo.url,
109
+ type: snapshot.ssrRemoteEntryType || defaultRemoteEntryInfo.type,
110
+ globalName: snapshot.globalName,
111
+ };
112
+ }
113
+ return defaultRemoteEntryInfo;
114
+ }
115
+ const processModuleAlias = (name, subPath) => {
116
+ // @host/ ./button -> @host/button
117
+ let moduleName;
118
+ if (name.endsWith('/')) {
119
+ moduleName = name.slice(0, -1);
120
+ }
121
+ else {
122
+ moduleName = name;
123
+ }
124
+ if (subPath.startsWith('.')) {
125
+ subPath = subPath.slice(1);
126
+ }
127
+ moduleName = moduleName + subPath;
128
+ return moduleName;
129
+ };
130
+
131
+ const CurrentGlobal = typeof globalThis === 'object' ? globalThis : window;
132
+ const nativeGlobal = (() => {
133
+ try {
134
+ // get real window (incase of sandbox)
135
+ return document.defaultView;
136
+ }
137
+ catch {
138
+ // node env
139
+ return CurrentGlobal;
140
+ }
141
+ })();
142
+ const Global = nativeGlobal;
143
+ function definePropertyGlobalVal(target, key, val) {
144
+ Object.defineProperty(target, key, {
145
+ value: val,
146
+ configurable: false,
147
+ writable: true,
148
+ });
149
+ }
150
+ function includeOwnProperty(target, key) {
151
+ return Object.hasOwnProperty.call(target, key);
152
+ }
153
+ // This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
154
+ // The sandbox in the microfrontend does not replicate the value of 'configurable'.
155
+ // If there is no loading content on the global object, this section defines the loading object.
156
+ if (!includeOwnProperty(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
157
+ definePropertyGlobalVal(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
158
+ }
159
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
160
+ function setGlobalDefaultVal(target) {
161
+ if (includeOwnProperty(target, '__VMOK__') &&
162
+ !includeOwnProperty(target, '__FEDERATION__')) {
163
+ definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
164
+ }
165
+ if (!includeOwnProperty(target, '__FEDERATION__')) {
166
+ definePropertyGlobalVal(target, '__FEDERATION__', {
167
+ __GLOBAL_PLUGIN__: [],
168
+ __INSTANCES__: [],
169
+ moduleInfo: {},
170
+ __SHARE__: {},
171
+ __MANIFEST_LOADING__: {},
172
+ __PRELOADED_MAP__: new Map(),
173
+ });
174
+ definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
175
+ }
176
+ target.__FEDERATION__.__GLOBAL_PLUGIN__ ??= [];
177
+ target.__FEDERATION__.__INSTANCES__ ??= [];
178
+ target.__FEDERATION__.moduleInfo ??= {};
179
+ target.__FEDERATION__.__SHARE__ ??= {};
180
+ target.__FEDERATION__.__MANIFEST_LOADING__ ??= {};
181
+ target.__FEDERATION__.__PRELOADED_MAP__ ??= new Map();
182
+ }
183
+ setGlobalDefaultVal(CurrentGlobal);
184
+ setGlobalDefaultVal(nativeGlobal);
185
+ function resetFederationGlobalInfo() {
186
+ CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
187
+ CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];
188
+ CurrentGlobal.__FEDERATION__.moduleInfo = {};
189
+ CurrentGlobal.__FEDERATION__.__SHARE__ = {};
190
+ CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
191
+ Object.keys(globalLoading).forEach((key) => {
192
+ delete globalLoading[key];
193
+ });
194
+ }
195
+ function setGlobalFederationInstance(FederationInstance) {
196
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);
197
+ }
198
+ function getGlobalFederationConstructor() {
199
+ return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
200
+ }
201
+ function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
202
+ if (isDebug) {
203
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
204
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-feat-support-bridge-react-router-v7-20251015102312";
205
+ }
206
+ }
207
+ // eslint-disable-next-line @typescript-eslint/ban-types
208
+ function getInfoWithoutType(target, key) {
209
+ if (typeof key === 'string') {
210
+ const keyRes = target[key];
211
+ if (keyRes) {
212
+ return {
213
+ value: target[key],
214
+ key: key,
215
+ };
216
+ }
217
+ else {
218
+ const targetKeys = Object.keys(target);
219
+ for (const targetKey of targetKeys) {
220
+ const [targetTypeOrName, _] = targetKey.split(':');
221
+ const nKey = `${targetTypeOrName}:${key}`;
222
+ const typeWithKeyRes = target[nKey];
223
+ if (typeWithKeyRes) {
224
+ return {
225
+ value: typeWithKeyRes,
226
+ key: nKey,
227
+ };
228
+ }
229
+ }
230
+ return {
231
+ value: undefined,
232
+ key: key,
233
+ };
234
+ }
235
+ }
236
+ else {
237
+ throw new Error('key must be string');
238
+ }
239
+ }
240
+ const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo;
241
+ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot) => {
242
+ // Check if the remote is included in the hostSnapshot
243
+ const moduleKey = getFMId(moduleInfo);
244
+ const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
245
+ // The remoteSnapshot might not include a version
246
+ if (getModuleInfo &&
247
+ !getModuleInfo.version &&
248
+ 'version' in moduleInfo &&
249
+ moduleInfo['version']) {
250
+ getModuleInfo.version = moduleInfo['version'];
251
+ }
252
+ if (getModuleInfo) {
253
+ return getModuleInfo;
254
+ }
255
+ // If the remote is not included in the hostSnapshot, deploy a micro app snapshot
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?.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
+ // This function is used to register global plugins.
293
+ // It iterates over the provided plugins and checks if they are already registered.
294
+ // If a plugin is not registered, it is added to the global plugins.
295
+ // If a plugin is already registered, a warning message is logged.
296
+ const registerGlobalPlugins = (plugins) => {
297
+ const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
298
+ plugins.forEach((plugin) => {
299
+ if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) {
300
+ __GLOBAL_PLUGIN__.push(plugin);
301
+ }
302
+ else {
303
+ warn(`The plugin ${plugin.name} has been registered.`);
304
+ }
305
+ });
306
+ };
307
+ const getGlobalHostPlugins = () => nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
308
+ const getPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
309
+ const setPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
310
+
311
+ const DEFAULT_SCOPE = 'default';
312
+ const DEFAULT_REMOTE_TYPE = 'global';
313
+
314
+ // fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
315
+ // those constants are based on https://www.rubydoc.info/gems/semantic_range/3.0.0/SemanticRange#BUILDIDENTIFIER-constant
316
+ // Copyright (c)
317
+ // vite-plugin-federation is licensed under Mulan PSL v2.
318
+ // You can use this software according to the terms and conditions of the Mulan PSL v2.
319
+ // You may obtain a copy of Mulan PSL v2 at:
320
+ // http://license.coscl.org.cn/MulanPSL2
321
+ // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
322
+ // See the Mulan PSL v2 for more details.
323
+ const buildIdentifier = '[0-9A-Za-z-]+';
324
+ const build = `(?:\\+(${buildIdentifier}(?:\\.${buildIdentifier})*))`;
325
+ const numericIdentifier = '0|[1-9]\\d*';
326
+ const numericIdentifierLoose = '[0-9]+';
327
+ const nonNumericIdentifier = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
328
+ const preReleaseIdentifierLoose = `(?:${numericIdentifierLoose}|${nonNumericIdentifier})`;
329
+ const preReleaseLoose = `(?:-?(${preReleaseIdentifierLoose}(?:\\.${preReleaseIdentifierLoose})*))`;
330
+ const preReleaseIdentifier = `(?:${numericIdentifier}|${nonNumericIdentifier})`;
331
+ const preRelease = `(?:-(${preReleaseIdentifier}(?:\\.${preReleaseIdentifier})*))`;
332
+ const xRangeIdentifier = `${numericIdentifier}|x|X|\\*`;
333
+ const xRangePlain = `[v=\\s]*(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:${preRelease})?${build}?)?)?`;
334
+ const hyphenRange = `^\\s*(${xRangePlain})\\s+-\\s+(${xRangePlain})\\s*$`;
335
+ const mainVersionLoose = `(${numericIdentifierLoose})\\.(${numericIdentifierLoose})\\.(${numericIdentifierLoose})`;
336
+ const loosePlain = `[v=\\s]*${mainVersionLoose}${preReleaseLoose}?${build}?`;
337
+ const gtlt = '((?:<|>)?=?)';
338
+ const comparatorTrim = `(\\s*)${gtlt}\\s*(${loosePlain}|${xRangePlain})`;
339
+ const loneTilde = '(?:~>?)';
340
+ const tildeTrim = `(\\s*)${loneTilde}\\s+`;
341
+ const loneCaret = '(?:\\^)';
342
+ const caretTrim = `(\\s*)${loneCaret}\\s+`;
343
+ const star = '(<|>)?=?\\s*\\*';
344
+ const caret = `^${loneCaret}${xRangePlain}$`;
345
+ const mainVersion = `(${numericIdentifier})\\.(${numericIdentifier})\\.(${numericIdentifier})`;
346
+ const fullPlain = `v?${mainVersion}${preRelease}?${build}?`;
347
+ const tilde = `^${loneTilde}${xRangePlain}$`;
348
+ const xRange = `^${gtlt}\\s*${xRangePlain}$`;
349
+ const comparator = `^${gtlt}\\s*(${fullPlain})$|^$`;
350
+ // copy from semver package
351
+ const gte0 = '^\\s*>=\\s*0.0.0\\s*$';
352
+
353
+ // fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
354
+ // Copyright (c)
355
+ // vite-plugin-federation is licensed under Mulan PSL v2.
356
+ // You can use this software according to the terms and conditions of the Mulan PSL v2.
357
+ // You may obtain a copy of Mulan PSL v2 at:
358
+ // http://license.coscl.org.cn/MulanPSL2
359
+ // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
360
+ // See the Mulan PSL v2 for more details.
361
+ function parseRegex(source) {
362
+ return new RegExp(source);
363
+ }
364
+ function isXVersion(version) {
365
+ return !version || version.toLowerCase() === 'x' || version === '*';
366
+ }
367
+ function pipe(...fns) {
368
+ return (x) => fns.reduce((v, f) => f(v), x);
369
+ }
370
+ function extractComparator(comparatorString) {
371
+ return comparatorString.match(parseRegex(comparator));
372
+ }
373
+ function combineVersion(major, minor, patch, preRelease) {
374
+ const mainVersion = `${major}.${minor}.${patch}`;
375
+ if (preRelease) {
376
+ return `${mainVersion}-${preRelease}`;
377
+ }
378
+ return mainVersion;
379
+ }
380
+
381
+ // fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
382
+ // Copyright (c)
383
+ // vite-plugin-federation is licensed under Mulan PSL v2.
384
+ // You can use this software according to the terms and conditions of the Mulan PSL v2.
385
+ // You may obtain a copy of Mulan PSL v2 at:
386
+ // http://license.coscl.org.cn/MulanPSL2
387
+ // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
388
+ // See the Mulan PSL v2 for more details.
389
+ function parseHyphen(range) {
390
+ return range.replace(parseRegex(hyphenRange), (_range, from, fromMajor, fromMinor, fromPatch, _fromPreRelease, _fromBuild, to, toMajor, toMinor, toPatch, toPreRelease) => {
391
+ if (isXVersion(fromMajor)) {
392
+ from = '';
393
+ }
394
+ else if (isXVersion(fromMinor)) {
395
+ from = `>=${fromMajor}.0.0`;
396
+ }
397
+ else if (isXVersion(fromPatch)) {
398
+ from = `>=${fromMajor}.${fromMinor}.0`;
399
+ }
400
+ else {
401
+ from = `>=${from}`;
402
+ }
403
+ if (isXVersion(toMajor)) {
404
+ to = '';
405
+ }
406
+ else if (isXVersion(toMinor)) {
407
+ to = `<${Number(toMajor) + 1}.0.0-0`;
408
+ }
409
+ else if (isXVersion(toPatch)) {
410
+ to = `<${toMajor}.${Number(toMinor) + 1}.0-0`;
411
+ }
412
+ else if (toPreRelease) {
413
+ to = `<=${toMajor}.${toMinor}.${toPatch}-${toPreRelease}`;
414
+ }
415
+ else {
416
+ to = `<=${to}`;
417
+ }
418
+ return `${from} ${to}`.trim();
419
+ });
420
+ }
421
+ function parseComparatorTrim(range) {
422
+ return range.replace(parseRegex(comparatorTrim), '$1$2$3');
423
+ }
424
+ function parseTildeTrim(range) {
425
+ return range.replace(parseRegex(tildeTrim), '$1~');
426
+ }
427
+ function parseCaretTrim(range) {
428
+ return range.replace(parseRegex(caretTrim), '$1^');
429
+ }
430
+ function parseCarets(range) {
431
+ return range
432
+ .trim()
433
+ .split(/\s+/)
434
+ .map((rangeVersion) => rangeVersion.replace(parseRegex(caret), (_, major, minor, patch, preRelease) => {
435
+ if (isXVersion(major)) {
436
+ return '';
437
+ }
438
+ else if (isXVersion(minor)) {
439
+ return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
440
+ }
441
+ else if (isXVersion(patch)) {
442
+ if (major === '0') {
443
+ return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
444
+ }
445
+ else {
446
+ return `>=${major}.${minor}.0 <${Number(major) + 1}.0.0-0`;
447
+ }
448
+ }
449
+ else if (preRelease) {
450
+ if (major === '0') {
451
+ if (minor === '0') {
452
+ return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${minor}.${Number(patch) + 1}-0`;
453
+ }
454
+ else {
455
+ return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${Number(minor) + 1}.0-0`;
456
+ }
457
+ }
458
+ else {
459
+ return `>=${major}.${minor}.${patch}-${preRelease} <${Number(major) + 1}.0.0-0`;
460
+ }
461
+ }
462
+ else {
463
+ if (major === '0') {
464
+ if (minor === '0') {
465
+ return `>=${major}.${minor}.${patch} <${major}.${minor}.${Number(patch) + 1}-0`;
466
+ }
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
+ }))
474
+ .join(' ');
475
+ }
476
+ function parseTildes(range) {
477
+ return range
478
+ .trim()
479
+ .split(/\s+/)
480
+ .map((rangeVersion) => rangeVersion.replace(parseRegex(tilde), (_, major, minor, patch, preRelease) => {
481
+ if (isXVersion(major)) {
482
+ return '';
483
+ }
484
+ else if (isXVersion(minor)) {
485
+ return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
486
+ }
487
+ else if (isXVersion(patch)) {
488
+ return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
489
+ }
490
+ else if (preRelease) {
491
+ return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${Number(minor) + 1}.0-0`;
492
+ }
493
+ return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
494
+ }))
495
+ .join(' ');
496
+ }
497
+ function parseXRanges(range) {
498
+ return range
499
+ .split(/\s+/)
500
+ .map((rangeVersion) => rangeVersion
501
+ .trim()
502
+ .replace(parseRegex(xRange), (ret, gtlt, major, minor, patch, preRelease) => {
503
+ const isXMajor = isXVersion(major);
504
+ const isXMinor = isXMajor || isXVersion(minor);
505
+ const isXPatch = isXMinor || isXVersion(patch);
506
+ if (gtlt === '=' && isXPatch) {
507
+ gtlt = '';
508
+ }
509
+ preRelease = '';
510
+ if (isXMajor) {
511
+ if (gtlt === '>' || gtlt === '<') {
512
+ // nothing is allowed
513
+ return '<0.0.0-0';
514
+ }
515
+ else {
516
+ // nothing is forbidden
517
+ return '*';
518
+ }
519
+ }
520
+ else if (gtlt && isXPatch) {
521
+ // replace X with 0
522
+ if (isXMinor) {
523
+ minor = 0;
524
+ }
525
+ patch = 0;
526
+ if (gtlt === '>') {
527
+ // >1 => >=2.0.0
528
+ // >1.2 => >=1.3.0
529
+ gtlt = '>=';
530
+ if (isXMinor) {
531
+ major = Number(major) + 1;
532
+ minor = 0;
533
+ patch = 0;
534
+ }
535
+ else {
536
+ minor = Number(minor) + 1;
537
+ patch = 0;
538
+ }
539
+ }
540
+ else if (gtlt === '<=') {
541
+ // <=0.7.x is actually <0.8.0, since any 0.7.x should pass
542
+ // Similarly, <=7.x is actually <8.0.0, etc.
543
+ gtlt = '<';
544
+ if (isXMinor) {
545
+ major = Number(major) + 1;
546
+ }
547
+ else {
548
+ minor = Number(minor) + 1;
549
+ }
550
+ }
551
+ if (gtlt === '<') {
552
+ preRelease = '-0';
553
+ }
554
+ return `${gtlt + major}.${minor}.${patch}${preRelease}`;
555
+ }
556
+ else if (isXMinor) {
557
+ return `>=${major}.0.0${preRelease} <${Number(major) + 1}.0.0-0`;
558
+ }
559
+ else if (isXPatch) {
560
+ return `>=${major}.${minor}.0${preRelease} <${major}.${Number(minor) + 1}.0-0`;
561
+ }
562
+ return ret;
563
+ }))
564
+ .join(' ');
565
+ }
566
+ function parseStar(range) {
567
+ return range.trim().replace(parseRegex(star), '');
568
+ }
569
+ function parseGTE0(comparatorString) {
570
+ return comparatorString.trim().replace(parseRegex(gte0), '');
571
+ }
572
+
573
+ // fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
574
+ // Copyright (c)
575
+ // vite-plugin-federation is licensed under Mulan PSL v2.
576
+ // You can use this software according to the terms and conditions of the Mulan PSL v2.
577
+ // You may obtain a copy of Mulan PSL v2 at:
578
+ // http://license.coscl.org.cn/MulanPSL2
579
+ // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
580
+ // See the Mulan PSL v2 for more details.
581
+ function compareAtom(rangeAtom, versionAtom) {
582
+ rangeAtom = Number(rangeAtom) || rangeAtom;
583
+ versionAtom = Number(versionAtom) || versionAtom;
584
+ if (rangeAtom > versionAtom) {
585
+ return 1;
586
+ }
587
+ if (rangeAtom === versionAtom) {
588
+ return 0;
589
+ }
590
+ return -1;
591
+ }
592
+ function comparePreRelease(rangeAtom, versionAtom) {
593
+ const { preRelease: rangePreRelease } = rangeAtom;
594
+ const { preRelease: versionPreRelease } = versionAtom;
595
+ if (rangePreRelease === undefined && Boolean(versionPreRelease)) {
596
+ return 1;
597
+ }
598
+ if (Boolean(rangePreRelease) && versionPreRelease === undefined) {
599
+ return -1;
600
+ }
601
+ if (rangePreRelease === undefined && versionPreRelease === undefined) {
602
+ return 0;
603
+ }
604
+ for (let i = 0, n = rangePreRelease.length; i <= n; i++) {
605
+ const rangeElement = rangePreRelease[i];
606
+ const versionElement = versionPreRelease[i];
607
+ if (rangeElement === versionElement) {
608
+ continue;
609
+ }
610
+ if (rangeElement === undefined && versionElement === undefined) {
611
+ return 0;
612
+ }
613
+ if (!rangeElement) {
614
+ return 1;
615
+ }
616
+ if (!versionElement) {
617
+ return -1;
618
+ }
619
+ return compareAtom(rangeElement, versionElement);
620
+ }
621
+ return 0;
622
+ }
623
+ function compareVersion(rangeAtom, versionAtom) {
624
+ return (compareAtom(rangeAtom.major, versionAtom.major) ||
625
+ compareAtom(rangeAtom.minor, versionAtom.minor) ||
626
+ compareAtom(rangeAtom.patch, versionAtom.patch) ||
627
+ comparePreRelease(rangeAtom, versionAtom));
628
+ }
629
+ function eq(rangeAtom, versionAtom) {
630
+ return rangeAtom.version === versionAtom.version;
631
+ }
632
+ function compare(rangeAtom, versionAtom) {
633
+ switch (rangeAtom.operator) {
634
+ case '':
635
+ case '=':
636
+ return eq(rangeAtom, versionAtom);
637
+ case '>':
638
+ return compareVersion(rangeAtom, versionAtom) < 0;
639
+ case '>=':
640
+ return (eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0);
641
+ case '<':
642
+ return compareVersion(rangeAtom, versionAtom) > 0;
643
+ case '<=':
644
+ return (eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0);
645
+ case undefined: {
646
+ // mean * or x -> all versions
647
+ return true;
648
+ }
649
+ default:
650
+ return false;
651
+ }
652
+ }
653
+
654
+ // fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
655
+ // Copyright (c)
656
+ // vite-plugin-federation is licensed under Mulan PSL v2.
657
+ // You can use this software according to the terms and conditions of the Mulan PSL v2.
658
+ // You may obtain a copy of Mulan PSL v2 at:
659
+ // http://license.coscl.org.cn/MulanPSL2
660
+ // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
661
+ // See the Mulan PSL v2 for more details.
662
+ function parseComparatorString(range) {
663
+ return pipe(
664
+ // handle caret
665
+ // ^ --> * (any, kinda silly)
666
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
667
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
668
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
669
+ // ^1.2.3 --> >=1.2.3 <2.0.0-0
670
+ // ^1.2.0 --> >=1.2.0 <2.0.0-0
671
+ parseCarets,
672
+ // handle tilde
673
+ // ~, ~> --> * (any, kinda silly)
674
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
675
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
676
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
677
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
678
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
679
+ parseTildes, parseXRanges, parseStar)(range);
680
+ }
681
+ function parseRange(range) {
682
+ return pipe(
683
+ // handle hyphenRange
684
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
685
+ parseHyphen,
686
+ // handle trim comparator
687
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
688
+ parseComparatorTrim,
689
+ // handle trim tilde
690
+ // `~ 1.2.3` => `~1.2.3`
691
+ parseTildeTrim,
692
+ // handle trim caret
693
+ // `^ 1.2.3` => `^1.2.3`
694
+ parseCaretTrim)(range.trim())
695
+ .split(/\s+/)
696
+ .join(' ');
697
+ }
698
+ function satisfy(version, range) {
699
+ if (!version) {
700
+ return false;
701
+ }
702
+ // Extract version details once
703
+ const extractedVersion = extractComparator(version);
704
+ if (!extractedVersion) {
705
+ // If the version string is invalid, it can't satisfy any range
706
+ return false;
707
+ }
708
+ const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease,] = extractedVersion;
709
+ const versionAtom = {
710
+ operator: versionOperator,
711
+ version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease), // exclude build atom
712
+ major: versionMajor,
713
+ minor: versionMinor,
714
+ patch: versionPatch,
715
+ preRelease: versionPreRelease?.split('.'),
716
+ };
717
+ // Split the range by || to handle OR conditions
718
+ const orRanges = range.split('||');
719
+ for (const orRange of orRanges) {
720
+ const trimmedOrRange = orRange.trim();
721
+ if (!trimmedOrRange) {
722
+ // An empty range string signifies wildcard *, satisfy any valid version
723
+ // (We already checked if the version itself is valid)
724
+ return true;
725
+ }
726
+ // Handle simple wildcards explicitly before complex parsing
727
+ if (trimmedOrRange === '*' || trimmedOrRange === 'x') {
728
+ return true;
729
+ }
730
+ try {
731
+ // Apply existing parsing logic to the current OR sub-range
732
+ const parsedSubRange = parseRange(trimmedOrRange); // Handles hyphens, trims etc.
733
+ // Check if the result of initial parsing is empty, which can happen
734
+ // for some wildcard cases handled by parseRange/parseComparatorString.
735
+ // E.g. `parseStar` used in `parseComparatorString` returns ''.
736
+ if (!parsedSubRange.trim()) {
737
+ // If parsing results in empty string, treat as wildcard match
738
+ return true;
739
+ }
740
+ const parsedComparatorString = parsedSubRange
741
+ .split(' ')
742
+ .map((rangeVersion) => parseComparatorString(rangeVersion)) // Expands ^, ~
743
+ .join(' ');
744
+ // Check again if the comparator string became empty after specific parsing like ^ or ~
745
+ if (!parsedComparatorString.trim()) {
746
+ return true;
747
+ }
748
+ // Split the sub-range by space for implicit AND conditions
749
+ const comparators = parsedComparatorString
750
+ .split(/\s+/)
751
+ .map((comparator) => parseGTE0(comparator))
752
+ // Filter out empty strings that might result from multiple spaces
753
+ .filter(Boolean);
754
+ // If a sub-range becomes empty after parsing (e.g., invalid characters),
755
+ // it cannot be satisfied. This check might be redundant now but kept for safety.
756
+ if (comparators.length === 0) {
757
+ continue;
758
+ }
759
+ let subRangeSatisfied = true;
760
+ for (const comparator of comparators) {
761
+ const extractedComparator = extractComparator(comparator);
762
+ // If any part of the AND sub-range is invalid, the sub-range is not satisfied
763
+ if (!extractedComparator) {
764
+ subRangeSatisfied = false;
765
+ break;
766
+ }
767
+ const [, rangeOperator, , rangeMajor, rangeMinor, rangePatch, rangePreRelease,] = extractedComparator;
768
+ const rangeAtom = {
769
+ operator: rangeOperator,
770
+ version: combineVersion(rangeMajor, rangeMinor, rangePatch, rangePreRelease),
771
+ major: rangeMajor,
772
+ minor: rangeMinor,
773
+ patch: rangePatch,
774
+ preRelease: rangePreRelease?.split('.'),
775
+ };
776
+ // Check if the version satisfies this specific comparator in the AND chain
777
+ if (!compare(rangeAtom, versionAtom)) {
778
+ subRangeSatisfied = false; // This part of the AND condition failed
779
+ break; // No need to check further comparators in this sub-range
780
+ }
781
+ }
782
+ // If all AND conditions within this OR sub-range were met, the overall range is satisfied
783
+ if (subRangeSatisfied) {
784
+ return true;
785
+ }
786
+ }
787
+ catch (e) {
788
+ // Log error and treat this sub-range as unsatisfied
789
+ console.error(`[semver] Error processing range part "${trimmedOrRange}":`, e);
790
+ continue;
791
+ }
792
+ }
793
+ // If none of the OR sub-ranges were satisfied
794
+ return false;
795
+ }
796
+
797
+ function formatShare(shareArgs, from, name, shareStrategy) {
798
+ let get;
799
+ if ('get' in shareArgs) {
800
+ // eslint-disable-next-line prefer-destructuring
801
+ get = shareArgs.get;
802
+ }
803
+ else if ('lib' in shareArgs) {
804
+ get = () => Promise.resolve(shareArgs.lib);
805
+ }
806
+ else {
807
+ get = () => Promise.resolve(() => {
808
+ throw new Error(`Can not get shared '${name}'!`);
809
+ });
810
+ }
811
+ return {
812
+ deps: [],
813
+ useIn: [],
814
+ from,
815
+ loading: null,
816
+ ...shareArgs,
817
+ shareConfig: {
818
+ requiredVersion: `^${shareArgs.version}`,
819
+ singleton: false,
820
+ eager: false,
821
+ strictVersion: false,
822
+ ...shareArgs.shareConfig,
823
+ },
824
+ get,
825
+ loaded: shareArgs?.loaded || 'lib' in shareArgs ? true : undefined,
826
+ version: shareArgs.version ?? '0',
827
+ scope: Array.isArray(shareArgs.scope)
828
+ ? shareArgs.scope
829
+ : [shareArgs.scope ?? 'default'],
830
+ strategy: (shareArgs.strategy ?? shareStrategy) || 'version-first',
831
+ };
832
+ }
833
+ function formatShareConfigs(globalOptions, userOptions) {
834
+ const shareArgs = userOptions.shared || {};
835
+ const from = userOptions.name;
836
+ const shareInfos = Object.keys(shareArgs).reduce((res, pkgName) => {
837
+ const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
838
+ res[pkgName] = res[pkgName] || [];
839
+ arrayShareArgs.forEach((shareConfig) => {
840
+ res[pkgName].push(formatShare(shareConfig, from, pkgName, userOptions.shareStrategy));
841
+ });
842
+ return res;
843
+ }, {});
844
+ const shared = {
845
+ ...globalOptions.shared,
846
+ };
847
+ Object.keys(shareInfos).forEach((shareKey) => {
848
+ if (!shared[shareKey]) {
849
+ shared[shareKey] = shareInfos[shareKey];
850
+ }
851
+ else {
852
+ shareInfos[shareKey].forEach((newUserSharedOptions) => {
853
+ const isSameVersion = shared[shareKey].find((sharedVal) => sharedVal.version === newUserSharedOptions.version);
854
+ if (!isSameVersion) {
855
+ shared[shareKey].push(newUserSharedOptions);
856
+ }
857
+ });
858
+ }
859
+ });
860
+ return { shared, shareInfos };
861
+ }
862
+ function versionLt(a, b) {
863
+ const transformInvalidVersion = (version) => {
864
+ const isNumberVersion = !Number.isNaN(Number(version));
865
+ if (isNumberVersion) {
866
+ const splitArr = version.split('.');
867
+ let validVersion = version;
868
+ for (let i = 0; i < 3 - splitArr.length; i++) {
869
+ validVersion += '.0';
870
+ }
871
+ return validVersion;
872
+ }
873
+ return version;
874
+ };
875
+ if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
876
+ return true;
877
+ }
878
+ else {
879
+ return false;
880
+ }
881
+ }
882
+ const findVersion = (shareVersionMap, cb) => {
883
+ const callback = cb ||
884
+ function (prev, cur) {
885
+ return versionLt(prev, cur);
886
+ };
887
+ return Object.keys(shareVersionMap).reduce((prev, cur) => {
888
+ if (!prev) {
889
+ return cur;
890
+ }
891
+ if (callback(prev, cur)) {
892
+ return cur;
893
+ }
894
+ // default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
895
+ if (prev === '0') {
896
+ return cur;
897
+ }
898
+ return prev;
899
+ }, 0);
900
+ };
901
+ const isLoaded = (shared) => {
902
+ return Boolean(shared.loaded) || typeof shared.lib === 'function';
903
+ };
904
+ const isLoading = (shared) => {
905
+ return Boolean(shared.loading);
906
+ };
907
+ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
908
+ const versions = shareScopeMap[scope][pkgName];
909
+ const callback = function (prev, cur) {
910
+ return !isLoaded(versions[prev]) && versionLt(prev, cur);
911
+ };
912
+ return findVersion(shareScopeMap[scope][pkgName], callback);
913
+ }
914
+ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
915
+ const versions = shareScopeMap[scope][pkgName];
916
+ const callback = function (prev, cur) {
917
+ const isLoadingOrLoaded = (shared) => {
918
+ return isLoaded(shared) || isLoading(shared);
919
+ };
920
+ if (isLoadingOrLoaded(versions[cur])) {
921
+ if (isLoadingOrLoaded(versions[prev])) {
922
+ return Boolean(versionLt(prev, cur));
923
+ }
924
+ else {
925
+ return true;
926
+ }
927
+ }
928
+ if (isLoadingOrLoaded(versions[prev])) {
929
+ return false;
930
+ }
931
+ return versionLt(prev, cur);
932
+ };
933
+ return findVersion(shareScopeMap[scope][pkgName], callback);
934
+ }
935
+ function getFindShareFunction(strategy) {
936
+ if (strategy === 'loaded-first') {
937
+ return findSingletonVersionOrderByLoaded;
938
+ }
939
+ return findSingletonVersionOrderByVersion;
940
+ }
941
+ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
942
+ if (!localShareScopeMap) {
943
+ return;
944
+ }
945
+ const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
946
+ const scopes = Array.isArray(scope) ? scope : [scope];
947
+ for (const sc of scopes) {
948
+ if (shareConfig &&
949
+ localShareScopeMap[sc] &&
950
+ localShareScopeMap[sc][pkgName]) {
951
+ const { requiredVersion } = shareConfig;
952
+ const findShareFunction = getFindShareFunction(strategy);
953
+ const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
954
+ //@ts-ignore
955
+ const defaultResolver = () => {
956
+ if (shareConfig.singleton) {
957
+ if (typeof requiredVersion === 'string' &&
958
+ !satisfy(maxOrSingletonVersion, requiredVersion)) {
959
+ const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion &&
960
+ localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
961
+ if (shareConfig.strictVersion) {
962
+ error(msg);
963
+ }
964
+ else {
965
+ warn(msg);
966
+ }
967
+ }
968
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
969
+ }
970
+ else {
971
+ if (requiredVersion === false || requiredVersion === '*') {
972
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
973
+ }
974
+ if (satisfy(maxOrSingletonVersion, requiredVersion)) {
975
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
976
+ }
977
+ for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])) {
978
+ if (satisfy(versionKey, requiredVersion)) {
979
+ return versionValue;
980
+ }
981
+ }
982
+ }
983
+ };
984
+ const params = {
985
+ shareScopeMap: localShareScopeMap,
986
+ scope: sc,
987
+ pkgName,
988
+ version: maxOrSingletonVersion,
989
+ GlobalFederation: Global.__FEDERATION__,
990
+ resolver: defaultResolver,
991
+ };
992
+ const resolveShared = resolveShare.emit(params) || params;
993
+ return resolveShared.resolver();
994
+ }
995
+ }
996
+ }
997
+ function getGlobalShareScope() {
998
+ return Global.__FEDERATION__.__SHARE__;
999
+ }
1000
+ function getTargetSharedOptions(options) {
1001
+ const { pkgName, extraOptions, shareInfos } = options;
1002
+ const defaultResolver = (sharedOptions) => {
1003
+ if (!sharedOptions) {
1004
+ return undefined;
1005
+ }
1006
+ const shareVersionMap = {};
1007
+ sharedOptions.forEach((shared) => {
1008
+ shareVersionMap[shared.version] = shared;
1009
+ });
1010
+ const callback = function (prev, cur) {
1011
+ return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
1012
+ };
1013
+ const maxVersion = findVersion(shareVersionMap, callback);
1014
+ return shareVersionMap[maxVersion];
1015
+ };
1016
+ const resolver = extraOptions?.resolver ?? defaultResolver;
1017
+ return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions?.customShareInfo);
1018
+ }
1019
+
1020
+ function getBuilderId() {
1021
+ //@ts-ignore
1022
+ return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined'
1023
+ ? //@ts-ignore
1024
+ FEDERATION_BUILD_IDENTIFIER
1025
+ : '';
1026
+ }
1027
+
1028
+ // Function to match a remote with its name and expose
1029
+ // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
1030
+ // id: alias(app1) + expose(button) = app1/button
1031
+ // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
1032
+ function matchRemoteWithNameAndExpose(remotes, id) {
1033
+ for (const remote of remotes) {
1034
+ // match pkgName
1035
+ const isNameMatched = id.startsWith(remote.name);
1036
+ let expose = id.replace(remote.name, '');
1037
+ if (isNameMatched) {
1038
+ if (expose.startsWith('/')) {
1039
+ const pkgNameOrAlias = remote.name;
1040
+ expose = `.${expose}`;
1041
+ return {
1042
+ pkgNameOrAlias,
1043
+ expose,
1044
+ remote,
1045
+ };
1046
+ }
1047
+ else if (expose === '') {
1048
+ return {
1049
+ pkgNameOrAlias: remote.name,
1050
+ expose: '.',
1051
+ remote,
1052
+ };
1053
+ }
1054
+ }
1055
+ // match alias
1056
+ const isAliasMatched = remote.alias && id.startsWith(remote.alias);
1057
+ let exposeWithAlias = remote.alias && id.replace(remote.alias, '');
1058
+ if (remote.alias && isAliasMatched) {
1059
+ if (exposeWithAlias && exposeWithAlias.startsWith('/')) {
1060
+ const pkgNameOrAlias = remote.alias;
1061
+ exposeWithAlias = `.${exposeWithAlias}`;
1062
+ return {
1063
+ pkgNameOrAlias,
1064
+ expose: exposeWithAlias,
1065
+ remote,
1066
+ };
1067
+ }
1068
+ else if (exposeWithAlias === '') {
1069
+ return {
1070
+ pkgNameOrAlias: remote.alias,
1071
+ expose: '.',
1072
+ remote,
1073
+ };
1074
+ }
1075
+ }
1076
+ }
1077
+ return;
1078
+ }
1079
+ // Function to match a remote with its name or alias
1080
+ function matchRemote(remotes, nameOrAlias) {
1081
+ for (const remote of remotes) {
1082
+ const isNameMatched = nameOrAlias === remote.name;
1083
+ if (isNameMatched) {
1084
+ return remote;
1085
+ }
1086
+ const isAliasMatched = remote.alias && nameOrAlias === remote.alias;
1087
+ if (isAliasMatched) {
1088
+ return remote;
1089
+ }
1090
+ }
1091
+ return;
1092
+ }
1093
+
1094
+ function registerPlugins(plugins, instance) {
1095
+ const globalPlugins = getGlobalHostPlugins();
1096
+ const hookInstances = [
1097
+ instance.hooks,
1098
+ instance.remoteHandler.hooks,
1099
+ instance.sharedHandler.hooks,
1100
+ instance.snapshotHandler.hooks,
1101
+ instance.loaderHook,
1102
+ instance.bridgeHook,
1103
+ ];
1104
+ // Incorporate global plugins
1105
+ if (globalPlugins.length > 0) {
1106
+ globalPlugins.forEach((plugin) => {
1107
+ if (plugins?.find((item) => item.name !== plugin.name)) {
1108
+ plugins.push(plugin);
1109
+ }
1110
+ });
1111
+ }
1112
+ if (plugins && plugins.length > 0) {
1113
+ plugins.forEach((plugin) => {
1114
+ hookInstances.forEach((hookInstance) => {
1115
+ hookInstance.applyPlugin(plugin, instance);
1116
+ });
1117
+ });
1118
+ }
1119
+ return plugins;
1120
+ }
1121
+
1122
+ const importCallback = '.then(callbacks[0]).catch(callbacks[1])';
1123
+ async function loadEsmEntry({ entry, remoteEntryExports, }) {
1124
+ return new Promise((resolve, reject) => {
1125
+ try {
1126
+ if (!remoteEntryExports) {
1127
+ if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {
1128
+ new Function('callbacks', `import("${entry}")${importCallback}`)([
1129
+ resolve,
1130
+ reject,
1131
+ ]);
1132
+ }
1133
+ else {
1134
+ import(/* webpackIgnore: true */ /* @vite-ignore */ entry)
1135
+ .then(resolve)
1136
+ .catch(reject);
1137
+ }
1138
+ }
1139
+ else {
1140
+ resolve(remoteEntryExports);
1141
+ }
1142
+ }
1143
+ catch (e) {
1144
+ reject(e);
1145
+ }
1146
+ });
1147
+ }
1148
+ async function loadSystemJsEntry({ entry, remoteEntryExports, }) {
1149
+ return new Promise((resolve, reject) => {
1150
+ try {
1151
+ if (!remoteEntryExports) {
1152
+ //@ts-ignore
1153
+ if (typeof __system_context__ === 'undefined') {
1154
+ //@ts-ignore
1155
+ System.import(entry).then(resolve).catch(reject);
1156
+ }
1157
+ else {
1158
+ new Function('callbacks', `System.import("${entry}")${importCallback}`)([resolve, reject]);
1159
+ }
1160
+ }
1161
+ else {
1162
+ resolve(remoteEntryExports);
1163
+ }
1164
+ }
1165
+ catch (e) {
1166
+ reject(e);
1167
+ }
1168
+ });
1169
+ }
1170
+ function handleRemoteEntryLoaded(name, globalName, entry) {
1171
+ const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
1172
+ assert(entryExports, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_001, errorCodes.runtimeDescMap, {
1173
+ remoteName: name,
1174
+ remoteEntryUrl: entry,
1175
+ remoteEntryKey,
1176
+ }));
1177
+ return entryExports;
1178
+ }
1179
+ async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl, }) {
1180
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
1181
+ if (remoteEntryExports) {
1182
+ return remoteEntryExports;
1183
+ }
1184
+ // if getEntryUrl is passed, use the getEntryUrl to get the entry url
1185
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
1186
+ return sdk.loadScript(url, {
1187
+ attrs: {},
1188
+ createScriptHook: (url, attrs) => {
1189
+ const res = loaderHook.lifecycle.createScript.emit({ url, attrs });
1190
+ if (!res)
1191
+ return;
1192
+ if (res instanceof HTMLScriptElement) {
1193
+ return res;
1194
+ }
1195
+ if ('script' in res || 'timeout' in res) {
1196
+ return res;
1197
+ }
1198
+ return;
1199
+ },
1200
+ })
1201
+ .then(() => {
1202
+ return handleRemoteEntryLoaded(name, globalName, entry);
1203
+ })
1204
+ .catch((e) => {
1205
+ assert(undefined, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_008, errorCodes.runtimeDescMap, {
1206
+ remoteName: name,
1207
+ resourceUrl: entry,
1208
+ }));
1209
+ throw e;
1210
+ });
1211
+ }
1212
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, }) {
1213
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
1214
+ switch (type) {
1215
+ case 'esm':
1216
+ case 'module':
1217
+ return loadEsmEntry({ entry, remoteEntryExports });
1218
+ case 'system':
1219
+ return loadSystemJsEntry({ entry, remoteEntryExports });
1220
+ default:
1221
+ return loadEntryScript({
1222
+ entry,
1223
+ globalName,
1224
+ name,
1225
+ loaderHook,
1226
+ getEntryUrl,
1227
+ });
1228
+ }
1229
+ }
1230
+ async function loadEntryNode({ remoteInfo, loaderHook, }) {
1231
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
1232
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
1233
+ if (remoteEntryExports) {
1234
+ return remoteEntryExports;
1235
+ }
1236
+ return sdk.loadScriptNode(entry, {
1237
+ attrs: { name, globalName, type },
1238
+ loaderHook: {
1239
+ createScriptHook: (url, attrs = {}) => {
1240
+ const res = loaderHook.lifecycle.createScript.emit({ url, attrs });
1241
+ if (!res)
1242
+ return;
1243
+ if ('url' in res) {
1244
+ return res;
1245
+ }
1246
+ return;
1247
+ },
1248
+ },
1249
+ })
1250
+ .then(() => {
1251
+ return handleRemoteEntryLoaded(name, globalName, entry);
1252
+ })
1253
+ .catch((e) => {
1254
+ throw e;
1255
+ });
1256
+ }
1257
+ function getRemoteEntryUniqueKey(remoteInfo) {
1258
+ const { entry, name } = remoteInfo;
1259
+ return sdk.composeKeyWithSeparator(name, entry);
1260
+ }
1261
+ async function getRemoteEntry(params) {
1262
+ const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false, } = params;
1263
+ const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
1264
+ if (remoteEntryExports) {
1265
+ return remoteEntryExports;
1266
+ }
1267
+ if (!globalLoading[uniqueKey]) {
1268
+ const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
1269
+ const loaderHook = origin.loaderHook;
1270
+ globalLoading[uniqueKey] = loadEntryHook
1271
+ .emit({
1272
+ loaderHook,
1273
+ remoteInfo,
1274
+ remoteEntryExports,
1275
+ })
1276
+ .then((res) => {
1277
+ if (res) {
1278
+ return res;
1279
+ }
1280
+ // Use ENV_TARGET if defined, otherwise fallback to isBrowserEnv, must keep this
1281
+ const isWebEnvironment = typeof ENV_TARGET !== 'undefined'
1282
+ ? ENV_TARGET === 'web'
1283
+ : sdk.isBrowserEnv();
1284
+ return isWebEnvironment
1285
+ ? loadEntryDom({
1286
+ remoteInfo,
1287
+ remoteEntryExports,
1288
+ loaderHook,
1289
+ getEntryUrl,
1290
+ })
1291
+ : loadEntryNode({ remoteInfo, loaderHook });
1292
+ })
1293
+ .catch(async (err) => {
1294
+ const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
1295
+ const isScriptLoadError = err instanceof Error && err.message.includes(errorCodes.RUNTIME_008);
1296
+ if (isScriptLoadError && !_inErrorHandling) {
1297
+ const wrappedGetRemoteEntry = (params) => {
1298
+ return getRemoteEntry({ ...params, _inErrorHandling: true });
1299
+ };
1300
+ const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
1301
+ getRemoteEntry: wrappedGetRemoteEntry,
1302
+ origin,
1303
+ remoteInfo: remoteInfo,
1304
+ remoteEntryExports,
1305
+ globalLoading,
1306
+ uniqueKey,
1307
+ });
1308
+ if (RemoteEntryExports) {
1309
+ return RemoteEntryExports;
1310
+ }
1311
+ }
1312
+ throw err;
1313
+ });
1314
+ }
1315
+ return globalLoading[uniqueKey];
1316
+ }
1317
+ function getRemoteInfo(remote) {
1318
+ return {
1319
+ ...remote,
1320
+ entry: 'entry' in remote ? remote.entry : '',
1321
+ type: remote.type || DEFAULT_REMOTE_TYPE,
1322
+ entryGlobalName: remote.entryGlobalName || remote.name,
1323
+ shareScope: remote.shareScope || DEFAULT_SCOPE,
1324
+ };
1325
+ }
1326
+
1327
+ function defaultPreloadArgs(preloadConfig) {
1328
+ return {
1329
+ resourceCategory: 'sync',
1330
+ share: true,
1331
+ depsRemote: true,
1332
+ prefetchInterface: false,
1333
+ ...preloadConfig,
1334
+ };
1335
+ }
1336
+ function formatPreloadArgs(remotes, preloadArgs) {
1337
+ return preloadArgs.map((args) => {
1338
+ const remoteInfo = matchRemote(remotes, args.nameOrAlias);
1339
+ assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo &&
1340
+ sdk.safeToString({
1341
+ remoteInfo,
1342
+ remotes,
1343
+ })}`);
1344
+ return {
1345
+ remote: remoteInfo,
1346
+ preloadConfig: defaultPreloadArgs(args),
1347
+ };
1348
+ });
1349
+ }
1350
+ function normalizePreloadExposes(exposes) {
1351
+ if (!exposes) {
1352
+ return [];
1353
+ }
1354
+ return exposes.map((expose) => {
1355
+ if (expose === '.') {
1356
+ return expose;
1357
+ }
1358
+ if (expose.startsWith('./')) {
1359
+ return expose.replace('./', '');
1360
+ }
1361
+ return expose;
1362
+ });
1363
+ }
1364
+ function preloadAssets(remoteInfo, host, assets,
1365
+ // It is used to distinguish preload from load remote parallel loading
1366
+ useLinkPreload = true) {
1367
+ const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
1368
+ if (host.options.inBrowser) {
1369
+ entryAssets.forEach((asset) => {
1370
+ const { moduleInfo } = asset;
1371
+ const module = host.moduleCache.get(remoteInfo.name);
1372
+ if (module) {
1373
+ getRemoteEntry({
1374
+ origin: host,
1375
+ remoteInfo: moduleInfo,
1376
+ remoteEntryExports: module.remoteEntryExports,
1377
+ });
1378
+ }
1379
+ else {
1380
+ getRemoteEntry({
1381
+ origin: host,
1382
+ remoteInfo: moduleInfo,
1383
+ remoteEntryExports: undefined,
1384
+ });
1385
+ }
1386
+ });
1387
+ if (useLinkPreload) {
1388
+ const defaultAttrs = {
1389
+ rel: 'preload',
1390
+ as: 'style',
1391
+ };
1392
+ cssAssets.forEach((cssUrl) => {
1393
+ const { link: cssEl, needAttach } = sdk.createLink({
1394
+ url: cssUrl,
1395
+ cb: () => {
1396
+ // noop
1397
+ },
1398
+ attrs: defaultAttrs,
1399
+ createLinkHook: (url, attrs) => {
1400
+ const res = host.loaderHook.lifecycle.createLink.emit({
1401
+ url,
1402
+ attrs,
1403
+ });
1404
+ if (res instanceof HTMLLinkElement) {
1405
+ return res;
1406
+ }
1407
+ return;
1408
+ },
1409
+ });
1410
+ needAttach && document.head.appendChild(cssEl);
1411
+ });
1412
+ }
1413
+ else {
1414
+ const defaultAttrs = {
1415
+ rel: 'stylesheet',
1416
+ type: 'text/css',
1417
+ };
1418
+ cssAssets.forEach((cssUrl) => {
1419
+ const { link: cssEl, needAttach } = sdk.createLink({
1420
+ url: cssUrl,
1421
+ cb: () => {
1422
+ // noop
1423
+ },
1424
+ attrs: defaultAttrs,
1425
+ createLinkHook: (url, attrs) => {
1426
+ const res = host.loaderHook.lifecycle.createLink.emit({
1427
+ url,
1428
+ attrs,
1429
+ });
1430
+ if (res instanceof HTMLLinkElement) {
1431
+ return res;
1432
+ }
1433
+ return;
1434
+ },
1435
+ needDeleteLink: false,
1436
+ });
1437
+ needAttach && document.head.appendChild(cssEl);
1438
+ });
1439
+ }
1440
+ if (useLinkPreload) {
1441
+ const defaultAttrs = {
1442
+ rel: 'preload',
1443
+ as: 'script',
1444
+ };
1445
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
1446
+ const { link: linkEl, needAttach } = sdk.createLink({
1447
+ url: jsUrl,
1448
+ cb: () => {
1449
+ // noop
1450
+ },
1451
+ attrs: defaultAttrs,
1452
+ createLinkHook: (url, attrs) => {
1453
+ const res = host.loaderHook.lifecycle.createLink.emit({
1454
+ url,
1455
+ attrs,
1456
+ });
1457
+ if (res instanceof HTMLLinkElement) {
1458
+ return res;
1459
+ }
1460
+ return;
1461
+ },
1462
+ });
1463
+ needAttach && document.head.appendChild(linkEl);
1464
+ });
1465
+ }
1466
+ else {
1467
+ const defaultAttrs = {
1468
+ fetchpriority: 'high',
1469
+ type: remoteInfo?.type === 'module' ? 'module' : 'text/javascript',
1470
+ };
1471
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
1472
+ const { script: scriptEl, needAttach } = sdk.createScript({
1473
+ url: jsUrl,
1474
+ cb: () => {
1475
+ // noop
1476
+ },
1477
+ attrs: defaultAttrs,
1478
+ createScriptHook: (url, attrs) => {
1479
+ const res = host.loaderHook.lifecycle.createScript.emit({
1480
+ url,
1481
+ attrs,
1482
+ });
1483
+ if (res instanceof HTMLScriptElement) {
1484
+ return res;
1485
+ }
1486
+ return;
1487
+ },
1488
+ needDeleteScript: true,
1489
+ });
1490
+ needAttach && document.head.appendChild(scriptEl);
1491
+ });
1492
+ }
1493
+ }
1494
+ }
1495
+
1496
+ const ShareUtils = {
1497
+ getRegisteredShare,
1498
+ getGlobalShareScope,
1499
+ };
1500
+ const GlobalUtils = {
1501
+ Global,
1502
+ nativeGlobal,
1503
+ resetFederationGlobalInfo,
1504
+ setGlobalFederationInstance,
1505
+ getGlobalFederationConstructor,
1506
+ setGlobalFederationConstructor,
1507
+ getInfoWithoutType,
1508
+ getGlobalSnapshot,
1509
+ getTargetSnapshotInfoByModuleInfo,
1510
+ getGlobalSnapshotInfoByModuleInfo,
1511
+ setGlobalSnapshotInfoByModuleInfo,
1512
+ addGlobalSnapshot,
1513
+ getRemoteEntryExports,
1514
+ registerGlobalPlugins,
1515
+ getGlobalHostPlugins,
1516
+ getPreloaded,
1517
+ setPreloaded,
1518
+ };
1519
+ var helpers = {
1520
+ global: GlobalUtils,
1521
+ share: ShareUtils,
1522
+ utils: {
1523
+ matchRemoteWithNameAndExpose,
1524
+ preloadAssets,
1525
+ getRemoteInfo,
1526
+ },
1527
+ };
1528
+
1529
+ class Module {
1530
+ constructor({ remoteInfo, host, }) {
1531
+ this.inited = false;
1532
+ this.lib = undefined;
1533
+ this.remoteInfo = remoteInfo;
1534
+ this.host = host;
1535
+ }
1536
+ async getEntry() {
1537
+ if (this.remoteEntryExports) {
1538
+ return this.remoteEntryExports;
1539
+ }
1540
+ let remoteEntryExports;
1541
+ remoteEntryExports = await getRemoteEntry({
1542
+ origin: this.host,
1543
+ remoteInfo: this.remoteInfo,
1544
+ remoteEntryExports: this.remoteEntryExports,
1545
+ });
1546
+ assert(remoteEntryExports, `remoteEntryExports is undefined \n ${sdk.safeToString(this.remoteInfo)}`);
1547
+ this.remoteEntryExports = remoteEntryExports;
1548
+ return this.remoteEntryExports;
1549
+ }
1550
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1551
+ async get(id, expose, options, remoteSnapshot) {
1552
+ const { loadFactory = true } = options || { loadFactory: true };
1553
+ // Get remoteEntry.js
1554
+ const remoteEntryExports = await this.getEntry();
1555
+ if (!this.inited) {
1556
+ const localShareScopeMap = this.host.shareScopeMap;
1557
+ const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope)
1558
+ ? this.remoteInfo.shareScope
1559
+ : [this.remoteInfo.shareScope];
1560
+ if (!shareScopeKeys.length) {
1561
+ shareScopeKeys.push('default');
1562
+ }
1563
+ shareScopeKeys.forEach((shareScopeKey) => {
1564
+ if (!localShareScopeMap[shareScopeKey]) {
1565
+ localShareScopeMap[shareScopeKey] = {};
1566
+ }
1567
+ });
1568
+ // TODO: compate legacy init params, should use shareScopeMap if exist
1569
+ const shareScope = localShareScopeMap[shareScopeKeys[0]];
1570
+ const initScope = [];
1571
+ const remoteEntryInitOptions = {
1572
+ version: this.remoteInfo.version || '',
1573
+ shareScopeKeys: Array.isArray(this.remoteInfo.shareScope)
1574
+ ? shareScopeKeys
1575
+ : this.remoteInfo.shareScope || 'default',
1576
+ };
1577
+ // Help to find host instance
1578
+ Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
1579
+ value: localShareScopeMap,
1580
+ // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
1581
+ enumerable: false,
1582
+ });
1583
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
1584
+ shareScope,
1585
+ // @ts-ignore shareScopeMap will be set by Object.defineProperty
1586
+ remoteEntryInitOptions,
1587
+ initScope,
1588
+ remoteInfo: this.remoteInfo,
1589
+ origin: this.host,
1590
+ });
1591
+ if (typeof remoteEntryExports?.init === 'undefined') {
1592
+ error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_002, errorCodes.runtimeDescMap, {
1593
+ hostName: this.host.name,
1594
+ remoteName: this.remoteInfo.name,
1595
+ remoteEntryUrl: this.remoteInfo.entry,
1596
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
1597
+ }));
1598
+ }
1599
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
1600
+ await this.host.hooks.lifecycle.initContainer.emit({
1601
+ ...initContainerOptions,
1602
+ id,
1603
+ remoteSnapshot,
1604
+ remoteEntryExports,
1605
+ });
1606
+ }
1607
+ this.lib = remoteEntryExports;
1608
+ this.inited = true;
1609
+ let moduleFactory;
1610
+ moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
1611
+ remoteEntryExports,
1612
+ expose,
1613
+ moduleInfo: this.remoteInfo,
1614
+ });
1615
+ // get exposeGetter
1616
+ if (!moduleFactory) {
1617
+ moduleFactory = await remoteEntryExports.get(expose);
1618
+ }
1619
+ assert(moduleFactory, `${getFMId(this.remoteInfo)} remote don't export ${expose}.`);
1620
+ // keep symbol for module name always one format
1621
+ const symbolName = processModuleAlias(this.remoteInfo.name, expose);
1622
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
1623
+ if (!loadFactory) {
1624
+ return wrapModuleFactory;
1625
+ }
1626
+ const exposeContent = await wrapModuleFactory();
1627
+ return exposeContent;
1628
+ }
1629
+ wraperFactory(moduleFactory, id) {
1630
+ function defineModuleId(res, id) {
1631
+ if (res &&
1632
+ typeof res === 'object' &&
1633
+ Object.isExtensible(res) &&
1634
+ !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
1635
+ Object.defineProperty(res, Symbol.for('mf_module_id'), {
1636
+ value: id,
1637
+ enumerable: false,
1638
+ });
1639
+ }
1640
+ }
1641
+ if (moduleFactory instanceof Promise) {
1642
+ return async () => {
1643
+ const res = await moduleFactory();
1644
+ // This parameter is used for bridge debugging
1645
+ defineModuleId(res, id);
1646
+ return res;
1647
+ };
1648
+ }
1649
+ else {
1650
+ return () => {
1651
+ const res = moduleFactory();
1652
+ // This parameter is used for bridge debugging
1653
+ defineModuleId(res, id);
1654
+ return res;
1655
+ };
1656
+ }
1657
+ }
1658
+ }
1659
+
1660
+ class SyncHook {
1661
+ constructor(type) {
1662
+ this.type = '';
1663
+ this.listeners = new Set();
1664
+ if (type) {
1665
+ this.type = type;
1666
+ }
1667
+ }
1668
+ on(fn) {
1669
+ if (typeof fn === 'function') {
1670
+ this.listeners.add(fn);
1671
+ }
1672
+ }
1673
+ once(fn) {
1674
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1675
+ const self = this;
1676
+ this.on(function wrapper(...args) {
1677
+ self.remove(wrapper);
1678
+ // eslint-disable-next-line prefer-spread
1679
+ return fn.apply(null, args);
1680
+ });
1681
+ }
1682
+ emit(...data) {
1683
+ let result;
1684
+ if (this.listeners.size > 0) {
1685
+ // eslint-disable-next-line prefer-spread
1686
+ this.listeners.forEach((fn) => {
1687
+ result = fn(...data);
1688
+ });
1689
+ }
1690
+ return result;
1691
+ }
1692
+ remove(fn) {
1693
+ this.listeners.delete(fn);
1694
+ }
1695
+ removeAll() {
1696
+ this.listeners.clear();
1697
+ }
1698
+ }
1699
+
1700
+ class AsyncHook extends SyncHook {
1701
+ emit(...data) {
1702
+ let result;
1703
+ const ls = Array.from(this.listeners);
1704
+ if (ls.length > 0) {
1705
+ let i = 0;
1706
+ const call = (prev) => {
1707
+ if (prev === false) {
1708
+ return false; // Abort process
1709
+ }
1710
+ else if (i < ls.length) {
1711
+ return Promise.resolve(ls[i++].apply(null, data)).then(call);
1712
+ }
1713
+ else {
1714
+ return prev;
1715
+ }
1716
+ };
1717
+ result = call();
1718
+ }
1719
+ return Promise.resolve(result);
1720
+ }
1721
+ }
1722
+
1723
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1724
+ function checkReturnData(originalData, returnedData) {
1725
+ if (!isObject(returnedData)) {
1726
+ return false;
1727
+ }
1728
+ if (originalData !== returnedData) {
1729
+ // eslint-disable-next-line no-restricted-syntax
1730
+ for (const key in originalData) {
1731
+ if (!(key in returnedData)) {
1732
+ return false;
1733
+ }
1734
+ }
1735
+ }
1736
+ return true;
1737
+ }
1738
+ class SyncWaterfallHook extends SyncHook {
1739
+ constructor(type) {
1740
+ super();
1741
+ this.onerror = error;
1742
+ this.type = type;
1743
+ }
1744
+ emit(data) {
1745
+ if (!isObject(data)) {
1746
+ error(`The data for the "${this.type}" hook should be an object.`);
1747
+ }
1748
+ for (const fn of this.listeners) {
1749
+ try {
1750
+ const tempData = fn(data);
1751
+ if (checkReturnData(data, tempData)) {
1752
+ data = tempData;
1753
+ }
1754
+ else {
1755
+ this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
1756
+ break;
1757
+ }
1758
+ }
1759
+ catch (e) {
1760
+ warn(e);
1761
+ this.onerror(e);
1762
+ }
1763
+ }
1764
+ return data;
1765
+ }
1766
+ }
1767
+
1768
+ class AsyncWaterfallHook extends SyncHook {
1769
+ constructor(type) {
1770
+ super();
1771
+ this.onerror = error;
1772
+ this.type = type;
1773
+ }
1774
+ emit(data) {
1775
+ if (!isObject(data)) {
1776
+ error(`The response data for the "${this.type}" hook must be an object.`);
1777
+ }
1778
+ const ls = Array.from(this.listeners);
1779
+ if (ls.length > 0) {
1780
+ let i = 0;
1781
+ const processError = (e) => {
1782
+ warn(e);
1783
+ this.onerror(e);
1784
+ return data;
1785
+ };
1786
+ const call = (prevData) => {
1787
+ if (checkReturnData(data, prevData)) {
1788
+ data = prevData;
1789
+ if (i < ls.length) {
1790
+ try {
1791
+ return Promise.resolve(ls[i++](data)).then(call, processError);
1792
+ }
1793
+ catch (e) {
1794
+ return processError(e);
1795
+ }
1796
+ }
1797
+ }
1798
+ else {
1799
+ this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
1800
+ }
1801
+ return data;
1802
+ };
1803
+ return Promise.resolve(call(data));
1804
+ }
1805
+ return Promise.resolve(data);
1806
+ }
1807
+ }
1808
+
1809
+ class PluginSystem {
1810
+ constructor(lifecycle) {
1811
+ this.registerPlugins = {};
1812
+ this.lifecycle = lifecycle;
1813
+ this.lifecycleKeys = Object.keys(lifecycle);
1814
+ }
1815
+ applyPlugin(plugin, instance) {
1816
+ assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
1817
+ // The plugin's name is mandatory and must be unique
1818
+ const pluginName = plugin.name;
1819
+ assert(pluginName, 'A name must be provided by the plugin.');
1820
+ if (!this.registerPlugins[pluginName]) {
1821
+ this.registerPlugins[pluginName] = plugin;
1822
+ plugin.apply?.(instance);
1823
+ Object.keys(this.lifecycle).forEach((key) => {
1824
+ const pluginLife = plugin[key];
1825
+ if (pluginLife) {
1826
+ this.lifecycle[key].on(pluginLife);
1827
+ }
1828
+ });
1829
+ }
1830
+ }
1831
+ removePlugin(pluginName) {
1832
+ assert(pluginName, 'A name is required.');
1833
+ const plugin = this.registerPlugins[pluginName];
1834
+ assert(plugin, `The plugin "${pluginName}" is not registered.`);
1835
+ Object.keys(plugin).forEach((key) => {
1836
+ if (key !== 'name') {
1837
+ this.lifecycle[key].remove(plugin[key]);
1838
+ }
1839
+ });
1840
+ }
1841
+ }
1842
+
1843
+ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
1844
+ const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
1845
+ if (!remoteEntryInfo.url) {
1846
+ error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
1847
+ }
1848
+ let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
1849
+ if (!sdk.isBrowserEnv() && !entryUrl.startsWith('http')) {
1850
+ entryUrl = `https:${entryUrl}`;
1851
+ }
1852
+ remoteInfo.type = remoteEntryInfo.type;
1853
+ remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
1854
+ remoteInfo.entry = entryUrl;
1855
+ remoteInfo.version = remoteSnapshot.version;
1856
+ remoteInfo.buildVersion = remoteSnapshot.buildVersion;
1857
+ }
1858
+ function snapshotPlugin() {
1859
+ return {
1860
+ name: 'snapshot-plugin',
1861
+ async afterResolve(args) {
1862
+ const { remote, pkgNameOrAlias, expose, origin, remoteInfo, id } = args;
1863
+ if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
1864
+ const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo({
1865
+ moduleInfo: remote,
1866
+ id,
1867
+ });
1868
+ assignRemoteInfo(remoteInfo, remoteSnapshot);
1869
+ // preloading assets
1870
+ const preloadOptions = {
1871
+ remote,
1872
+ preloadConfig: {
1873
+ nameOrAlias: pkgNameOrAlias,
1874
+ exposes: [expose],
1875
+ resourceCategory: 'sync',
1876
+ share: false,
1877
+ depsRemote: false,
1878
+ },
1879
+ };
1880
+ const assets = await origin.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
1881
+ origin,
1882
+ preloadOptions,
1883
+ remoteInfo,
1884
+ remote,
1885
+ remoteSnapshot,
1886
+ globalSnapshot,
1887
+ });
1888
+ if (assets) {
1889
+ preloadAssets(remoteInfo, origin, assets, false);
1890
+ }
1891
+ return {
1892
+ ...args,
1893
+ remoteSnapshot,
1894
+ };
1895
+ }
1896
+ return args;
1897
+ },
1898
+ };
1899
+ }
1900
+
1901
+ // name
1902
+ // name:version
1903
+ function splitId(id) {
1904
+ const splitInfo = id.split(':');
1905
+ if (splitInfo.length === 1) {
1906
+ return {
1907
+ name: splitInfo[0],
1908
+ version: undefined,
1909
+ };
1910
+ }
1911
+ else if (splitInfo.length === 2) {
1912
+ return {
1913
+ name: splitInfo[0],
1914
+ version: splitInfo[1],
1915
+ };
1916
+ }
1917
+ else {
1918
+ return {
1919
+ name: splitInfo[1],
1920
+ version: splitInfo[2],
1921
+ };
1922
+ }
1923
+ }
1924
+ // Traverse all nodes in moduleInfo and traverse the entire snapshot
1925
+ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot) {
1926
+ const id = getFMId(remoteInfo);
1927
+ const { value: snapshotValue } = getInfoWithoutType(globalSnapshot, id);
1928
+ const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
1929
+ if (effectiveRemoteSnapshot && !sdk.isManifestProvider(effectiveRemoteSnapshot)) {
1930
+ traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
1931
+ if (effectiveRemoteSnapshot.remotesInfo) {
1932
+ const remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
1933
+ for (const key of remoteKeys) {
1934
+ if (memo[key]) {
1935
+ continue;
1936
+ }
1937
+ memo[key] = true;
1938
+ const subRemoteInfo = splitId(key);
1939
+ const remoteValue = effectiveRemoteSnapshot.remotesInfo[key];
1940
+ traverseModuleInfo(globalSnapshot, {
1941
+ name: subRemoteInfo.name,
1942
+ version: remoteValue.matchedVersion,
1943
+ }, traverse, false, memo, undefined);
1944
+ }
1945
+ }
1946
+ }
1947
+ }
1948
+ const isExisted = (type, url) => {
1949
+ return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
1950
+ };
1951
+ // eslint-disable-next-line max-lines-per-function
1952
+ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
1953
+ const cssAssets = [];
1954
+ const jsAssets = [];
1955
+ const entryAssets = [];
1956
+ const loadedSharedJsAssets = new Set();
1957
+ const loadedSharedCssAssets = new Set();
1958
+ const { options } = origin;
1959
+ const { preloadConfig: rootPreloadConfig } = preloadOptions;
1960
+ const { depsRemote } = rootPreloadConfig;
1961
+ const memo = {};
1962
+ traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot) => {
1963
+ let preloadConfig;
1964
+ if (isRoot) {
1965
+ preloadConfig = rootPreloadConfig;
1966
+ }
1967
+ else {
1968
+ if (Array.isArray(depsRemote)) {
1969
+ // eslint-disable-next-line array-callback-return
1970
+ const findPreloadConfig = depsRemote.find((remoteConfig) => {
1971
+ if (remoteConfig.nameOrAlias === remoteInfo.name ||
1972
+ remoteConfig.nameOrAlias === remoteInfo.alias) {
1973
+ return true;
1974
+ }
1975
+ return false;
1976
+ });
1977
+ if (!findPreloadConfig) {
1978
+ return;
1979
+ }
1980
+ preloadConfig = defaultPreloadArgs(findPreloadConfig);
1981
+ }
1982
+ else if (depsRemote === true) {
1983
+ preloadConfig = rootPreloadConfig;
1984
+ }
1985
+ else {
1986
+ return;
1987
+ }
1988
+ }
1989
+ const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
1990
+ if (remoteEntryUrl) {
1991
+ entryAssets.push({
1992
+ name: remoteInfo.name,
1993
+ moduleInfo: {
1994
+ name: remoteInfo.name,
1995
+ entry: remoteEntryUrl,
1996
+ type: 'remoteEntryType' in moduleInfoSnapshot
1997
+ ? moduleInfoSnapshot.remoteEntryType
1998
+ : 'global',
1999
+ entryGlobalName: 'globalName' in moduleInfoSnapshot
2000
+ ? moduleInfoSnapshot.globalName
2001
+ : remoteInfo.name,
2002
+ shareScope: '',
2003
+ version: 'version' in moduleInfoSnapshot
2004
+ ? moduleInfoSnapshot.version
2005
+ : undefined,
2006
+ },
2007
+ url: remoteEntryUrl,
2008
+ });
2009
+ }
2010
+ let moduleAssetsInfo = 'modules' in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];
2011
+ const normalizedPreloadExposes = normalizePreloadExposes(preloadConfig.exposes);
2012
+ if (normalizedPreloadExposes.length && 'modules' in moduleInfoSnapshot) {
2013
+ moduleAssetsInfo = moduleInfoSnapshot?.modules?.reduce((assets, moduleAssetInfo) => {
2014
+ if (normalizedPreloadExposes?.indexOf(moduleAssetInfo.moduleName) !==
2015
+ -1) {
2016
+ assets.push(moduleAssetInfo);
2017
+ }
2018
+ return assets;
2019
+ }, []);
2020
+ }
2021
+ function handleAssets(assets) {
2022
+ const assetsRes = assets.map((asset) => sdk.getResourceUrl(moduleInfoSnapshot, asset));
2023
+ if (preloadConfig.filter) {
2024
+ return assetsRes.filter(preloadConfig.filter);
2025
+ }
2026
+ return assetsRes;
2027
+ }
2028
+ if (moduleAssetsInfo) {
2029
+ const assetsLength = moduleAssetsInfo.length;
2030
+ for (let index = 0; index < assetsLength; index++) {
2031
+ const assetsInfo = moduleAssetsInfo[index];
2032
+ const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;
2033
+ origin.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
2034
+ id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
2035
+ name: remoteInfo.name,
2036
+ remoteSnapshot: moduleInfoSnapshot,
2037
+ preloadConfig,
2038
+ remote: remoteInfo,
2039
+ origin,
2040
+ });
2041
+ const preloaded = getPreloaded(exposeFullPath);
2042
+ if (preloaded) {
2043
+ continue;
2044
+ }
2045
+ if (preloadConfig.resourceCategory === 'all') {
2046
+ cssAssets.push(...handleAssets(assetsInfo.assets.css.async));
2047
+ cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
2048
+ jsAssets.push(...handleAssets(assetsInfo.assets.js.async));
2049
+ jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
2050
+ // eslint-disable-next-line no-constant-condition
2051
+ }
2052
+ else if ((preloadConfig.resourceCategory = 'sync')) {
2053
+ cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
2054
+ jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
2055
+ }
2056
+ setPreloaded(exposeFullPath);
2057
+ }
2058
+ }
2059
+ }, true, memo, remoteSnapshot);
2060
+ if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
2061
+ const collectSharedAssets = (shareInfo, snapshotShared) => {
2062
+ const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
2063
+ // If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
2064
+ if (registeredShared && typeof registeredShared.lib === 'function') {
2065
+ snapshotShared.assets.js.sync.forEach((asset) => {
2066
+ loadedSharedJsAssets.add(asset);
2067
+ });
2068
+ snapshotShared.assets.css.sync.forEach((asset) => {
2069
+ loadedSharedCssAssets.add(asset);
2070
+ });
2071
+ }
2072
+ };
2073
+ remoteSnapshot.shared.forEach((shared) => {
2074
+ const shareInfos = options.shared?.[shared.sharedName];
2075
+ if (!shareInfos) {
2076
+ return;
2077
+ }
2078
+ // if no version, preload all shared
2079
+ const sharedOptions = shared.version
2080
+ ? shareInfos.find((s) => s.version === shared.version)
2081
+ : shareInfos;
2082
+ if (!sharedOptions) {
2083
+ return;
2084
+ }
2085
+ const arrayShareInfo = arrayOptions(sharedOptions);
2086
+ arrayShareInfo.forEach((s) => {
2087
+ collectSharedAssets(s, shared);
2088
+ });
2089
+ });
2090
+ }
2091
+ const needPreloadJsAssets = jsAssets.filter((asset) => !loadedSharedJsAssets.has(asset) && !isExisted('script', asset));
2092
+ const needPreloadCssAssets = cssAssets.filter((asset) => !loadedSharedCssAssets.has(asset) && !isExisted('link', asset));
2093
+ return {
2094
+ cssAssets: needPreloadCssAssets,
2095
+ jsAssetsWithoutEntry: needPreloadJsAssets,
2096
+ entryAssets: entryAssets.filter((entry) => !isExisted('script', entry.url)),
2097
+ };
2098
+ }
2099
+ const generatePreloadAssetsPlugin = function () {
2100
+ return {
2101
+ name: 'generate-preload-assets-plugin',
2102
+ async generatePreloadAssets(args) {
2103
+ const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot, } = args;
2104
+ if (!sdk.isBrowserEnv()) {
2105
+ return {
2106
+ cssAssets: [],
2107
+ jsAssetsWithoutEntry: [],
2108
+ entryAssets: [],
2109
+ };
2110
+ }
2111
+ if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
2112
+ return {
2113
+ cssAssets: [],
2114
+ jsAssetsWithoutEntry: [],
2115
+ entryAssets: [
2116
+ {
2117
+ name: remote.name,
2118
+ url: remote.entry,
2119
+ moduleInfo: {
2120
+ name: remoteInfo.name,
2121
+ entry: remote.entry,
2122
+ type: remoteInfo.type || 'global',
2123
+ entryGlobalName: '',
2124
+ shareScope: '',
2125
+ },
2126
+ },
2127
+ ],
2128
+ };
2129
+ }
2130
+ assignRemoteInfo(remoteInfo, remoteSnapshot);
2131
+ const assets = generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
2132
+ return assets;
2133
+ },
2134
+ };
2135
+ };
2136
+
2137
+ function getGlobalRemoteInfo(moduleInfo, origin) {
2138
+ const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
2139
+ name: origin.name,
2140
+ version: origin.options.version,
2141
+ });
2142
+ // get remote detail info from global
2143
+ const globalRemoteInfo = hostGlobalSnapshot &&
2144
+ 'remotesInfo' in hostGlobalSnapshot &&
2145
+ hostGlobalSnapshot.remotesInfo &&
2146
+ getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
2147
+ if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
2148
+ return {
2149
+ hostGlobalSnapshot,
2150
+ globalSnapshot: getGlobalSnapshot(),
2151
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
2152
+ name: moduleInfo.name,
2153
+ version: globalRemoteInfo.matchedVersion,
2154
+ }),
2155
+ };
2156
+ }
2157
+ return {
2158
+ hostGlobalSnapshot: undefined,
2159
+ globalSnapshot: getGlobalSnapshot(),
2160
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
2161
+ name: moduleInfo.name,
2162
+ version: 'version' in moduleInfo ? moduleInfo.version : undefined,
2163
+ }),
2164
+ };
2165
+ }
2166
+ class SnapshotHandler {
2167
+ constructor(HostInstance) {
2168
+ this.loadingHostSnapshot = null;
2169
+ this.manifestCache = new Map();
2170
+ this.hooks = new PluginSystem({
2171
+ beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
2172
+ loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
2173
+ loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot'),
2174
+ afterLoadSnapshot: new AsyncWaterfallHook('afterLoadSnapshot'),
2175
+ });
2176
+ this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
2177
+ this.HostInstance = HostInstance;
2178
+ this.loaderHook = HostInstance.loaderHook;
2179
+ }
2180
+ // eslint-disable-next-line max-lines-per-function
2181
+ async loadRemoteSnapshotInfo({ moduleInfo, id, expose, }) {
2182
+ const { options } = this.HostInstance;
2183
+ await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
2184
+ options,
2185
+ moduleInfo,
2186
+ });
2187
+ let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
2188
+ name: this.HostInstance.options.name,
2189
+ version: this.HostInstance.options.version,
2190
+ });
2191
+ if (!hostSnapshot) {
2192
+ hostSnapshot = {
2193
+ version: this.HostInstance.options.version || '',
2194
+ remoteEntry: '',
2195
+ remotesInfo: {},
2196
+ };
2197
+ addGlobalSnapshot({
2198
+ [this.HostInstance.options.name]: hostSnapshot,
2199
+ });
2200
+ }
2201
+ // In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.
2202
+ // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
2203
+ if (hostSnapshot &&
2204
+ 'remotesInfo' in hostSnapshot &&
2205
+ !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
2206
+ if ('version' in moduleInfo || 'entry' in moduleInfo) {
2207
+ hostSnapshot.remotesInfo = {
2208
+ ...hostSnapshot?.remotesInfo,
2209
+ [moduleInfo.name]: {
2210
+ matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry,
2211
+ },
2212
+ };
2213
+ }
2214
+ }
2215
+ const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
2216
+ const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes, } = await this.hooks.lifecycle.loadSnapshot.emit({
2217
+ options,
2218
+ moduleInfo,
2219
+ hostGlobalSnapshot,
2220
+ remoteSnapshot,
2221
+ globalSnapshot,
2222
+ });
2223
+ let mSnapshot;
2224
+ let gSnapshot;
2225
+ // global snapshot includes manifest or module info includes manifest
2226
+ if (globalRemoteSnapshot) {
2227
+ if (sdk.isManifestProvider(globalRemoteSnapshot)) {
2228
+ const remoteEntry = sdk.isBrowserEnv()
2229
+ ? globalRemoteSnapshot.remoteEntry
2230
+ : globalRemoteSnapshot.ssrRemoteEntry ||
2231
+ globalRemoteSnapshot.remoteEntry ||
2232
+ '';
2233
+ const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
2234
+ // eslint-disable-next-line @typescript-eslint/no-shadow
2235
+ const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo({
2236
+ ...moduleInfo,
2237
+ // The global remote may be overridden
2238
+ // Therefore, set the snapshot key to the global address of the actual request
2239
+ entry: remoteEntry,
2240
+ }, moduleSnapshot);
2241
+ mSnapshot = moduleSnapshot;
2242
+ gSnapshot = globalSnapshotRes;
2243
+ }
2244
+ else {
2245
+ const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
2246
+ options: this.HostInstance.options,
2247
+ moduleInfo,
2248
+ remoteSnapshot: globalRemoteSnapshot,
2249
+ from: 'global',
2250
+ });
2251
+ mSnapshot = remoteSnapshotRes;
2252
+ gSnapshot = globalSnapshotRes;
2253
+ }
2254
+ }
2255
+ else {
2256
+ if (isRemoteInfoWithEntry(moduleInfo)) {
2257
+ // get from manifest.json and merge remote info from remote server
2258
+ const moduleSnapshot = await this.getManifestJson(moduleInfo.entry, moduleInfo, {});
2259
+ // eslint-disable-next-line @typescript-eslint/no-shadow
2260
+ const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
2261
+ const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
2262
+ options: this.HostInstance.options,
2263
+ moduleInfo,
2264
+ remoteSnapshot: moduleSnapshot,
2265
+ from: 'global',
2266
+ });
2267
+ mSnapshot = remoteSnapshotRes;
2268
+ gSnapshot = globalSnapshotRes;
2269
+ }
2270
+ else {
2271
+ error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_007, errorCodes.runtimeDescMap, {
2272
+ hostName: moduleInfo.name,
2273
+ hostVersion: moduleInfo.version,
2274
+ globalSnapshot: JSON.stringify(globalSnapshotRes),
2275
+ }));
2276
+ }
2277
+ }
2278
+ await this.hooks.lifecycle.afterLoadSnapshot.emit({
2279
+ id,
2280
+ host: this.HostInstance,
2281
+ options,
2282
+ moduleInfo,
2283
+ remoteSnapshot: mSnapshot,
2284
+ });
2285
+ return {
2286
+ remoteSnapshot: mSnapshot,
2287
+ globalSnapshot: gSnapshot,
2288
+ };
2289
+ }
2290
+ getGlobalRemoteInfo(moduleInfo) {
2291
+ return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
2292
+ }
2293
+ async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
2294
+ const getManifest = async () => {
2295
+ let manifestJson = this.manifestCache.get(manifestUrl);
2296
+ if (manifestJson) {
2297
+ return manifestJson;
2298
+ }
2299
+ try {
2300
+ let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {});
2301
+ if (!res || !(res instanceof Response)) {
2302
+ res = await fetch(manifestUrl, {});
2303
+ }
2304
+ manifestJson = (await res.json());
2305
+ }
2306
+ catch (err) {
2307
+ manifestJson =
2308
+ (await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
2309
+ id: manifestUrl,
2310
+ error: err,
2311
+ from: 'runtime',
2312
+ lifecycle: 'afterResolve',
2313
+ origin: this.HostInstance,
2314
+ }));
2315
+ if (!manifestJson) {
2316
+ delete this.manifestLoading[manifestUrl];
2317
+ error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_003, errorCodes.runtimeDescMap, {
2318
+ manifestUrl,
2319
+ moduleName: moduleInfo.name,
2320
+ hostName: this.HostInstance.options.name,
2321
+ }, `${err}`));
2322
+ }
2323
+ }
2324
+ assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, `${manifestUrl} is not a federation manifest`);
2325
+ this.manifestCache.set(manifestUrl, manifestJson);
2326
+ return manifestJson;
2327
+ };
2328
+ const asyncLoadProcess = async () => {
2329
+ const manifestJson = await getManifest();
2330
+ const remoteSnapshot = sdk.generateSnapshotFromManifest(manifestJson, {
2331
+ version: manifestUrl,
2332
+ });
2333
+ const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
2334
+ options: this.HostInstance.options,
2335
+ moduleInfo,
2336
+ manifestJson,
2337
+ remoteSnapshot,
2338
+ manifestUrl,
2339
+ from: 'manifest',
2340
+ });
2341
+ return remoteSnapshotRes;
2342
+ };
2343
+ if (!this.manifestLoading[manifestUrl]) {
2344
+ this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);
2345
+ }
2346
+ return this.manifestLoading[manifestUrl];
2347
+ }
2348
+ }
2349
+
2350
+ class SharedHandler {
2351
+ constructor(host) {
2352
+ this.hooks = new PluginSystem({
2353
+ afterResolve: new AsyncWaterfallHook('afterResolve'),
2354
+ beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
2355
+ // not used yet
2356
+ loadShare: new AsyncHook(),
2357
+ resolveShare: new SyncWaterfallHook('resolveShare'),
2358
+ // maybe will change, temporarily for internal use only
2359
+ initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap'),
2360
+ });
2361
+ this.host = host;
2362
+ this.shareScopeMap = {};
2363
+ this.initTokens = {};
2364
+ this._setGlobalShareScopeMap(host.options);
2365
+ }
2366
+ // register shared in shareScopeMap
2367
+ registerShared(globalOptions, userOptions) {
2368
+ const { shareInfos, shared } = formatShareConfigs(globalOptions, userOptions);
2369
+ const sharedKeys = Object.keys(shareInfos);
2370
+ sharedKeys.forEach((sharedKey) => {
2371
+ const sharedVals = shareInfos[sharedKey];
2372
+ sharedVals.forEach((sharedVal) => {
2373
+ const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
2374
+ if (!registeredShared && sharedVal && sharedVal.lib) {
2375
+ this.setShared({
2376
+ pkgName: sharedKey,
2377
+ lib: sharedVal.lib,
2378
+ get: sharedVal.get,
2379
+ loaded: true,
2380
+ shared: sharedVal,
2381
+ from: userOptions.name,
2382
+ });
2383
+ }
2384
+ });
2385
+ });
2386
+ return {
2387
+ shareInfos,
2388
+ shared,
2389
+ };
2390
+ }
2391
+ async loadShare(pkgName, extraOptions) {
2392
+ const { host } = this;
2393
+ // This function performs the following steps:
2394
+ // 1. Checks if the currently loaded share already exists, if not, it throws an error
2395
+ // 2. Searches globally for a matching share, if found, it uses it directly
2396
+ // 3. If not found, it retrieves it from the current share and stores the obtained share globally.
2397
+ const shareOptions = getTargetSharedOptions({
2398
+ pkgName,
2399
+ extraOptions,
2400
+ shareInfos: host.options.shared,
2401
+ });
2402
+ if (shareOptions?.scope) {
2403
+ await Promise.all(shareOptions.scope.map(async (shareScope) => {
2404
+ await Promise.all(this.initializeSharing(shareScope, {
2405
+ strategy: shareOptions.strategy,
2406
+ }));
2407
+ return;
2408
+ }));
2409
+ }
2410
+ const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
2411
+ pkgName,
2412
+ shareInfo: shareOptions,
2413
+ shared: host.options.shared,
2414
+ origin: host,
2415
+ });
2416
+ const { shareInfo: shareOptionsRes } = loadShareRes;
2417
+ // Assert that shareInfoRes exists, if not, throw an error
2418
+ assert(shareOptionsRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
2419
+ // Retrieve from cache
2420
+ const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
2421
+ const addUseIn = (shared) => {
2422
+ if (!shared.useIn) {
2423
+ shared.useIn = [];
2424
+ }
2425
+ addUniqueItem(shared.useIn, host.options.name);
2426
+ };
2427
+ if (registeredShared && registeredShared.lib) {
2428
+ addUseIn(registeredShared);
2429
+ return registeredShared.lib;
2430
+ }
2431
+ else if (registeredShared &&
2432
+ registeredShared.loading &&
2433
+ !registeredShared.loaded) {
2434
+ const factory = await registeredShared.loading;
2435
+ registeredShared.loaded = true;
2436
+ if (!registeredShared.lib) {
2437
+ registeredShared.lib = factory;
2438
+ }
2439
+ addUseIn(registeredShared);
2440
+ return factory;
2441
+ }
2442
+ else if (registeredShared) {
2443
+ const asyncLoadProcess = async () => {
2444
+ const factory = await registeredShared.get();
2445
+ addUseIn(registeredShared);
2446
+ registeredShared.loaded = true;
2447
+ registeredShared.lib = factory;
2448
+ return factory;
2449
+ };
2450
+ const loading = asyncLoadProcess();
2451
+ this.setShared({
2452
+ pkgName,
2453
+ loaded: false,
2454
+ shared: registeredShared,
2455
+ from: host.options.name,
2456
+ lib: null,
2457
+ loading,
2458
+ });
2459
+ return loading;
2460
+ }
2461
+ else {
2462
+ if (extraOptions?.customShareInfo) {
2463
+ return false;
2464
+ }
2465
+ const asyncLoadProcess = async () => {
2466
+ const factory = await shareOptionsRes.get();
2467
+ shareOptionsRes.lib = factory;
2468
+ shareOptionsRes.loaded = true;
2469
+ addUseIn(shareOptionsRes);
2470
+ const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
2471
+ if (gShared) {
2472
+ gShared.lib = factory;
2473
+ gShared.loaded = true;
2474
+ gShared.from = shareOptionsRes.from;
2475
+ }
2476
+ return factory;
2477
+ };
2478
+ const loading = asyncLoadProcess();
2479
+ this.setShared({
2480
+ pkgName,
2481
+ loaded: false,
2482
+ shared: shareOptionsRes,
2483
+ from: host.options.name,
2484
+ lib: null,
2485
+ loading,
2486
+ });
2487
+ return loading;
2488
+ }
2489
+ }
2490
+ /**
2491
+ * This function initializes the sharing sequence (executed only once per share scope).
2492
+ * It accepts one argument, the name of the share scope.
2493
+ * If the share scope does not exist, it creates one.
2494
+ */
2495
+ // eslint-disable-next-line @typescript-eslint/member-ordering
2496
+ initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
2497
+ const { host } = this;
2498
+ const from = extraOptions?.from;
2499
+ const strategy = extraOptions?.strategy;
2500
+ let initScope = extraOptions?.initScope;
2501
+ const promises = [];
2502
+ if (from !== 'build') {
2503
+ const { initTokens } = this;
2504
+ if (!initScope)
2505
+ initScope = [];
2506
+ let initToken = initTokens[shareScopeName];
2507
+ if (!initToken)
2508
+ initToken = initTokens[shareScopeName] = { from: this.host.name };
2509
+ if (initScope.indexOf(initToken) >= 0)
2510
+ return promises;
2511
+ initScope.push(initToken);
2512
+ }
2513
+ const shareScope = this.shareScopeMap;
2514
+ const hostName = host.options.name;
2515
+ // Creates a new share scope if necessary
2516
+ if (!shareScope[shareScopeName]) {
2517
+ shareScope[shareScopeName] = {};
2518
+ }
2519
+ // Executes all initialization snippets from all accessible modules
2520
+ const scope = shareScope[shareScopeName];
2521
+ const register = (name, shared) => {
2522
+ const { version, eager } = shared;
2523
+ scope[name] = scope[name] || {};
2524
+ const versions = scope[name];
2525
+ const activeVersion = versions[version];
2526
+ const activeVersionEager = Boolean(activeVersion &&
2527
+ (activeVersion.eager || activeVersion.shareConfig?.eager));
2528
+ if (!activeVersion ||
2529
+ (activeVersion.strategy !== 'loaded-first' &&
2530
+ !activeVersion.loaded &&
2531
+ (Boolean(!eager) !== !activeVersionEager
2532
+ ? eager
2533
+ : hostName > activeVersion.from))) {
2534
+ versions[version] = shared;
2535
+ }
2536
+ };
2537
+ const initFn = (mod) => mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
2538
+ const initRemoteModule = async (key) => {
2539
+ const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
2540
+ id: key,
2541
+ });
2542
+ if (module.getEntry) {
2543
+ let remoteEntryExports;
2544
+ try {
2545
+ remoteEntryExports = await module.getEntry();
2546
+ }
2547
+ catch (error) {
2548
+ remoteEntryExports =
2549
+ (await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
2550
+ id: key,
2551
+ error,
2552
+ from: 'runtime',
2553
+ lifecycle: 'beforeLoadShare',
2554
+ origin: host,
2555
+ }));
2556
+ }
2557
+ if (!module.inited) {
2558
+ await initFn(remoteEntryExports);
2559
+ module.inited = true;
2560
+ }
2561
+ }
2562
+ };
2563
+ Object.keys(host.options.shared).forEach((shareName) => {
2564
+ const sharedArr = host.options.shared[shareName];
2565
+ sharedArr.forEach((shared) => {
2566
+ if (shared.scope.includes(shareScopeName)) {
2567
+ register(shareName, shared);
2568
+ }
2569
+ });
2570
+ });
2571
+ // TODO: strategy==='version-first' need to be removed in the future
2572
+ if (host.options.shareStrategy === 'version-first' ||
2573
+ strategy === 'version-first') {
2574
+ host.options.remotes.forEach((remote) => {
2575
+ if (remote.shareScope === shareScopeName) {
2576
+ promises.push(initRemoteModule(remote.name));
2577
+ }
2578
+ });
2579
+ }
2580
+ return promises;
2581
+ }
2582
+ // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
2583
+ // 1. If the loaded shared already exists globally, then it will be reused
2584
+ // 2. If lib exists in local shared, it will be used directly
2585
+ // 3. If the local get returns something other than Promise, then it will be used directly
2586
+ loadShareSync(pkgName, extraOptions) {
2587
+ const { host } = this;
2588
+ const shareOptions = getTargetSharedOptions({
2589
+ pkgName,
2590
+ extraOptions,
2591
+ shareInfos: host.options.shared,
2592
+ });
2593
+ if (shareOptions?.scope) {
2594
+ shareOptions.scope.forEach((shareScope) => {
2595
+ this.initializeSharing(shareScope, { strategy: shareOptions.strategy });
2596
+ });
2597
+ }
2598
+ const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare);
2599
+ const addUseIn = (shared) => {
2600
+ if (!shared.useIn) {
2601
+ shared.useIn = [];
2602
+ }
2603
+ addUniqueItem(shared.useIn, host.options.name);
2604
+ };
2605
+ if (registeredShared) {
2606
+ if (typeof registeredShared.lib === 'function') {
2607
+ addUseIn(registeredShared);
2608
+ if (!registeredShared.loaded) {
2609
+ registeredShared.loaded = true;
2610
+ if (registeredShared.from === host.options.name) {
2611
+ shareOptions.loaded = true;
2612
+ }
2613
+ }
2614
+ return registeredShared.lib;
2615
+ }
2616
+ if (typeof registeredShared.get === 'function') {
2617
+ const module = registeredShared.get();
2618
+ if (!(module instanceof Promise)) {
2619
+ addUseIn(registeredShared);
2620
+ this.setShared({
2621
+ pkgName,
2622
+ loaded: true,
2623
+ from: host.options.name,
2624
+ lib: module,
2625
+ shared: registeredShared,
2626
+ });
2627
+ return module;
2628
+ }
2629
+ }
2630
+ }
2631
+ if (shareOptions.lib) {
2632
+ if (!shareOptions.loaded) {
2633
+ shareOptions.loaded = true;
2634
+ }
2635
+ return shareOptions.lib;
2636
+ }
2637
+ if (shareOptions.get) {
2638
+ const module = shareOptions.get();
2639
+ if (module instanceof Promise) {
2640
+ const errorCode = extraOptions?.from === 'build' ? errorCodes.RUNTIME_005 : errorCodes.RUNTIME_006;
2641
+ throw new Error(errorCodes.getShortErrorMsg(errorCode, errorCodes.runtimeDescMap, {
2642
+ hostName: host.options.name,
2643
+ sharedPkgName: pkgName,
2644
+ }));
2645
+ }
2646
+ shareOptions.lib = module;
2647
+ this.setShared({
2648
+ pkgName,
2649
+ loaded: true,
2650
+ from: host.options.name,
2651
+ lib: shareOptions.lib,
2652
+ shared: shareOptions,
2653
+ });
2654
+ return shareOptions.lib;
2655
+ }
2656
+ throw new Error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_006, errorCodes.runtimeDescMap, {
2657
+ hostName: host.options.name,
2658
+ sharedPkgName: pkgName,
2659
+ }));
2660
+ }
2661
+ initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
2662
+ const { host } = this;
2663
+ this.shareScopeMap[scopeName] = shareScope;
2664
+ this.hooks.lifecycle.initContainerShareScopeMap.emit({
2665
+ shareScope,
2666
+ options: host.options,
2667
+ origin: host,
2668
+ scopeName,
2669
+ hostShareScopeMap: extraOptions.hostShareScopeMap,
2670
+ });
2671
+ }
2672
+ setShared({ pkgName, shared, from, lib, loading, loaded, get, }) {
2673
+ const { version, scope = 'default', ...shareInfo } = shared;
2674
+ const scopes = Array.isArray(scope) ? scope : [scope];
2675
+ scopes.forEach((sc) => {
2676
+ if (!this.shareScopeMap[sc]) {
2677
+ this.shareScopeMap[sc] = {};
2678
+ }
2679
+ if (!this.shareScopeMap[sc][pkgName]) {
2680
+ this.shareScopeMap[sc][pkgName] = {};
2681
+ }
2682
+ if (!this.shareScopeMap[sc][pkgName][version]) {
2683
+ this.shareScopeMap[sc][pkgName][version] = {
2684
+ version,
2685
+ scope: ['default'],
2686
+ ...shareInfo,
2687
+ lib,
2688
+ loaded,
2689
+ loading,
2690
+ };
2691
+ if (get) {
2692
+ this.shareScopeMap[sc][pkgName][version].get = get;
2693
+ }
2694
+ return;
2695
+ }
2696
+ const registeredShared = this.shareScopeMap[sc][pkgName][version];
2697
+ if (loading && !registeredShared.loading) {
2698
+ registeredShared.loading = loading;
2699
+ }
2700
+ if (loaded && !registeredShared.loaded) {
2701
+ registeredShared.loaded = loaded;
2702
+ }
2703
+ if (from && registeredShared.from !== from) {
2704
+ registeredShared.from = from;
2705
+ }
2706
+ });
2707
+ }
2708
+ _setGlobalShareScopeMap(hostOptions) {
2709
+ const globalShareScopeMap = getGlobalShareScope();
2710
+ const identifier = hostOptions.id || hostOptions.name;
2711
+ if (identifier && !globalShareScopeMap[identifier]) {
2712
+ globalShareScopeMap[identifier] = this.shareScopeMap;
2713
+ }
2714
+ }
2715
+ }
2716
+
2717
+ class RemoteHandler {
2718
+ constructor(host) {
2719
+ this.hooks = new PluginSystem({
2720
+ beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
2721
+ registerRemote: new SyncWaterfallHook('registerRemote'),
2722
+ beforeRequest: new AsyncWaterfallHook('beforeRequest'),
2723
+ onLoad: new AsyncHook('onLoad'),
2724
+ handlePreloadModule: new SyncHook('handlePreloadModule'),
2725
+ errorLoadRemote: new AsyncHook('errorLoadRemote'),
2726
+ beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
2727
+ generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
2728
+ // not used yet
2729
+ afterPreloadRemote: new AsyncHook(),
2730
+ loadEntry: new AsyncHook(),
2731
+ });
2732
+ this.host = host;
2733
+ this.idToRemoteMap = {};
2734
+ }
2735
+ formatAndRegisterRemote(globalOptions, userOptions) {
2736
+ const userRemotes = userOptions.remotes || [];
2737
+ return userRemotes.reduce((res, remote) => {
2738
+ this.registerRemote(remote, res, { force: false });
2739
+ return res;
2740
+ }, globalOptions.remotes);
2741
+ }
2742
+ setIdToRemoteMap(id, remoteMatchInfo) {
2743
+ const { remote, expose } = remoteMatchInfo;
2744
+ const { name, alias } = remote;
2745
+ this.idToRemoteMap[id] = { name: remote.name, expose };
2746
+ if (alias && id.startsWith(name)) {
2747
+ const idWithAlias = id.replace(name, alias);
2748
+ this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };
2749
+ return;
2750
+ }
2751
+ if (alias && id.startsWith(alias)) {
2752
+ const idWithName = id.replace(alias, name);
2753
+ this.idToRemoteMap[idWithName] = { name: remote.name, expose };
2754
+ }
2755
+ }
2756
+ // eslint-disable-next-line max-lines-per-function
2757
+ // eslint-disable-next-line @typescript-eslint/member-ordering
2758
+ async loadRemote(id, options) {
2759
+ const { host } = this;
2760
+ try {
2761
+ const { loadFactory = true } = options || {
2762
+ loadFactory: true,
2763
+ };
2764
+ // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
2765
+ // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.
2766
+ // 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)
2767
+ // 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get
2768
+ // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
2769
+ // id: alias(app1) + expose(button) = app1/button
2770
+ // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
2771
+ const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
2772
+ id,
2773
+ });
2774
+ const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot, } = remoteMatchInfo;
2775
+ const moduleOrFactory = (await module.get(idRes, expose, options, remoteSnapshot));
2776
+ const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
2777
+ id: idRes,
2778
+ pkgNameOrAlias,
2779
+ expose,
2780
+ exposeModule: loadFactory ? moduleOrFactory : undefined,
2781
+ exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,
2782
+ remote,
2783
+ options: moduleOptions,
2784
+ moduleInstance: module,
2785
+ origin: host,
2786
+ });
2787
+ this.setIdToRemoteMap(id, remoteMatchInfo);
2788
+ if (typeof moduleWrapper === 'function') {
2789
+ return moduleWrapper;
2790
+ }
2791
+ return moduleOrFactory;
2792
+ }
2793
+ catch (error) {
2794
+ const { from = 'runtime' } = options || { from: 'runtime' };
2795
+ const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
2796
+ id,
2797
+ error,
2798
+ from,
2799
+ lifecycle: 'onLoad',
2800
+ origin: host,
2801
+ });
2802
+ if (!failOver) {
2803
+ throw error;
2804
+ }
2805
+ return failOver;
2806
+ }
2807
+ }
2808
+ // eslint-disable-next-line @typescript-eslint/member-ordering
2809
+ async preloadRemote(preloadOptions) {
2810
+ const { host } = this;
2811
+ await this.hooks.lifecycle.beforePreloadRemote.emit({
2812
+ preloadOps: preloadOptions,
2813
+ options: host.options,
2814
+ origin: host,
2815
+ });
2816
+ const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
2817
+ await Promise.all(preloadOps.map(async (ops) => {
2818
+ const { remote } = ops;
2819
+ const remoteInfo = getRemoteInfo(remote);
2820
+ const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
2821
+ moduleInfo: remote,
2822
+ });
2823
+ const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
2824
+ origin: host,
2825
+ preloadOptions: ops,
2826
+ remote,
2827
+ remoteInfo,
2828
+ globalSnapshot,
2829
+ remoteSnapshot,
2830
+ });
2831
+ if (!assets) {
2832
+ return;
2833
+ }
2834
+ preloadAssets(remoteInfo, host, assets);
2835
+ }));
2836
+ }
2837
+ registerRemotes(remotes, options) {
2838
+ const { host } = this;
2839
+ remotes.forEach((remote) => {
2840
+ this.registerRemote(remote, host.options.remotes, {
2841
+ force: options?.force,
2842
+ });
2843
+ });
2844
+ }
2845
+ async getRemoteModuleAndOptions(options) {
2846
+ const { host } = this;
2847
+ const { id } = options;
2848
+ let loadRemoteArgs;
2849
+ try {
2850
+ loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
2851
+ id,
2852
+ options: host.options,
2853
+ origin: host,
2854
+ });
2855
+ }
2856
+ catch (error) {
2857
+ loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({
2858
+ id,
2859
+ options: host.options,
2860
+ origin: host,
2861
+ from: 'runtime',
2862
+ error,
2863
+ lifecycle: 'beforeRequest',
2864
+ }));
2865
+ if (!loadRemoteArgs) {
2866
+ throw error;
2867
+ }
2868
+ }
2869
+ const { id: idRes } = loadRemoteArgs;
2870
+ const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
2871
+ assert(remoteSplitInfo, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_004, errorCodes.runtimeDescMap, {
2872
+ hostName: host.options.name,
2873
+ requestId: idRes,
2874
+ }));
2875
+ const { remote: rawRemote } = remoteSplitInfo;
2876
+ const remoteInfo = getRemoteInfo(rawRemote);
2877
+ const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit({
2878
+ id: idRes,
2879
+ ...remoteSplitInfo,
2880
+ options: host.options,
2881
+ origin: host,
2882
+ remoteInfo,
2883
+ });
2884
+ const { remote, expose } = matchInfo;
2885
+ assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
2886
+ let module = host.moduleCache.get(remote.name);
2887
+ const moduleOptions = {
2888
+ host: host,
2889
+ remoteInfo,
2890
+ };
2891
+ if (!module) {
2892
+ module = new Module(moduleOptions);
2893
+ host.moduleCache.set(remote.name, module);
2894
+ }
2895
+ return {
2896
+ module,
2897
+ moduleOptions,
2898
+ remoteMatchInfo: matchInfo,
2899
+ };
2900
+ }
2901
+ registerRemote(remote, targetRemotes, options) {
2902
+ const { host } = this;
2903
+ const normalizeRemote = () => {
2904
+ if (remote.alias) {
2905
+ // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
2906
+ // As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
2907
+ const findEqual = targetRemotes.find((item) => remote.alias &&
2908
+ (item.name.startsWith(remote.alias) ||
2909
+ item.alias?.startsWith(remote.alias)));
2910
+ assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
2911
+ }
2912
+ // Set the remote entry to a complete path
2913
+ if ('entry' in remote) {
2914
+ if (sdk.isBrowserEnv() && !remote.entry.startsWith('http')) {
2915
+ remote.entry = new URL(remote.entry, window.location.origin).href;
2916
+ }
2917
+ }
2918
+ if (!remote.shareScope) {
2919
+ remote.shareScope = DEFAULT_SCOPE;
2920
+ }
2921
+ if (!remote.type) {
2922
+ remote.type = DEFAULT_REMOTE_TYPE;
2923
+ }
2924
+ };
2925
+ this.hooks.lifecycle.beforeRegisterRemote.emit({ remote, origin: host });
2926
+ const registeredRemote = targetRemotes.find((item) => item.name === remote.name);
2927
+ if (!registeredRemote) {
2928
+ normalizeRemote();
2929
+ targetRemotes.push(remote);
2930
+ this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });
2931
+ }
2932
+ else {
2933
+ const messages = [
2934
+ `The remote "${remote.name}" is already registered.`,
2935
+ 'Please note that overriding it may cause unexpected errors.',
2936
+ ];
2937
+ if (options?.force) {
2938
+ // remove registered remote
2939
+ this.removeRemote(registeredRemote);
2940
+ normalizeRemote();
2941
+ targetRemotes.push(remote);
2942
+ this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });
2943
+ sdk.warn(messages.join(' '));
2944
+ }
2945
+ }
2946
+ }
2947
+ removeRemote(remote) {
2948
+ try {
2949
+ const { host } = this;
2950
+ const { name } = remote;
2951
+ const remoteIndex = host.options.remotes.findIndex((item) => item.name === name);
2952
+ if (remoteIndex !== -1) {
2953
+ host.options.remotes.splice(remoteIndex, 1);
2954
+ }
2955
+ const loadedModule = host.moduleCache.get(remote.name);
2956
+ if (loadedModule) {
2957
+ const remoteInfo = loadedModule.remoteInfo;
2958
+ const key = remoteInfo.entryGlobalName;
2959
+ if (CurrentGlobal[key]) {
2960
+ if (Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable) {
2961
+ delete CurrentGlobal[key];
2962
+ }
2963
+ else {
2964
+ // @ts-ignore
2965
+ CurrentGlobal[key] = undefined;
2966
+ }
2967
+ }
2968
+ const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
2969
+ if (globalLoading[remoteEntryUniqueKey]) {
2970
+ delete globalLoading[remoteEntryUniqueKey];
2971
+ }
2972
+ host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
2973
+ // delete unloaded shared and instance
2974
+ let remoteInsId = remoteInfo.buildVersion
2975
+ ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)
2976
+ : remoteInfo.name;
2977
+ const remoteInsIndex = CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {
2978
+ if (remoteInfo.buildVersion) {
2979
+ return ins.options.id === remoteInsId;
2980
+ }
2981
+ else {
2982
+ return ins.name === remoteInsId;
2983
+ }
2984
+ });
2985
+ if (remoteInsIndex !== -1) {
2986
+ const remoteIns = CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];
2987
+ remoteInsId = remoteIns.options.id || remoteInsId;
2988
+ const globalShareScopeMap = getGlobalShareScope();
2989
+ let isAllSharedNotUsed = true;
2990
+ const needDeleteKeys = [];
2991
+ Object.keys(globalShareScopeMap).forEach((instId) => {
2992
+ const shareScopeMap = globalShareScopeMap[instId];
2993
+ shareScopeMap &&
2994
+ Object.keys(shareScopeMap).forEach((shareScope) => {
2995
+ const shareScopeVal = shareScopeMap[shareScope];
2996
+ shareScopeVal &&
2997
+ Object.keys(shareScopeVal).forEach((shareName) => {
2998
+ const sharedPkgs = shareScopeVal[shareName];
2999
+ sharedPkgs &&
3000
+ Object.keys(sharedPkgs).forEach((shareVersion) => {
3001
+ const shared = sharedPkgs[shareVersion];
3002
+ if (shared &&
3003
+ typeof shared === 'object' &&
3004
+ shared.from === remoteInfo.name) {
3005
+ if (shared.loaded || shared.loading) {
3006
+ shared.useIn = shared.useIn.filter((usedHostName) => usedHostName !== remoteInfo.name);
3007
+ if (shared.useIn.length) {
3008
+ isAllSharedNotUsed = false;
3009
+ }
3010
+ else {
3011
+ needDeleteKeys.push([
3012
+ instId,
3013
+ shareScope,
3014
+ shareName,
3015
+ shareVersion,
3016
+ ]);
3017
+ }
3018
+ }
3019
+ else {
3020
+ needDeleteKeys.push([
3021
+ instId,
3022
+ shareScope,
3023
+ shareName,
3024
+ shareVersion,
3025
+ ]);
3026
+ }
3027
+ }
3028
+ });
3029
+ });
3030
+ });
3031
+ });
3032
+ if (isAllSharedNotUsed) {
3033
+ remoteIns.shareScopeMap = {};
3034
+ delete globalShareScopeMap[remoteInsId];
3035
+ }
3036
+ needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion]) => {
3037
+ delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[shareVersion];
3038
+ });
3039
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
3040
+ }
3041
+ const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
3042
+ if (hostGlobalSnapshot) {
3043
+ const remoteKey = hostGlobalSnapshot &&
3044
+ 'remotesInfo' in hostGlobalSnapshot &&
3045
+ hostGlobalSnapshot.remotesInfo &&
3046
+ getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
3047
+ if (remoteKey) {
3048
+ delete hostGlobalSnapshot.remotesInfo[remoteKey];
3049
+ if (
3050
+ //eslint-disable-next-line no-extra-boolean-cast
3051
+ Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
3052
+ delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
3053
+ }
3054
+ }
3055
+ }
3056
+ host.moduleCache.delete(remote.name);
3057
+ }
3058
+ }
3059
+ catch (err) {
3060
+ logger.log('removeRemote fail: ', err);
3061
+ }
3062
+ }
3063
+ }
3064
+
3065
+ const USE_SNAPSHOT = typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean'
3066
+ ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
3067
+ : true; // Default to true (use snapshot) when not explicitly defined
3068
+ class ModuleFederation {
3069
+ constructor(userOptions) {
3070
+ this.hooks = new PluginSystem({
3071
+ beforeInit: new SyncWaterfallHook('beforeInit'),
3072
+ init: new SyncHook(),
3073
+ // maybe will change, temporarily for internal use only
3074
+ beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
3075
+ // maybe will change, temporarily for internal use only
3076
+ initContainer: new AsyncWaterfallHook('initContainer'),
3077
+ });
3078
+ this.version = "0.0.0-feat-support-bridge-react-router-v7-20251015102312";
3079
+ this.moduleCache = new Map();
3080
+ this.loaderHook = new PluginSystem({
3081
+ // FIXME: may not be suitable , not open to the public yet
3082
+ getModuleInfo: new SyncHook(),
3083
+ createScript: new SyncHook(),
3084
+ createLink: new SyncHook(),
3085
+ fetch: new AsyncHook(),
3086
+ loadEntryError: new AsyncHook(),
3087
+ getModuleFactory: new AsyncHook(),
3088
+ });
3089
+ this.bridgeHook = new PluginSystem({
3090
+ beforeBridgeRender: new SyncHook(),
3091
+ afterBridgeRender: new SyncHook(),
3092
+ beforeBridgeDestroy: new SyncHook(),
3093
+ afterBridgeDestroy: new SyncHook(),
3094
+ });
3095
+ const plugins = USE_SNAPSHOT
3096
+ ? [snapshotPlugin(), generatePreloadAssetsPlugin()]
3097
+ : [];
3098
+ // TODO: Validate the details of the options
3099
+ // Initialize options with default values
3100
+ const defaultOptions = {
3101
+ id: getBuilderId(),
3102
+ name: userOptions.name,
3103
+ plugins,
3104
+ remotes: [],
3105
+ shared: {},
3106
+ inBrowser: sdk.isBrowserEnv(),
3107
+ };
3108
+ this.name = userOptions.name;
3109
+ this.options = defaultOptions;
3110
+ this.snapshotHandler = new SnapshotHandler(this);
3111
+ this.sharedHandler = new SharedHandler(this);
3112
+ this.remoteHandler = new RemoteHandler(this);
3113
+ this.shareScopeMap = this.sharedHandler.shareScopeMap;
3114
+ this.registerPlugins([
3115
+ ...defaultOptions.plugins,
3116
+ ...(userOptions.plugins || []),
3117
+ ]);
3118
+ this.options = this.formatOptions(defaultOptions, userOptions);
3119
+ }
3120
+ initOptions(userOptions) {
3121
+ this.registerPlugins(userOptions.plugins);
3122
+ const options = this.formatOptions(this.options, userOptions);
3123
+ this.options = options;
3124
+ return options;
3125
+ }
3126
+ async loadShare(pkgName, extraOptions) {
3127
+ return this.sharedHandler.loadShare(pkgName, extraOptions);
3128
+ }
3129
+ // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
3130
+ // 1. If the loaded shared already exists globally, then it will be reused
3131
+ // 2. If lib exists in local shared, it will be used directly
3132
+ // 3. If the local get returns something other than Promise, then it will be used directly
3133
+ loadShareSync(pkgName, extraOptions) {
3134
+ return this.sharedHandler.loadShareSync(pkgName, extraOptions);
3135
+ }
3136
+ initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
3137
+ return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);
3138
+ }
3139
+ initRawContainer(name, url, container) {
3140
+ const remoteInfo = getRemoteInfo({ name, entry: url });
3141
+ const module = new Module({ host: this, remoteInfo });
3142
+ module.remoteEntryExports = container;
3143
+ this.moduleCache.set(name, module);
3144
+ return module;
3145
+ }
3146
+ // eslint-disable-next-line max-lines-per-function
3147
+ // eslint-disable-next-line @typescript-eslint/member-ordering
3148
+ async loadRemote(id, options) {
3149
+ return this.remoteHandler.loadRemote(id, options);
3150
+ }
3151
+ // eslint-disable-next-line @typescript-eslint/member-ordering
3152
+ async preloadRemote(preloadOptions) {
3153
+ return this.remoteHandler.preloadRemote(preloadOptions);
3154
+ }
3155
+ initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
3156
+ this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
3157
+ }
3158
+ formatOptions(globalOptions, userOptions) {
3159
+ const { shared } = formatShareConfigs(globalOptions, userOptions);
3160
+ const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
3161
+ origin: this,
3162
+ userOptions,
3163
+ options: globalOptions,
3164
+ shareInfo: shared,
3165
+ });
3166
+ const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
3167
+ const { shared: handledShared } = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes);
3168
+ const plugins = [...globalOptionsRes.plugins];
3169
+ if (userOptionsRes.plugins) {
3170
+ userOptionsRes.plugins.forEach((plugin) => {
3171
+ if (!plugins.includes(plugin)) {
3172
+ plugins.push(plugin);
3173
+ }
3174
+ });
3175
+ }
3176
+ const optionsRes = {
3177
+ ...globalOptions,
3178
+ ...userOptions,
3179
+ plugins,
3180
+ remotes,
3181
+ shared: handledShared,
3182
+ };
3183
+ this.hooks.lifecycle.init.emit({
3184
+ origin: this,
3185
+ options: optionsRes,
3186
+ });
3187
+ return optionsRes;
3188
+ }
3189
+ registerPlugins(plugins) {
3190
+ const pluginRes = registerPlugins(plugins, this);
3191
+ // Merge plugin
3192
+ this.options.plugins = this.options.plugins.reduce((res, plugin) => {
3193
+ if (!plugin)
3194
+ return res;
3195
+ if (res && !res.find((item) => item.name === plugin.name)) {
3196
+ res.push(plugin);
3197
+ }
3198
+ return res;
3199
+ }, pluginRes || []);
3200
+ }
3201
+ registerRemotes(remotes, options) {
3202
+ return this.remoteHandler.registerRemotes(remotes, options);
3203
+ }
3204
+ registerShared(shared) {
3205
+ this.sharedHandler.registerShared(this.options, {
3206
+ ...this.options,
3207
+ shared,
3208
+ });
3209
+ }
3210
+ }
3211
+
3212
+ var index = /*#__PURE__*/Object.freeze({
3213
+ __proto__: null
3214
+ });
3215
+
3216
+ exports.loadScript = sdk.loadScript;
3217
+ exports.loadScriptNode = sdk.loadScriptNode;
3218
+ exports.CurrentGlobal = CurrentGlobal;
3219
+ exports.Global = Global;
3220
+ exports.Module = Module;
3221
+ exports.ModuleFederation = ModuleFederation;
3222
+ exports.addGlobalSnapshot = addGlobalSnapshot;
3223
+ exports.assert = assert;
3224
+ exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
3225
+ exports.getGlobalSnapshot = getGlobalSnapshot;
3226
+ exports.getInfoWithoutType = getInfoWithoutType;
3227
+ exports.getRegisteredShare = getRegisteredShare;
3228
+ exports.getRemoteEntry = getRemoteEntry;
3229
+ exports.getRemoteInfo = getRemoteInfo;
3230
+ exports.helpers = helpers;
3231
+ exports.isStaticResourcesEqual = isStaticResourcesEqual;
3232
+ exports.matchRemoteWithNameAndExpose = matchRemoteWithNameAndExpose;
3233
+ exports.registerGlobalPlugins = registerGlobalPlugins;
3234
+ exports.resetFederationGlobalInfo = resetFederationGlobalInfo;
3235
+ exports.safeWrapper = safeWrapper;
3236
+ exports.satisfy = satisfy;
3237
+ exports.setGlobalFederationConstructor = setGlobalFederationConstructor;
3238
+ exports.setGlobalFederationInstance = setGlobalFederationInstance;
3239
+ exports.types = index;
3240
+ //# sourceMappingURL=index.cjs.cjs.map