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