@module-federation/runtime-core 0.0.0-next-20250926024003 → 0.0.0-perf-devtools-20260106124142

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