@module-federation/runtime-core 0.0.0-next-20250926024003 → 0.0.0-refactor-manifest-20251013103938

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-20250926024003";
204
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-refactor-manifest-20251013103938";
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,11 +1522,17 @@ 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;
@@ -1458,7 +1541,7 @@ let Module = class Module {
1458
1541
  remoteEntryExports = await getRemoteEntry({
1459
1542
  origin: this.host,
1460
1543
  remoteInfo: this.remoteInfo,
1461
- remoteEntryExports: this.remoteEntryExports
1544
+ remoteEntryExports: this.remoteEntryExports,
1462
1545
  });
1463
1546
  assert(remoteEntryExports, `remoteEntryExports is undefined \n ${sdk.safeToString(this.remoteInfo)}`);
1464
1547
  this.remoteEntryExports = remoteEntryExports;
@@ -1466,20 +1549,18 @@ let Module = class Module {
1466
1549
  }
1467
1550
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1468
1551
  async get(id, expose, options, remoteSnapshot) {
1469
- const { loadFactory = true } = options || {
1470
- loadFactory: true
1471
- };
1552
+ const { loadFactory = true } = options || { loadFactory: true };
1472
1553
  // Get remoteEntry.js
1473
1554
  const remoteEntryExports = await this.getEntry();
1474
1555
  if (!this.inited) {
1475
1556
  const localShareScopeMap = this.host.shareScopeMap;
1476
- const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope) ? this.remoteInfo.shareScope : [
1477
- this.remoteInfo.shareScope
1478
- ];
1557
+ const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope)
1558
+ ? this.remoteInfo.shareScope
1559
+ : [this.remoteInfo.shareScope];
1479
1560
  if (!shareScopeKeys.length) {
1480
1561
  shareScopeKeys.push('default');
1481
1562
  }
1482
- shareScopeKeys.forEach((shareScopeKey)=>{
1563
+ shareScopeKeys.forEach((shareScopeKey) => {
1483
1564
  if (!localShareScopeMap[shareScopeKey]) {
1484
1565
  localShareScopeMap[shareScopeKey] = {};
1485
1566
  }
@@ -1489,13 +1570,15 @@ let Module = class Module {
1489
1570
  const initScope = [];
1490
1571
  const remoteEntryInitOptions = {
1491
1572
  version: this.remoteInfo.version || '',
1492
- shareScopeKeys: Array.isArray(this.remoteInfo.shareScope) ? shareScopeKeys : this.remoteInfo.shareScope || 'default'
1573
+ shareScopeKeys: Array.isArray(this.remoteInfo.shareScope)
1574
+ ? shareScopeKeys
1575
+ : this.remoteInfo.shareScope || 'default',
1493
1576
  };
1494
1577
  // Help to find host instance
1495
1578
  Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
1496
1579
  value: localShareScopeMap,
1497
1580
  // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
1498
- enumerable: false
1581
+ enumerable: false,
1499
1582
  });
1500
1583
  const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
1501
1584
  shareScope,
@@ -1503,22 +1586,23 @@ let Module = class Module {
1503
1586
  remoteEntryInitOptions,
1504
1587
  initScope,
1505
1588
  remoteInfo: this.remoteInfo,
1506
- origin: this.host
1589
+ origin: this.host,
1507
1590
  });
1508
- if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === 'undefined') {
1591
+ if (typeof remoteEntryExports?.init === 'undefined') {
1509
1592
  error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_002, errorCodes.runtimeDescMap, {
1510
1593
  hostName: this.host.name,
1511
1594
  remoteName: this.remoteInfo.name,
1512
1595
  remoteEntryUrl: this.remoteInfo.entry,
1513
- remoteEntryKey: this.remoteInfo.entryGlobalName
1596
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
1514
1597
  }));
1515
1598
  }
1516
1599
  await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
1517
- await this.host.hooks.lifecycle.initContainer.emit(polyfills._extends({}, initContainerOptions, {
1600
+ await this.host.hooks.lifecycle.initContainer.emit({
1601
+ ...initContainerOptions,
1518
1602
  id,
1519
1603
  remoteSnapshot,
1520
- remoteEntryExports
1521
- }));
1604
+ remoteEntryExports,
1605
+ });
1522
1606
  }
1523
1607
  this.lib = remoteEntryExports;
1524
1608
  this.inited = true;
@@ -1526,7 +1610,7 @@ let Module = class Module {
1526
1610
  moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
1527
1611
  remoteEntryExports,
1528
1612
  expose,
1529
- moduleInfo: this.remoteInfo
1613
+ moduleInfo: this.remoteInfo,
1530
1614
  });
1531
1615
  // get exposeGetter
