@module-federation/runtime-core 0.0.0-fix-lazy-comile-20250925082726

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