@module-federation/runtime-core 0.19.1 → 0.21.0

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