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