1532
1616
  if (!moduleFactory) {
@@ -1544,22 +1628,26 @@ let Module = class Module {
1544
1628
  }
1545
1629
  wraperFactory(moduleFactory, id) {
1546
1630
  function defineModuleId(res, id) {
1547
- if (res && typeof res === 'object' && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
1631
+ if (res &&
1632
+ typeof res === 'object' &&
1633
+ Object.isExtensible(res) &&
1634
+ !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
1548
1635
  Object.defineProperty(res, Symbol.for('mf_module_id'), {
1549
1636
  value: id,
1550
- enumerable: false
1637
+ enumerable: false,
1551
1638
  });
1552
1639
  }
1553
1640
  }
1554
1641
  if (moduleFactory instanceof Promise) {
1555
- return async ()=>{
1642
+ return async () => {
1556
1643
  const res = await moduleFactory();
1557
1644
  // This parameter is used for bridge debugging
1558
1645
  defineModuleId(res, id);
1559
1646
  return res;
1560
1647
  };
1561
- } else {
1562
- return ()=>{
1648
+ }
1649
+ else {
1650
+ return () => {
1563
1651
  const res = moduleFactory();
1564
1652
  // This parameter is used for bridge debugging
1565
1653
  defineModuleId(res, id);
@@ -1567,15 +1655,16 @@ let Module = class Module {
1567
1655
  };
1568
1656
  }
1569
1657
  }
1570
- constructor({ remoteInfo, host }){
1571
- this.inited = false;
1572
- this.lib = undefined;
1573
- this.remoteInfo = remoteInfo;
1574
- this.host = host;
1575
- }
1576
- };
1658
+ }
1577
1659
 
1578
1660
  class SyncHook {
1661
+ constructor(type) {
1662
+ this.type = '';
1663
+ this.listeners = new Set();
1664
+ if (type) {
1665
+ this.type = type;
1666
+ }
1667
+ }
1579
1668
  on(fn) {
1580
1669
  if (typeof fn === 'function') {
1581
1670
  this.listeners.add(fn);
@@ -1594,7 +1683,7 @@ class SyncHook {
1594
1683
  let result;
1595
1684
  if (this.listeners.size > 0) {
1596
1685
  // eslint-disable-next-line prefer-spread
1597
- this.listeners.forEach((fn)=>{
1686
+ this.listeners.forEach((fn) => {
1598
1687
  result = fn(...data);
1599
1688
  });
1600
1689
  }
@@ -1606,13 +1695,6 @@ class SyncHook {
1606
1695
  removeAll() {
1607
1696
  this.listeners.clear();
1608
1697
  }
1609
- constructor(type){
1610
- this.type = '';
1611
- this.listeners = new Set();
1612
- if (type) {
1613
- this.type = type;
1614
- }
1615
- }
1616
1698
  }
1617
1699
 
1618
1700
  class AsyncHook extends SyncHook {
@@ -1621,12 +1703,14 @@ class AsyncHook extends SyncHook {
1621
1703
  const ls = Array.from(this.listeners);
1622
1704
  if (ls.length > 0) {
1623
1705
  let i = 0;
1624
- const call = (prev)=>{
1706
+ const call = (prev) => {
1625
1707
  if (prev === false) {
1626
1708
  return false; // Abort process
1627
- } else if (i < ls.length) {
1709
+ }
1710
+ else if (i < ls.length) {
1628
1711
  return Promise.resolve(ls[i++].apply(null, data)).then(call);
1629
- } else {
1712
+ }
1713
+ else {
1630
1714
  return prev;
1631
1715
  }
1632
1716
  };
@@ -1643,7 +1727,7 @@ function checkReturnData(originalData, returnedData) {
1643
1727
  }
1644
1728
  if (originalData !== returnedData) {
1645
1729
  // eslint-disable-next-line no-restricted-syntax
1646
- for(const key in originalData){
1730
+ for (const key in originalData) {
1647
1731
  if (!(key in returnedData)) {
1648
1732
  return false;
1649
1733
  }
@@ -1652,34 +1736,41 @@ function checkReturnData(originalData, returnedData) {
1652
1736
  return true;
1653
1737
  }
1654
1738
  class SyncWaterfallHook extends SyncHook {
1739
+ constructor(type) {
1740
+ super();
1741
+ this.onerror = error;
1742
+ this.type = type;
1743
+ }
1655
1744
  emit(data) {
1656
1745
  if (!isObject(data)) {
1657
1746
  error(`The data for the "${this.type}" hook should be an object.`);
1658
1747
  }
1659
- for (const fn of this.listeners){
1748
+ for (const fn of this.listeners) {
1660
1749
  try {
1661
1750
  const tempData = fn(data);
1662
1751
  if (checkReturnData(data, tempData)) {
1663
1752
  data = tempData;
1664
- } else {
1753
+ }
1754
+ else {
1665
1755
  this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
1666
1756
  break;
1667
1757
  }
1668
- } catch (e) {
1758
+ }
1759
+ catch (e) {
1669
1760
  warn(e);
1670
1761
  this.onerror(e);
1671
1762
  }
1672
1763
  }
1673
1764
  return data;
1674
1765
  }
1675
- constructor(type){
1766
+ }
1767
+
1768
+ class AsyncWaterfallHook extends SyncHook {
1769
+ constructor(type) {
1676
1770
  super();
1677
1771
  this.onerror = error;
1678
1772
  this.type = type;
1679
1773
  }
1680
- }
1681
-
1682
- class AsyncWaterfallHook extends SyncHook {
1683
1774
  emit(data) {
1684
1775
  if (!isObject(data)) {
1685
1776
  error(`The response data for the "${this.type}" hook must be an object.`);
@@ -1687,22 +1778,24 @@ class AsyncWaterfallHook extends SyncHook {
1687
1778
  const ls = Array.from(this.listeners);
1688
1779
  if (ls.length > 0) {
1689
1780
  let i = 0;
1690
- const processError = (e)=>{
1781
+ const processError = (e) => {
1691
1782
  warn(e);
1692
1783
  this.onerror(e);
1693
1784
  return data;
1694
1785
  };
1695
- const call = (prevData)=>{
1786
+ const call = (prevData) => {
1696
1787
  if (checkReturnData(data, prevData)) {
1697
1788
  data = prevData;
1698
1789
  if (i < ls.length) {
1699
1790
  try {
1700
1791
  return Promise.resolve(ls[i++](data)).then(call, processError);
1701
- } catch (e) {
1792
+ }
1793
+ catch (e) {
1702
1794
  return processError(e);
1703
1795
  }
1704
1796
  }
1705
- } else {
1797
+ }
1798
+ else {
1706
1799
  this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
1707
1800
  }
1708
1801
  return data;
@@ -1711,14 +1804,14 @@ class AsyncWaterfallHook extends SyncHook {
1711
1804
  }
1712
1805
  return Promise.resolve(data);
1713
1806
  }
1714
- constructor(type){
1715
- super();
1716
- this.onerror = error;
1717
- this.type = type;
1718
- }
1719
1807
  }
1720
1808
 
1721
1809
  class PluginSystem {
1810
+ constructor(lifecycle) {
1811
+ this.registerPlugins = {};
1812
+ this.lifecycle = lifecycle;
1813
+ this.lifecycleKeys = Object.keys(lifecycle);
1814
+ }
1722
1815
  applyPlugin(plugin, instance) {
1723
1816
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
1724
1817
  // The plugin's name is mandatory and must be unique
@@ -1726,8 +1819,8 @@ class PluginSystem {
1726
1819
  assert(pluginName, 'A name must be provided by the plugin.');
1727
1820
  if (!this.registerPlugins[pluginName]) {
1728
1821
  this.registerPlugins[pluginName] = plugin;
1729
- plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
1730
- Object.keys(this.lifecycle).forEach((key)=>{
1822
+ plugin.apply?.(instance);
1823
+ Object.keys(this.lifecycle).forEach((key) => {
1731
1824
  const pluginLife = plugin[key];
1732
1825
  if (pluginLife) {
1733
1826
  this.lifecycle[key].on(pluginLife);
@@ -1739,17 +1832,12 @@ class PluginSystem {
1739
1832
  assert(pluginName, 'A name is required.');
1740
1833
  const plugin = this.registerPlugins[pluginName];
1741
1834
  assert(plugin, `The plugin "${pluginName}" is not registered.`);
1742
- Object.keys(plugin).forEach((key)=>{
1835
+ Object.keys(plugin).forEach((key) => {
1743
1836
  if (key !== 'name') {
1744
1837
  this.lifecycle[key].remove(plugin[key]);
1745
1838
  }
1746
1839
  });
1747
1840
  }
1748
- constructor(lifecycle){
1749
- this.registerPlugins = {};
1750
- this.lifecycle = lifecycle;
1751
- this.lifecycleKeys = Object.keys(lifecycle);
1752
- }
1753
1841
  }
1754
1842
 
1755
1843
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
@@ -1770,12 +1858,12 @@ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
1770
1858
  function snapshotPlugin() {
1771
1859
  return {
1772
1860
  name: 'snapshot-plugin',
1773
- async afterResolve (args) {
1861
+ async afterResolve(args) {
1774
1862
  const { remote, pkgNameOrAlias, expose, origin, remoteInfo, id } = args;
1775
1863
  if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
1776
1864
  const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo({
1777
1865
  moduleInfo: remote,
1778
- id
1866
+ id,
1779
1867
  });
1780
1868
  assignRemoteInfo(remoteInfo, remoteSnapshot);
1781
1869
  // preloading assets
@@ -1783,13 +1871,11 @@ function snapshotPlugin() {
1783
1871
  remote,
1784
1872
  preloadConfig: {
1785
1873
  nameOrAlias: pkgNameOrAlias,
1786
- exposes: [
1787
- expose
1788
- ],
1874
+ exposes: [expose],
1789
1875
  resourceCategory: 'sync',
1790
1876
  share: false,
1791
- depsRemote: false
1792
- }
1877
+ depsRemote: false,
1878
+ },
1793
1879
  };
1794
1880
  const assets = await origin.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
1795
1881
  origin,
@@ -1797,17 +1883,18 @@ function snapshotPlugin() {
1797
1883
  remoteInfo,
1798
1884
  remote,
1799
1885
  remoteSnapshot,
1800
- globalSnapshot
1886
+ globalSnapshot,
1801
1887
  });
1802
1888
  if (assets) {
1803
1889
  preloadAssets(remoteInfo, origin, assets, false);
1804
1890
  }
1805
- return polyfills._extends({}, args, {
1806
- remoteSnapshot
1807
- });
1891
+ return {
1892
+ ...args,
1893
+ remoteSnapshot,
1894
+ };
1808
1895
  }
1809
1896
  return args;
1810
- }
1897
+ },
1811
1898
  };
1812
1899
  }
1813
1900
 
@@ -1818,17 +1905,19 @@ function splitId(id) {
1818
1905
  if (splitInfo.length === 1) {
1819
1906
  return {
1820
1907
  name: splitInfo[0],
1821
- version: undefined
1908
+ version: undefined,
1822
1909
  };
1823
- } else if (splitInfo.length === 2) {
1910
+ }
1911
+ else if (splitInfo.length === 2) {
1824
1912
  return {
1825
1913
  name: splitInfo[0],
1826
- version: splitInfo[1]
1914
+ version: splitInfo[1],
1827
1915
  };
1828
- } else {
1916
+ }
1917
+ else {
1829
1918
  return {
1830
1919
  name: splitInfo[1],
1831
- version: splitInfo[2]
1920
+ version: splitInfo[2],
1832
1921
  };
1833
1922
  }
1834
1923
  }
@@ -1841,7 +1930,7 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
1841
1930
  traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
1842
1931
  if (effectiveRemoteSnapshot.remotesInfo) {
1843
1932
  const remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
1844
- for (const key of remoteKeys){
1933
+ for (const key of remoteKeys) {
1845
1934
  if (memo[key]) {
1846
1935
  continue;
1847
1936
  }
@@ -1850,13 +1939,13 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
1850
1939
  const remoteValue = effectiveRemoteSnapshot.remotesInfo[key];
1851
1940
  traverseModuleInfo(globalSnapshot, {
1852
1941
  name: subRemoteInfo.name,
1853
- version: remoteValue.matchedVersion
1942
+ version: remoteValue.matchedVersion,
1854
1943
  }, traverse, false, memo, undefined);
1855
1944
  }
1856
1945
  }
1857
1946
  }
1858
1947
  }
1859
- const isExisted = (type, url)=>{
1948
+ const isExisted = (type, url) => {
1860
1949
  return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
1861
1950
  };
1862
1951
  // eslint-disable-next-line max-lines-per-function
@@ -1870,15 +1959,17 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1870
1959
  const { preloadConfig: rootPreloadConfig } = preloadOptions;
1871
1960
  const { depsRemote } = rootPreloadConfig;
1872
1961
  const memo = {};
1873
- traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot)=>{
1962
+ traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot) => {
1874
1963
  let preloadConfig;
1875
1964
  if (isRoot) {
1876
1965
  preloadConfig = rootPreloadConfig;
1877
- } else {
1966
+ }
1967
+ else {
1878
1968
  if (Array.isArray(depsRemote)) {
1879
1969
  // eslint-disable-next-line array-callback-return
1880
- const findPreloadConfig = depsRemote.find((remoteConfig)=>{
1881
- if (remoteConfig.nameOrAlias === remoteInfo.name || remoteConfig.nameOrAlias === remoteInfo.alias) {
1970
+ const findPreloadConfig = depsRemote.find((remoteConfig) => {
1971
+ if (remoteConfig.nameOrAlias === remoteInfo.name ||
1972
+ remoteConfig.nameOrAlias === remoteInfo.alias) {
1882
1973
  return true;
1883
1974
  }
1884
1975
  return false;
@@ -1887,9 +1978,11 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1887
1978
  return;
1888
1979
  }
1889
1980
  preloadConfig = defaultPreloadArgs(findPreloadConfig);
1890
- } else if (depsRemote === true) {
1981
+ }
1982
+ else if (depsRemote === true) {
1891
1983
  preloadConfig = rootPreloadConfig;
1892
- } else {
1984
+ }
1985
+ else {
1893
1986
  return;
1894
1987
  }
1895
1988
  }
@@ -1900,27 +1993,33 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1900
1993
  moduleInfo: {
1901
1994
  name: remoteInfo.name,
1902
1995
  entry: remoteEntryUrl,
1903
- type: 'remoteEntryType' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntryType : 'global',
1904
- entryGlobalName: 'globalName' in moduleInfoSnapshot ? moduleInfoSnapshot.globalName : remoteInfo.name,
1996
+ type: 'remoteEntryType' in moduleInfoSnapshot
1997
+ ? moduleInfoSnapshot.remoteEntryType
1998
+ : 'global',
1999
+ entryGlobalName: 'globalName' in moduleInfoSnapshot
2000
+ ? moduleInfoSnapshot.globalName
2001
+ : remoteInfo.name,
1905
2002
  shareScope: '',
1906
- version: 'version' in moduleInfoSnapshot ? moduleInfoSnapshot.version : undefined
2003
+ version: 'version' in moduleInfoSnapshot
2004
+ ? moduleInfoSnapshot.version
2005
+ : undefined,
1907
2006
  },
1908
- url: remoteEntryUrl
2007
+ url: remoteEntryUrl,
1909
2008
  });
1910
2009
  }
1911
2010
  let moduleAssetsInfo = 'modules' in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];
1912
2011
  const normalizedPreloadExposes = normalizePreloadExposes(preloadConfig.exposes);
1913
2012
  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) {
2013
+ moduleAssetsInfo = moduleInfoSnapshot?.modules?.reduce((assets, moduleAssetInfo) => {
2014
+ if (normalizedPreloadExposes?.indexOf(moduleAssetInfo.moduleName) !==
2015
+ -1) {
1917
2016
  assets.push(moduleAssetInfo);
1918
2017
  }
1919
2018
  return assets;
1920
2019
  }, []);
1921
2020
  }
1922
2021
  function handleAssets(assets) {
1923
- const assetsRes = assets.map((asset)=>sdk.getResourceUrl(moduleInfoSnapshot, asset));
2022
+ const assetsRes = assets.map((asset) => sdk.getResourceUrl(moduleInfoSnapshot, asset));
1924
2023
  if (preloadConfig.filter) {
1925
2024
  return assetsRes.filter(preloadConfig.filter);
1926
2025
  }
@@ -1928,7 +2027,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1928
2027
  }
1929
2028
  if (moduleAssetsInfo) {
1930
2029
  const assetsLength = moduleAssetsInfo.length;
1931
- for(let index = 0; index < assetsLength; index++){
2030
+ for (let index = 0; index < assetsLength; index++) {
1932
2031
  const assetsInfo = moduleAssetsInfo[index];
1933
2032
  const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;
1934
2033
  origin.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
@@ -1937,7 +2036,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1937
2036
  remoteSnapshot: moduleInfoSnapshot,
1938
2037
  preloadConfig,
1939
2038
  remote: remoteInfo,
1940
- origin
2039
+ origin,
1941
2040
  });
1942
2041
  const preloaded = getPreloaded(exposeFullPath);
1943
2042
  if (preloaded) {
@@ -1948,8 +2047,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1948
2047
  cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
1949
2048
  jsAssets.push(...handleAssets(assetsInfo.assets.js.async));
1950
2049
  jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
1951
- // eslint-disable-next-line no-constant-condition
1952
- } else if (preloadConfig.resourceCategory = 'sync') {
2050
+ // eslint-disable-next-line no-constant-condition
2051
+ }
2052
+ else if ((preloadConfig.resourceCategory = 'sync')) {
1953
2053
  cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
1954
2054
  jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
1955
2055
  }
@@ -1958,53 +2058,54 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1958
2058
  }
1959
2059
  }, true, memo, remoteSnapshot);
1960
2060
  if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
1961
- const collectSharedAssets = (shareInfo, snapshotShared)=>{
2061
+ const collectSharedAssets = (shareInfo, snapshotShared) => {
1962
2062
  const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
1963
2063
  // If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
1964
2064
  if (registeredShared && typeof registeredShared.lib === 'function') {
1965
- snapshotShared.assets.js.sync.forEach((asset)=>{
2065
+ snapshotShared.assets.js.sync.forEach((asset) => {
1966
2066
  loadedSharedJsAssets.add(asset);
1967
2067
  });
1968
- snapshotShared.assets.css.sync.forEach((asset)=>{
2068
+ snapshotShared.assets.css.sync.forEach((asset) => {
1969
2069
  loadedSharedCssAssets.add(asset);
1970
2070
  });
1971
2071
  }
1972
2072
  };
1973
- remoteSnapshot.shared.forEach((shared)=>{
1974
- var _options_shared;
1975
- const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
2073
+ remoteSnapshot.shared.forEach((shared) => {
2074
+ const shareInfos = options.shared?.[shared.sharedName];
1976
2075
  if (!shareInfos) {
1977
2076
  return;
1978
2077
  }
1979
2078
  // if no version, preload all shared
1980
- const sharedOptions = shared.version ? shareInfos.find((s)=>s.version === shared.version) : shareInfos;
2079
+ const sharedOptions = shared.version
2080
+ ? shareInfos.find((s) => s.version === shared.version)
2081
+ : shareInfos;
1981
2082
  if (!sharedOptions) {
1982
2083
  return;
1983
2084
  }
1984
2085
  const arrayShareInfo = arrayOptions(sharedOptions);
1985
- arrayShareInfo.forEach((s)=>{
2086
+ arrayShareInfo.forEach((s) => {
1986
2087
  collectSharedAssets(s, shared);
1987
2088
  });
1988
2089
  });
1989
2090
  }
1990
- const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset) && !isExisted('script', asset));
1991
- const needPreloadCssAssets = cssAssets.filter((asset)=>!loadedSharedCssAssets.has(asset) && !isExisted('link', asset));
2091
+ const needPreloadJsAssets = jsAssets.filter((asset) => !loadedSharedJsAssets.has(asset) && !isExisted('script', asset));
2092
+ const needPreloadCssAssets = cssAssets.filter((asset) => !loadedSharedCssAssets.has(asset) && !isExisted('link', asset));
1992
2093
  return {
1993
2094
  cssAssets: needPreloadCssAssets,
1994
2095
  jsAssetsWithoutEntry: needPreloadJsAssets,
1995
- entryAssets: entryAssets.filter((entry)=>!isExisted('script', entry.url))
2096
+ entryAssets: entryAssets.filter((entry) => !isExisted('script', entry.url)),
1996
2097
  };
1997
2098
  }
1998
- const generatePreloadAssetsPlugin = function() {
2099
+ const generatePreloadAssetsPlugin = function () {
1999
2100
  return {
2000
2101
  name: 'generate-preload-assets-plugin',
2001
- async generatePreloadAssets (args) {
2002
- const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
2102
+ async generatePreloadAssets(args) {
2103
+ const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot, } = args;
2003
2104
  if (!sdk.isBrowserEnv()) {
2004
2105
  return {
2005
2106
  cssAssets: [],
2006
2107
  jsAssetsWithoutEntry: [],
2007
- entryAssets: []
2108
+ entryAssets: [],
2008
2109
  };
2009
2110
  }
2010
2111
  if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
@@ -2020,34 +2121,37 @@ const generatePreloadAssetsPlugin = function() {
2020
2121
  entry: remote.entry,
2021
2122
  type: remoteInfo.type || 'global',
2022
2123
  entryGlobalName: '',
2023
- shareScope: ''
2024
- }
2025
- }
2026
- ]
2124
+ shareScope: '',
2125
+ },
2126
+ },
2127
+ ],
2027
2128
  };
2028
2129
  }
2029
2130
  assignRemoteInfo(remoteInfo, remoteSnapshot);
2030
2131
  const assets = generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
2031
2132
  return assets;
2032
- }
2133
+ },
2033
2134
  };
2034
2135
  };
2035
2136
 
2036
2137
  function getGlobalRemoteInfo(moduleInfo, origin) {
2037
2138
  const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
2038
2139
  name: origin.name,
2039
- version: origin.options.version
2140
+ version: origin.options.version,
2040
2141
  });
2041
2142
  // get remote detail info from global
2042
- const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
2143
+ const globalRemoteInfo = hostGlobalSnapshot &&
2144
+ 'remotesInfo' in hostGlobalSnapshot &&
2145
+ hostGlobalSnapshot.remotesInfo &&
2146
+ getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
2043
2147
  if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
2044
2148
  return {
2045
2149
  hostGlobalSnapshot,
2046
2150
  globalSnapshot: getGlobalSnapshot(),
2047
2151
  remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
2048
2152
  name: moduleInfo.name,
2049
- version: globalRemoteInfo.matchedVersion
2050
- })
2153
+ version: globalRemoteInfo.matchedVersion,
2154
+ }),
2051
2155
  };
2052
2156
  }
2053
2157
  return {
@@ -2055,77 +2159,100 @@ function getGlobalRemoteInfo(moduleInfo, origin) {
2055
2159
  globalSnapshot: getGlobalSnapshot(),
2056
2160
  remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
2057
2161
  name: moduleInfo.name,
2058
- version: 'version' in moduleInfo ? moduleInfo.version : undefined
2059
- })
2162
+ version: 'version' in moduleInfo ? moduleInfo.version : undefined,
2163
+ }),
2060
2164
  };
2061
2165
  }
2062
2166
  class SnapshotHandler {
2167
+ constructor(HostInstance) {
2168
+ this.loadingHostSnapshot = null;
2169
+ this.manifestCache = new Map();
2170
+ this.hooks = new PluginSystem({
2171
+ beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
2172
+ loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
2173
+ loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot'),
2174
+ afterLoadSnapshot: new AsyncWaterfallHook('afterLoadSnapshot'),
2175
+ });
2176
+ this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
2177
+ this.HostInstance = HostInstance;
2178
+ this.loaderHook = HostInstance.loaderHook;
2179
+ }
2063
2180
  // eslint-disable-next-line max-lines-per-function
2064
- async loadRemoteSnapshotInfo({ moduleInfo, id, expose }) {
2181
+ async loadRemoteSnapshotInfo({ moduleInfo, id, expose, }) {
2065
2182
  const { options } = this.HostInstance;
2066
2183
  await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
2067
2184
  options,
2068
- moduleInfo
2185
+ moduleInfo,
2069
2186
  });
2070
2187
  let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
2071
2188
  name: this.HostInstance.options.name,
2072
- version: this.HostInstance.options.version
2189
+ version: this.HostInstance.options.version,
2073
2190
  });
2074
2191
  if (!hostSnapshot) {
2075
2192
  hostSnapshot = {
2076
2193
  version: this.HostInstance.options.version || '',
2077
2194
  remoteEntry: '',
2078
- remotesInfo: {}
2195
+ remotesInfo: {},
2079
2196
  };
2080
2197
  addGlobalSnapshot({
2081
- [this.HostInstance.options.name]: hostSnapshot
2198
+ [this.HostInstance.options.name]: hostSnapshot,
2082
2199
  });
2083
2200
  }
2084
2201
  // In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.
2085
2202
  // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
2086
- if (hostSnapshot && 'remotesInfo' in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
2203
+ if (hostSnapshot &&
2204
+ 'remotesInfo' in hostSnapshot &&
2205
+ !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
2087
2206
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
2088
- hostSnapshot.remotesInfo = polyfills._extends({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
2207
+ hostSnapshot.remotesInfo = {
2208
+ ...hostSnapshot?.remotesInfo,
2089
2209
  [moduleInfo.name]: {
2090
- matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
2091
- }
2092
- });
2210
+ matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry,
2211
+ },
2212
+ };
2093
2213
  }
2094
2214
  }
2095
2215
  const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
2096
- const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
2216
+ const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes, } = await this.hooks.lifecycle.loadSnapshot.emit({
2097
2217
  options,
2098
2218
  moduleInfo,
2099
2219
  hostGlobalSnapshot,
2100
2220
  remoteSnapshot,
2101
- globalSnapshot
2221
+ globalSnapshot,
2102
2222
  });
2103
2223
  let mSnapshot;
2104
2224
  let gSnapshot;
2105
2225
  // global snapshot includes manifest or module info includes manifest
2106
2226
  if (globalRemoteSnapshot) {
2107
2227
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
2108
- const remoteEntry = sdk.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
2228
+ const remoteEntry = sdk.isBrowserEnv()
2229
+ ? globalRemoteSnapshot.remoteEntry
2230
+ : globalRemoteSnapshot.ssrRemoteEntry ||
2231
+ globalRemoteSnapshot.remoteEntry ||
2232
+ '';
2109
2233
  const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
2110
2234
  // eslint-disable-next-line @typescript-eslint/no-shadow
2111
- const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(polyfills._extends({}, moduleInfo, {
2235
+ const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo({
2236
+ ...moduleInfo,
2112
2237
  // The global remote may be overridden
2113
2238
  // Therefore, set the snapshot key to the global address of the actual request
2114
- entry: remoteEntry
2115
- }), moduleSnapshot);
2239
+ entry: remoteEntry,
2240
+ }, moduleSnapshot);
2116
2241
  mSnapshot = moduleSnapshot;
2117
2242
  gSnapshot = globalSnapshotRes;
2118
- } else {
2243
+ }
2244
+ else {
2119
2245
  const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
2120
2246
  options: this.HostInstance.options,
2121
2247
  moduleInfo,
2122
2248
  remoteSnapshot: globalRemoteSnapshot,
2123
- from: 'global'
2249
+ from: 'global',
2124
2250
  });
2125
2251
  mSnapshot = remoteSnapshotRes;
2126
2252
  gSnapshot = globalSnapshotRes;
2127
2253
  }
2128
- } else {
2254
+ }
2255
+ else {
2129
2256
  if (isRemoteInfoWithEntry(moduleInfo)) {
2130
2257
  // get from manifest.json and merge remote info from remote server
2131
2258
  const moduleSnapshot = await this.getManifestJson(moduleInfo.entry, moduleInfo, {});
@@ -2135,15 +2262,16 @@ class SnapshotHandler {
2135
2262
  options: this.HostInstance.options,
2136
2263
  moduleInfo,
2137
2264
  remoteSnapshot: moduleSnapshot,
2138
- from: 'global'
2265
+ from: 'global',
2139
2266
  });
2140
2267
  mSnapshot = remoteSnapshotRes;
2141
2268
  gSnapshot = globalSnapshotRes;
2142
- } else {
2269
+ }
2270
+ else {
2143
2271
  error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_007, errorCodes.runtimeDescMap, {
2144
2272
  hostName: moduleInfo.name,
2145
2273
  hostVersion: moduleInfo.version,
2146
- globalSnapshot: JSON.stringify(globalSnapshotRes)
2274
+ globalSnapshot: JSON.stringify(globalSnapshotRes),
2147
2275
  }));
2148
2276
  }
2149
2277
  }
@@ -2152,18 +2280,18 @@ class SnapshotHandler {
2152
2280
  host: this.HostInstance,
2153
2281
  options,
2154
2282
  moduleInfo,
2155
- remoteSnapshot: mSnapshot
2283
+ remoteSnapshot: mSnapshot,
2156
2284
  });
2157
2285
  return {
2158
2286
  remoteSnapshot: mSnapshot,
2159
- globalSnapshot: gSnapshot
2287
+ globalSnapshot: gSnapshot,
2160
2288
  };
2161
2289
  }
2162
2290
  getGlobalRemoteInfo(moduleInfo) {
2163
2291
  return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
2164
2292
  }
2165
2293
  async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
2166
- const getManifest = async ()=>{
2294
+ const getManifest = async () => {
2167
2295
  let manifestJson = this.manifestCache.get(manifestUrl);
2168
2296
  if (manifestJson) {
2169
2297
  return manifestJson;
@@ -2173,21 +2301,23 @@ class SnapshotHandler {
2173
2301
  if (!res || !(res instanceof Response)) {
2174
2302
  res = await fetch(manifestUrl, {});
2175
2303
  }
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
- });
2304
+ manifestJson = (await res.json());
2305
+ }
2306
+ catch (err) {
2307
+ manifestJson =
2308
+ (await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
2309
+ id: manifestUrl,
2310
+ error: err,
2311
+ from: 'runtime',
2312
+ lifecycle: 'afterResolve',
2313
+ origin: this.HostInstance,
2314
+ }));
2185
2315
  if (!manifestJson) {
2186
2316
  delete this.manifestLoading[manifestUrl];
2187
2317
  error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_003, errorCodes.runtimeDescMap, {
2188
2318
  manifestUrl,
2189
2319
  moduleName: moduleInfo.name,
2190
- hostName: this.HostInstance.options.name
2320
+ hostName: this.HostInstance.options.name,
2191
2321
  }, `${err}`));
2192
2322
  }
2193
2323
  }
@@ -2195,10 +2325,10 @@ class SnapshotHandler {
2195
2325
  this.manifestCache.set(manifestUrl, manifestJson);
2196
2326
  return manifestJson;
2197
2327
  };
2198
- const asyncLoadProcess = async ()=>{
2328
+ const asyncLoadProcess = async () => {
2199
2329
  const manifestJson = await getManifest();
2200
2330
  const remoteSnapshot = sdk.generateSnapshotFromManifest(manifestJson, {
2201
- version: manifestUrl
2331
+ version: manifestUrl,
2202
2332
  });
2203
2333
  const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
2204
2334
  options: this.HostInstance.options,
@@ -2206,38 +2336,40 @@ class SnapshotHandler {
2206
2336
  manifestJson,
2207
2337
  remoteSnapshot,
2208
2338
  manifestUrl,
2209
- from: 'manifest'
2339
+ from: 'manifest',
2210
2340
  });
2211
2341
  return remoteSnapshotRes;
2212
2342
  };
2213
2343
  if (!this.manifestLoading[manifestUrl]) {
2214
- this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res)=>res);
2344
+ this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);
2215
2345
  }
2216
2346
  return this.manifestLoading[manifestUrl];
2217
2347
  }
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
2348
  }
2232
2349
 
2233
2350
  class SharedHandler {
2351
+ constructor(host) {
2352
+ this.hooks = new PluginSystem({
2353
+ afterResolve: new AsyncWaterfallHook('afterResolve'),
2354
+ beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
2355
+ // not used yet
2356
+ loadShare: new AsyncHook(),
2357
+ resolveShare: new SyncWaterfallHook('resolveShare'),
2358
+ // maybe will change, temporarily for internal use only
2359
+ initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap'),
2360
+ });
2361
+ this.host = host;
2362
+ this.shareScopeMap = {};
2363
+ this.initTokens = {};
2364
+ this._setGlobalShareScopeMap(host.options);
2365
+ }
2234
2366
  // register shared in shareScopeMap
2235
2367
  registerShared(globalOptions, userOptions) {
2236
2368
  const { shareInfos, shared } = formatShareConfigs(globalOptions, userOptions);
2237
2369
  const sharedKeys = Object.keys(shareInfos);
2238
- sharedKeys.forEach((sharedKey)=>{
2370
+ sharedKeys.forEach((sharedKey) => {
2239
2371
  const sharedVals = shareInfos[sharedKey];
2240
- sharedVals.forEach((sharedVal)=>{
2372
+ sharedVals.forEach((sharedVal) => {
2241
2373
  const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
2242
2374
  if (!registeredShared && sharedVal && sharedVal.lib) {
2243
2375
  this.setShared({
@@ -2246,14 +2378,14 @@ class SharedHandler {
2246
2378
  get: sharedVal.get,
2247
2379
  loaded: true,
2248
2380
  shared: sharedVal,
2249
- from: userOptions.name
2381
+ from: userOptions.name,
2250
2382
  });
2251
2383
  }
2252
2384
  });
2253
2385
  });
2254
2386
  return {
2255
2387
  shareInfos,
2256
- shared
2388
+ shared,
2257
2389
  };
2258
2390
  }
2259
2391
  async loadShare(pkgName, extraOptions) {
@@ -2265,12 +2397,12 @@ class SharedHandler {
2265
2397
  const shareOptions = getTargetSharedOptions({
2266
2398
  pkgName,
2267
2399
  extraOptions,
2268
- shareInfos: host.options.shared
2400
+ shareInfos: host.options.shared,
2269
2401
  });
2270
- if (shareOptions == null ? void 0 : shareOptions.scope) {
2271
- await Promise.all(shareOptions.scope.map(async (shareScope)=>{
2402
+ if (shareOptions?.scope) {
2403
+ await Promise.all(shareOptions.scope.map(async (shareScope) => {
2272
2404
  await Promise.all(this.initializeSharing(shareScope, {
2273
- strategy: shareOptions.strategy
2405
+ strategy: shareOptions.strategy,
2274
2406
  }));
2275
2407
  return;
2276
2408
  }));
@@ -2279,14 +2411,14 @@ class SharedHandler {
2279
2411
  pkgName,
2280
2412
  shareInfo: shareOptions,
2281
2413
  shared: host.options.shared,
2282
- origin: host
2414
+ origin: host,
2283
2415
  });
2284
2416
  const { shareInfo: shareOptionsRes } = loadShareRes;
2285
2417
  // Assert that shareInfoRes exists, if not, throw an error
2286
2418
  assert(shareOptionsRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
2287
2419
  // Retrieve from cache
2288
2420
  const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
2289
- const addUseIn = (shared)=>{
2421
+ const addUseIn = (shared) => {
2290
2422
  if (!shared.useIn) {
2291
2423
  shared.useIn = [];
2292
2424
  }
@@ -2295,7 +2427,10 @@ class SharedHandler {
2295
2427
  if (registeredShared && registeredShared.lib) {
2296
2428
  addUseIn(registeredShared);
2297
2429
  return registeredShared.lib;
2298
- } else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
2430
+ }
2431
+ else if (registeredShared &&
2432
+ registeredShared.loading &&
2433
+ !registeredShared.loaded) {
2299
2434
  const factory = await registeredShared.loading;
2300
2435
  registeredShared.loaded = true;
2301
2436
  if (!registeredShared.lib) {
@@ -2303,8 +2438,9 @@ class SharedHandler {
2303
2438
  }
2304
2439
  addUseIn(registeredShared);
2305
2440
  return factory;
2306
- } else if (registeredShared) {
2307
- const asyncLoadProcess = async ()=>{
2441
+ }
2442
+ else if (registeredShared) {
2443
+ const asyncLoadProcess = async () => {
2308
2444
  const factory = await registeredShared.get();
2309
2445
  addUseIn(registeredShared);
2310
2446
  registeredShared.loaded = true;
@@ -2318,14 +2454,15 @@ class SharedHandler {
2318
2454
  shared: registeredShared,
2319
2455
  from: host.options.name,
2320
2456
  lib: null,
2321
- loading
2457
+ loading,
2322
2458
  });
2323
2459
  return loading;
2324
- } else {
2325
- if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
2460
+ }
2461
+ else {
2462
+ if (extraOptions?.customShareInfo) {
2326
2463
  return false;
2327
2464
  }
2328
- const asyncLoadProcess = async ()=>{
2465
+ const asyncLoadProcess = async () => {
2329
2466
  const factory = await shareOptionsRes.get();
2330
2467
  shareOptionsRes.lib = factory;
2331
2468
  shareOptionsRes.loaded = true;
@@ -2345,7 +2482,7 @@ class SharedHandler {
2345
2482
  shared: shareOptionsRes,
2346
2483
  from: host.options.name,
2347
2484
  lib: null,
2348
- loading
2485
+ loading,
2349
2486
  });
2350
2487
  return loading;
2351
2488
  }
@@ -2354,21 +2491,23 @@ class SharedHandler {
2354
2491
  * This function initializes the sharing sequence (executed only once per share scope).
2355
2492
  * It accepts one argument, the name of the share scope.
2356
2493
  * If the share scope does not exist, it creates one.
2357
- */ // eslint-disable-next-line @typescript-eslint/member-ordering
2494
+ */
2495
+ // eslint-disable-next-line @typescript-eslint/member-ordering
2358
2496
  initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
2359
2497
  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;
2498
+ const from = extraOptions?.from;
2499
+ const strategy = extraOptions?.strategy;
2500
+ let initScope = extraOptions?.initScope;
2363
2501
  const promises = [];
2364
2502
  if (from !== 'build') {
2365
2503
  const { initTokens } = this;
2366
- if (!initScope) initScope = [];
2504
+ if (!initScope)
2505
+ initScope = [];
2367
2506
  let initToken = initTokens[shareScopeName];
2368
- if (!initToken) initToken = initTokens[shareScopeName] = {
2369
- from: this.host.name
2370
- };
2371
- if (initScope.indexOf(initToken) >= 0) return promises;
2507
+ if (!initToken)
2508
+ initToken = initTokens[shareScopeName] = { from: this.host.name };
2509
+ if (initScope.indexOf(initToken) >= 0)
2510
+ return promises;
2372
2511
  initScope.push(initToken);
2373
2512
  }
2374
2513
  const shareScope = this.shareScopeMap;
@@ -2379,34 +2518,41 @@ class SharedHandler {
2379
2518
  }
2380
2519
  // Executes all initialization snippets from all accessible modules
2381
2520
  const scope = shareScope[shareScopeName];
2382
- const register = (name, shared)=>{
2383
- var _activeVersion_shareConfig;
2521
+ const register = (name, shared) => {
2384
2522
  const { version, eager } = shared;
2385
2523
  scope[name] = scope[name] || {};
2386
2524
  const versions = scope[name];
2387
2525
  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)) {
2526
+ const activeVersionEager = Boolean(activeVersion &&
2527
+ (activeVersion.eager || activeVersion.shareConfig?.eager));
2528
+ if (!activeVersion ||
2529
+ (activeVersion.strategy !== 'loaded-first' &&
2530
+ !activeVersion.loaded &&
2531
+ (Boolean(!eager) !== !activeVersionEager
2532
+ ? eager
2533
+ : hostName > activeVersion.from))) {
2390
2534
  versions[version] = shared;
2391
2535
  }
2392
2536
  };
2393
- const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
2394
- const initRemoteModule = async (key)=>{
2537
+ const initFn = (mod) => mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
2538
+ const initRemoteModule = async (key) => {
2395
2539
  const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
2396
- id: key
2540
+ id: key,
2397
2541
  });
2398
2542
  if (module.getEntry) {
2399
2543
  let remoteEntryExports;
2400
2544
  try {
2401
2545
  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
- });
2546
+ }
2547
+ catch (error) {
2548
+ remoteEntryExports =
2549
+ (await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
2550
+ id: key,
2551
+ error,
2552
+ from: 'runtime',
2553
+ lifecycle: 'beforeLoadShare',
2554
+ origin: host,
2555
+ }));
2410
2556
  }
2411
2557
  if (!module.inited) {
2412
2558
  await initFn(remoteEntryExports);
@@ -2414,17 +2560,18 @@ class SharedHandler {
2414
2560
  }
2415
2561
  }
2416
2562
  };
2417
- Object.keys(host.options.shared).forEach((shareName)=>{
2563
+ Object.keys(host.options.shared).forEach((shareName) => {
2418
2564
  const sharedArr = host.options.shared[shareName];
2419
- sharedArr.forEach((shared)=>{
2565
+ sharedArr.forEach((shared) => {
2420
2566
  if (shared.scope.includes(shareScopeName)) {
2421
2567
  register(shareName, shared);
2422
2568
  }
2423
2569
  });
2424
2570
  });
2425
2571
  // 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)=>{
2572
+ if (host.options.shareStrategy === 'version-first' ||
2573
+ strategy === 'version-first') {
2574
+ host.options.remotes.forEach((remote) => {
2428
2575
  if (remote.shareScope === shareScopeName) {
2429
2576
  promises.push(initRemoteModule(remote.name));
2430
2577
  }
@@ -2441,17 +2588,15 @@ class SharedHandler {
2441
2588
  const shareOptions = getTargetSharedOptions({
2442
2589
  pkgName,
2443
2590
  extraOptions,
2444
- shareInfos: host.options.shared
2591
+ shareInfos: host.options.shared,
2445
2592
  });
2446
- if (shareOptions == null ? void 0 : shareOptions.scope) {
2447
- shareOptions.scope.forEach((shareScope)=>{
2448
- this.initializeSharing(shareScope, {
2449
- strategy: shareOptions.strategy
2450
- });
2593
+ if (shareOptions?.scope) {
2594
+ shareOptions.scope.forEach((shareScope) => {
2595
+ this.initializeSharing(shareScope, { strategy: shareOptions.strategy });
2451
2596
  });
2452
2597
  }
2453
2598
  const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare);
2454
- const addUseIn = (shared)=>{
2599
+ const addUseIn = (shared) => {
2455
2600
  if (!shared.useIn) {
2456
2601
  shared.useIn = [];
2457
2602
  }
@@ -2477,7 +2622,7 @@ class SharedHandler {
2477
2622
  loaded: true,
2478
2623
  from: host.options.name,
2479
2624
  lib: module,
2480
- shared: registeredShared
2625
+ shared: registeredShared,
2481
2626
  });
2482
2627
  return module;
2483
2628
  }
@@ -2492,10 +2637,10 @@ class SharedHandler {
2492
2637
  if (shareOptions.get) {
2493
2638
  const module = shareOptions.get();
2494
2639
  if (module instanceof Promise) {
2495
- const errorCode = (extraOptions == null ? void 0 : extraOptions.from) === 'build' ? errorCodes.RUNTIME_005 : errorCodes.RUNTIME_006;
2640
+ const errorCode = extraOptions?.from === 'build' ? errorCodes.RUNTIME_005 : errorCodes.RUNTIME_006;
2496
2641
  throw new Error(errorCodes.getShortErrorMsg(errorCode, errorCodes.runtimeDescMap, {
2497
2642
  hostName: host.options.name,
2498
- sharedPkgName: pkgName
2643
+ sharedPkgName: pkgName,
2499
2644
  }));
2500
2645
  }
2501
2646
  shareOptions.lib = module;
@@ -2504,13 +2649,13 @@ class SharedHandler {
2504
2649
  loaded: true,
2505
2650
  from: host.options.name,
2506
2651
  lib: shareOptions.lib,
2507
- shared: shareOptions
2652
+ shared: shareOptions,
2508
2653
  });
2509
2654
  return shareOptions.lib;
2510
2655
  }
2511
2656
  throw new Error(errorCodes.getShortErrorMsg(errorCodes.RUNTIME_006, errorCodes.runtimeDescMap, {
2512
2657
  hostName: host.options.name,
2513
- sharedPkgName: pkgName
2658
+ sharedPkgName: pkgName,
2514
2659
  }));
2515
2660
  }
2516
2661
  initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
@@ -2521,18 +2666,13 @@ class SharedHandler {
2521
2666
  options: host.options,
2522
2667
  origin: host,
2523
2668
  scopeName,
2524
- hostShareScopeMap: extraOptions.hostShareScopeMap
2669
+ hostShareScopeMap: extraOptions.hostShareScopeMap,
2525
2670
  });
2526
2671
  }
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)=>{
2672
+ setShared({ pkgName, shared, from, lib, loading, loaded, get, }) {
2673
+ const { version, scope = 'default', ...shareInfo } = shared;
2674
+ const scopes = Array.isArray(scope) ? scope : [scope];
2675
+ scopes.forEach((sc) => {
2536
2676
  if (!this.shareScopeMap[sc]) {
2537
2677
  this.shareScopeMap[sc] = {};
2538
2678
  }
@@ -2540,16 +2680,14 @@ class SharedHandler {
2540
2680
  this.shareScopeMap[sc][pkgName] = {};
2541
2681
  }
2542
2682
  if (!this.shareScopeMap[sc][pkgName][version]) {
2543
- this.shareScopeMap[sc][pkgName][version] = polyfills._extends({
2683
+ this.shareScopeMap[sc][pkgName][version] = {
2544
2684
  version,
2545
- scope: [
2546
- 'default'
2547
- ]
2548
- }, shareInfo, {
2685
+ scope: ['default'],
2686
+ ...shareInfo,
2549
2687
  lib,
2550
2688
  loaded,
2551
- loading
2552
- });
2689
+ loading,
2690
+ };
2553
2691
  if (get) {
2554
2692
  this.shareScopeMap[sc][pkgName][version].get = get;
2555
2693
  }
@@ -2574,54 +2712,45 @@ class SharedHandler {
2574
2712
  globalShareScopeMap[identifier] = this.shareScopeMap;
2575
2713
  }
2576
2714
  }
2577
- constructor(host){
2715
+ }
2716
+
2717
+ class RemoteHandler {
2718
+ constructor(host) {
2578
2719
  this.hooks = new PluginSystem({
2579
- afterResolve: new AsyncWaterfallHook('afterResolve'),
2580
- beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
2720
+ beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
2721
+ registerRemote: new SyncWaterfallHook('registerRemote'),
2722
+ beforeRequest: new AsyncWaterfallHook('beforeRequest'),
2723
+ onLoad: new AsyncHook('onLoad'),
2724
+ handlePreloadModule: new SyncHook('handlePreloadModule'),
2725
+ errorLoadRemote: new AsyncHook('errorLoadRemote'),
2726
+ beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
2727
+ generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
2581
2728
  // 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')
2729
+ afterPreloadRemote: new AsyncHook(),
2730
+ loadEntry: new AsyncHook(),
2586
2731
  });
2587
2732
  this.host = host;
2588
- this.shareScopeMap = {};
2589
- this.initTokens = {};
2590
- this._setGlobalShareScopeMap(host.options);
2733
+ this.idToRemoteMap = {};
2591
2734
  }
2592
- }
2593
-
2594
- class RemoteHandler {
2595
2735
  formatAndRegisterRemote(globalOptions, userOptions) {
2596
2736
  const userRemotes = userOptions.remotes || [];
2597
- return userRemotes.reduce((res, remote)=>{
2598
- this.registerRemote(remote, res, {
2599
- force: false
2600
- });
2737
+ return userRemotes.reduce((res, remote) => {
2738
+ this.registerRemote(remote, res, { force: false });
2601
2739
  return res;
2602
2740
  }, globalOptions.remotes);
2603
2741
  }
2604
2742
  setIdToRemoteMap(id, remoteMatchInfo) {
2605
2743
  const { remote, expose } = remoteMatchInfo;
2606
2744
  const { name, alias } = remote;
2607
- this.idToRemoteMap[id] = {
2608
- name: remote.name,
2609
- expose
2610
- };
2745
+ this.idToRemoteMap[id] = { name: remote.name, expose };
2611
2746
  if (alias && id.startsWith(name)) {
2612
2747
  const idWithAlias = id.replace(name, alias);
2613
- this.idToRemoteMap[idWithAlias] = {
2614
- name: remote.name,
2615
- expose
2616
- };
2748
+ this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };
2617
2749
  return;
2618
2750
  }
2619
2751
  if (alias && id.startsWith(alias)) {
2620
2752
  const idWithName = id.replace(alias, name);
2621
- this.idToRemoteMap[idWithName] = {
2622
- name: remote.name,
2623
- expose
2624
- };
2753
+ this.idToRemoteMap[idWithName] = { name: remote.name, expose };
2625
2754
  }
2626
2755
  }
2627
2756
  // eslint-disable-next-line max-lines-per-function
@@ -2630,7 +2759,7 @@ class RemoteHandler {
2630
2759
  const { host } = this;
2631
2760
  try {
2632
2761
  const { loadFactory = true } = options || {
2633
- loadFactory: true
2762
+ loadFactory: true,
2634
2763
  };
2635
2764
  // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
2636
2765
  // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.
@@ -2640,10 +2769,10 @@ class RemoteHandler {
2640
2769
  // id: alias(app1) + expose(button) = app1/button
2641
2770
  // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
2642
2771
  const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
2643
- id
2772
+ id,
2644
2773
  });
2645
- const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
2646
- const moduleOrFactory = await module.get(idRes, expose, options, remoteSnapshot);
2774
+ const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot, } = remoteMatchInfo;
2775
+ const moduleOrFactory = (await module.get(idRes, expose, options, remoteSnapshot));
2647
2776
  const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
2648
2777
  id: idRes,
2649
2778
  pkgNameOrAlias,
@@ -2653,23 +2782,22 @@ class RemoteHandler {
2653
2782
  remote,
2654
2783
  options: moduleOptions,
2655
2784
  moduleInstance: module,
2656
- origin: host
2785
+ origin: host,
2657
2786
  });
2658
2787
  this.setIdToRemoteMap(id, remoteMatchInfo);
2659
2788
  if (typeof moduleWrapper === 'function') {
2660
2789
  return moduleWrapper;
2661
2790
  }
2662
2791
  return moduleOrFactory;
2663
- } catch (error) {
2664
- const { from = 'runtime' } = options || {
2665
- from: 'runtime'
2666
- };
2792
+ }
2793
+ catch (error) {
2794
+ const { from = 'runtime' } = options || { from: 'runtime' };
2667
2795
  const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
2668
2796
  id,
2669
2797
  error,
2670
2798
  from,
2671
2799
  lifecycle: 'onLoad',
2672
- origin: host
2800
+ origin: host,
2673
2801
  });
2674
2802
  if (!failOver) {
2675
2803
  throw error;
@@ -2683,14 +2811,14 @@ class RemoteHandler {
2683
2811
  await this.hooks.lifecycle.beforePreloadRemote.emit({
2684
2812
  preloadOps: preloadOptions,
2685
2813
  options: host.options,
2686
- origin: host
2814
+ origin: host,
2687
2815
  });
2688
2816
  const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
2689
- await Promise.all(preloadOps.map(async (ops)=>{
2817
+ await Promise.all(preloadOps.map(async (ops) => {
2690
2818
  const { remote } = ops;
2691
2819
  const remoteInfo = getRemoteInfo(remote);
2692
2820
  const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
2693
- moduleInfo: remote
2821
+ moduleInfo: remote,
2694
2822
  });
2695
2823
  const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
2696
2824
  origin: host,
@@ -2698,7 +2826,7 @@ class RemoteHandler {
2698
2826
  remote,
2699
2827
  remoteInfo,
2700
2828
  globalSnapshot,
2701
- remoteSnapshot
2829
+ remoteSnapshot,
2702
2830
  });
2703
2831
  if (!assets) {
2704
2832
  return;
@@ -2708,9 +2836,9 @@ class RemoteHandler {
2708
2836
  }
2709
2837
  registerRemotes(remotes, options) {
2710
2838
  const { host } = this;
2711
- remotes.forEach((remote)=>{
2839
+ remotes.forEach((remote) => {
2712
2840
  this.registerRemote(remote, host.options.remotes, {
2713
- force: options == null ? void 0 : options.force
2841
+ force: options?.force,
2714
2842
  });
2715
2843
  });
2716
2844
  }
@@ -2722,17 +2850,18 @@ class RemoteHandler {
2722
2850
  loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
2723
2851
  id,
2724
2852
  options: host.options,
2725
- origin: host
2853
+ origin: host,
2726
2854
  });
2727
- } catch (error) {
2728
- loadRemoteArgs = await this.hooks.lifecycle.errorLoadRemote.emit({
2855
+ }
2856
+ catch (error) {
2857
+ loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({
2729
2858
  id,
2730
2859
  options: host.options,
2731
2860
  origin: host,
2732
2861
  from: 'runtime',
2733
2862
  error,
2734
- lifecycle: 'beforeRequest'
2735
- });
2863
+ lifecycle: 'beforeRequest',
2864
+ }));
2736
2865
  if (!loadRemoteArgs) {
2737
2866
  throw error;
2738
2867
  }
@@ -2741,23 +2870,23 @@ class RemoteHandler {
2741
2870
  const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
2742
2871
  assert(remoteSplitInfo, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_004, errorCodes.runtimeDescMap, {
2743
2872
  hostName: host.options.name,
2744
- requestId: idRes
2873
+ requestId: idRes,
2745
2874
  }));
2746
2875
  const { remote: rawRemote } = remoteSplitInfo;
2747
2876
  const remoteInfo = getRemoteInfo(rawRemote);
2748
- const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(polyfills._extends({
2749
- id: idRes
2750
- }, remoteSplitInfo, {
2877
+ const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit({
2878
+ id: idRes,
2879
+ ...remoteSplitInfo,
2751
2880
  options: host.options,
2752
2881
  origin: host,
2753
- remoteInfo
2754
- }));
2882
+ remoteInfo,
2883
+ });
2755
2884
  const { remote, expose } = matchInfo;
2756
2885
  assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
2757
2886
  let module = host.moduleCache.get(remote.name);
2758
2887
  const moduleOptions = {
2759
2888
  host: host,
2760
- remoteInfo
2889
+ remoteInfo,
2761
2890
  };
2762
2891
  if (!module) {
2763
2892
  module = new Module(moduleOptions);
@@ -2766,19 +2895,18 @@ class RemoteHandler {
2766
2895
  return {
2767
2896
  module,
2768
2897
  moduleOptions,
2769
- remoteMatchInfo: matchInfo
2898
+ remoteMatchInfo: matchInfo,
2770
2899
  };
2771
2900
  }
2772
2901
  registerRemote(remote, targetRemotes, options) {
2773
2902
  const { host } = this;
2774
- const normalizeRemote = ()=>{
2903
+ const normalizeRemote = () => {
2775
2904
  if (remote.alias) {
2776
2905
  // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
2777
2906
  // 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
- });
2907
+ const findEqual = targetRemotes.find((item) => remote.alias &&
2908
+ (item.name.startsWith(remote.alias) ||
2909
+ item.alias?.startsWith(remote.alias)));
2782
2910
  assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
2783
2911
  }
2784
2912
  // Set the remote entry to a complete path
@@ -2794,32 +2922,24 @@ class RemoteHandler {
2794
2922
  remote.type = DEFAULT_REMOTE_TYPE;
2795
2923
  }
2796
2924
  };
2797
- this.hooks.lifecycle.beforeRegisterRemote.emit({
2798
- remote,
2799
- origin: host
2800
- });
2801
- const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
2925
+ this.hooks.lifecycle.beforeRegisterRemote.emit({ remote, origin: host });
2926
+ const registeredRemote = targetRemotes.find((item) => item.name === remote.name);
2802
2927
  if (!registeredRemote) {
2803
2928
  normalizeRemote();
2804
2929
  targetRemotes.push(remote);
2805
- this.hooks.lifecycle.registerRemote.emit({
2806
- remote,
2807
- origin: host
2808
- });
2809
- } else {
2930
+ this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });
2931
+ }
2932
+ else {
2810
2933
  const messages = [
2811
2934
  `The remote "${remote.name}" is already registered.`,
2812
- 'Please note that overriding it may cause unexpected errors.'
2935
+ 'Please note that overriding it may cause unexpected errors.',
2813
2936
  ];
2814
- if (options == null ? void 0 : options.force) {
2937
+ if (options?.force) {
2815
2938
  // remove registered remote
2816
2939
  this.removeRemote(registeredRemote);
2817
2940
  normalizeRemote();
2818
2941
  targetRemotes.push(remote);
2819
- this.hooks.lifecycle.registerRemote.emit({
2820
- remote,
2821
- origin: host
2822
- });
2942
+ this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });
2823
2943
  sdk.warn(messages.join(' '));
2824
2944
  }
2825
2945
  }
@@ -2828,7 +2948,7 @@ class RemoteHandler {
2828
2948
  try {
2829
2949
  const { host } = this;
2830
2950
  const { name } = remote;
2831
- const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
2951
+ const remoteIndex = host.options.remotes.findIndex((item) => item.name === name);
2832
2952
  if (remoteIndex !== -1) {
2833
2953
  host.options.remotes.splice(remoteIndex, 1);
2834
2954
  }
@@ -2837,10 +2957,10 @@ class RemoteHandler {
2837
2957
  const remoteInfo = loadedModule.remoteInfo;
2838
2958
  const key = remoteInfo.entryGlobalName;
2839
2959
  if (CurrentGlobal[key]) {
2840
- var _Object_getOwnPropertyDescriptor;
2841
- if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(CurrentGlobal, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
2960
+ if (Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable) {
2842
2961
  delete CurrentGlobal[key];
2843
- } else {
2962
+ }
2963
+ else {
2844
2964
  // @ts-ignore
2845
2965
  CurrentGlobal[key] = undefined;
2846
2966
  }
@@ -2851,11 +2971,14 @@ class RemoteHandler {
2851
2971
  }
2852
2972
  host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
2853
2973
  // 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)=>{
2974
+ let remoteInsId = remoteInfo.buildVersion
2975
+ ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)
2976
+ : remoteInfo.name;
2977
+ const remoteInsIndex = CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {
2856
2978
  if (remoteInfo.buildVersion) {
2857
2979
  return ins.options.id === remoteInsId;
2858
- } else {
2980
+ }
2981
+ else {
2859
2982
  return ins.name === remoteInsId;
2860
2983
  }
2861
2984
  });
@@ -2865,56 +2988,66 @@ class RemoteHandler {
2865
2988
  const globalShareScopeMap = getGlobalShareScope();
2866
2989
  let isAllSharedNotUsed = true;
2867
2990
  const needDeleteKeys = [];
2868
- Object.keys(globalShareScopeMap).forEach((instId)=>{
2991
+ Object.keys(globalShareScopeMap).forEach((instId) => {
2869
2992
  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
- });
2993
+ shareScopeMap &&
2994
+ Object.keys(shareScopeMap).forEach((shareScope) => {
2995
+ const shareScopeVal = shareScopeMap[shareScope];
2996
+ shareScopeVal &&
2997
+ Object.keys(shareScopeVal).forEach((shareName) => {
2998
+ const sharedPkgs = shareScopeVal[shareName];
2999
+ sharedPkgs &&
3000
+ Object.keys(sharedPkgs).forEach((shareVersion) => {
3001
+ const shared = sharedPkgs[shareVersion];
3002
+ if (shared &&
3003
+ typeof shared === 'object' &&
3004
+ shared.from === remoteInfo.name) {
3005
+ if (shared.loaded || shared.loading) {
3006
+ shared.useIn = shared.useIn.filter((usedHostName) => usedHostName !== remoteInfo.name);
3007
+ if (shared.useIn.length) {
3008
+ isAllSharedNotUsed = false;
3009
+ }
3010
+ else {
3011
+ needDeleteKeys.push([
3012
+ instId,
3013
+ shareScope,
3014
+ shareName,
3015
+ shareVersion,
3016
+ ]);
3017
+ }
3018
+ }
3019
+ else {
3020
+ needDeleteKeys.push([
3021
+ instId,
3022
+ shareScope,
3023
+ shareName,
3024
+ shareVersion,
3025
+ ]);
3026
+ }
3027
+ }
3028
+ });
3029
+ });
2899
3030
  });
2900
- });
2901
3031
  });
2902
3032
  if (isAllSharedNotUsed) {
2903
3033
  remoteIns.shareScopeMap = {};
2904
3034
  delete globalShareScopeMap[remoteInsId];
2905
3035
  }
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];
3036
+ needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion]) => {
3037
+ delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[shareVersion];
2909
3038
  });
2910
3039
  CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
2911
3040
  }
2912
3041
  const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
2913
3042
  if (hostGlobalSnapshot) {
2914
- const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
3043
+ const remoteKey = hostGlobalSnapshot &&
3044
+ 'remotesInfo' in hostGlobalSnapshot &&
3045
+ hostGlobalSnapshot.remotesInfo &&
3046
+ getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
2915
3047
  if (remoteKey) {
2916
3048
  delete hostGlobalSnapshot.remotesInfo[remoteKey];
2917
- if (//eslint-disable-next-line no-extra-boolean-cast
3049
+ if (
3050
+ //eslint-disable-next-line no-extra-boolean-cast
2918
3051
  Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
2919
3052
  delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
2920
3053
  }
@@ -2922,31 +3055,68 @@ class RemoteHandler {
2922
3055
  }
2923
3056
  host.moduleCache.delete(remote.name);
2924
3057
  }
2925
- } catch (err) {
3058
+ }
3059
+ catch (err) {
2926
3060
  logger.log('removeRemote fail: ', err);
2927
3061
  }
2928
3062
  }
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
3063
  }
2947
3064
 
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
3065
+ const USE_SNAPSHOT = typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean'
3066
+ ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
3067
+ : true; // Default to true (use snapshot) when not explicitly defined
2949
3068
  class ModuleFederation {
3069
+ constructor(userOptions) {
3070
+ this.hooks = new PluginSystem({
3071
+ beforeInit: new SyncWaterfallHook('beforeInit'),
3072
+ init: new SyncHook(),
3073
+ // maybe will change, temporarily for internal use only
3074
+ beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
3075
+ // maybe will change, temporarily for internal use only
3076
+ initContainer: new AsyncWaterfallHook('initContainer'),
3077
+ });
3078
+ this.version = "0.0.0-refactor-manifest-20251013103938";
3079
+ this.moduleCache = new Map();
3080
+ this.loaderHook = new PluginSystem({
3081
+ // FIXME: may not be suitable , not open to the public yet
3082
+ getModuleInfo: new SyncHook(),
3083
+ createScript: new SyncHook(),
3084
+ createLink: new SyncHook(),
3085
+ fetch: new AsyncHook(),
3086
+ loadEntryError: new AsyncHook(),
3087
+ getModuleFactory: new AsyncHook(),
3088
+ });
3089
+ this.bridgeHook = new PluginSystem({
3090
+ beforeBridgeRender: new SyncHook(),
3091
+ afterBridgeRender: new SyncHook(),
3092
+ beforeBridgeDestroy: new SyncHook(),
3093
+ afterBridgeDestroy: new SyncHook(),
3094
+ });
3095
+ const plugins = USE_SNAPSHOT
3096
+ ? [snapshotPlugin(), generatePreloadAssetsPlugin()]
3097
+ : [];
3098
+ // TODO: Validate the details of the options
3099
+ // Initialize options with default values
3100
+ const defaultOptions = {
3101
+ id: getBuilderId(),
3102
+ name: userOptions.name,
3103
+ plugins,
3104
+ remotes: [],
3105
+ shared: {},
3106
+ inBrowser: sdk.isBrowserEnv(),
3107
+ };
3108
+ this.name = userOptions.name;
3109
+ this.options = defaultOptions;
3110
+ this.snapshotHandler = new SnapshotHandler(this);
3111
+ this.sharedHandler = new SharedHandler(this);
3112
+ this.remoteHandler = new RemoteHandler(this);
3113
+ this.shareScopeMap = this.sharedHandler.shareScopeMap;
3114
+ this.registerPlugins([
3115
+ ...defaultOptions.plugins,
3116
+ ...(userOptions.plugins || []),
3117
+ ]);
3118
+ this.options = this.formatOptions(defaultOptions, userOptions);
3119
+ }
2950
3120
  initOptions(userOptions) {
2951
3121
  this.registerPlugins(userOptions.plugins);
2952
3122
  const options = this.formatOptions(this.options, userOptions);
@@ -2967,14 +3137,8 @@ class ModuleFederation {
2967
3137
  return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);
2968
3138
  }
2969
3139
  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
- });
3140
+ const remoteInfo = getRemoteInfo({ name, entry: url });
3141
+ const module = new Module({ host: this, remoteInfo });
2978
3142
  module.remoteEntryExports = container;
2979
3143
  this.moduleCache.set(name, module);
2980
3144
  return module;
@@ -2997,37 +3161,38 @@ class ModuleFederation {
2997
3161
  origin: this,
2998
3162
  userOptions,
2999
3163
  options: globalOptions,
3000
- shareInfo: shared
3164
+ shareInfo: shared,
3001
3165
  });
3002
3166
  const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
3003
3167
  const { shared: handledShared } = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes);
3004
- const plugins = [
3005
- ...globalOptionsRes.plugins
3006
- ];
3168
+ const plugins = [...globalOptionsRes.plugins];
3007
3169
  if (userOptionsRes.plugins) {
3008
- userOptionsRes.plugins.forEach((plugin)=>{
3170
+ userOptionsRes.plugins.forEach((plugin) => {
3009
3171
  if (!plugins.includes(plugin)) {
3010
3172
  plugins.push(plugin);
3011
3173
  }
3012
3174
  });
3013
3175
  }
3014
- const optionsRes = polyfills._extends({}, globalOptions, userOptions, {
3176
+ const optionsRes = {
3177
+ ...globalOptions,
3178
+ ...userOptions,
3015
3179
  plugins,
3016
3180
  remotes,
3017
- shared: handledShared
3018
- });
3181
+ shared: handledShared,
3182
+ };
3019
3183
  this.hooks.lifecycle.init.emit({
3020
3184
  origin: this,
3021
- options: optionsRes
3185
+ options: optionsRes,
3022
3186
  });
3023
3187
  return optionsRes;
3024
3188
  }
3025
3189
  registerPlugins(plugins) {
3026
3190
  const pluginRes = registerPlugins(plugins, this);
3027
3191
  // 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)) {
3192
+ this.options.plugins = this.options.plugins.reduce((res, plugin) => {
3193
+ if (!plugin)
3194
+ return res;
3195
+ if (res && !res.find((item) => item.name === plugin.name)) {
3031
3196
  res.push(plugin);
3032
3197
  }
3033
3198
  return res;
@@ -3037,61 +3202,10 @@ class ModuleFederation {
3037
3202
  return this.remoteHandler.registerRemotes(remotes, options);
3038
3203
  }
3039
3204
  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-20250926024003";
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()
3205
+ this.sharedHandler.registerShared(this.options, {
3206
+ ...this.options,
3207
+ shared,
3069
3208
  });
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
3209
  }
3096
3210
  }
3097
3211