@module-federation/runtime 0.0.0-next-20240830100524 → 0.0.0-next-20240902023803

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var share = require('./share.cjs.js');
5
+ var _extends = require('@swc/helpers/_/_extends');
6
6
  var sdk = require('@module-federation/sdk');
7
+ var share = require('./share.cjs.js');
8
+ var _object_without_properties_loose = require('@swc/helpers/_/_object_without_properties_loose');
7
9
 
8
10
  // Function to match a remote with its name and expose
9
11
  // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
@@ -69,20 +71,26 @@ function matchRemote(remotes, nameOrAlias) {
69
71
  return;
70
72
  }
71
73
 
72
- function _extends$7() {
73
- _extends$7 = Object.assign || function(target) {
74
- for(var i = 1; i < arguments.length; i++){
75
- var source = arguments[i];
76
- for(var key in source){
77
- if (Object.prototype.hasOwnProperty.call(source, key)) {
78
- target[key] = source[key];
79
- }
74
+ function registerPlugins$1(plugins, hookInstances) {
75
+ const globalPlugins = share.getGlobalHostPlugins();
76
+ // Incorporate global plugins
77
+ if (globalPlugins.length > 0) {
78
+ globalPlugins.forEach((plugin)=>{
79
+ if (plugins == null ? void 0 : plugins.find((item)=>item.name !== plugin.name)) {
80
+ plugins.push(plugin);
80
81
  }
81
- }
82
- return target;
83
- };
84
- return _extends$7.apply(this, arguments);
82
+ });
83
+ }
84
+ if (plugins && plugins.length > 0) {
85
+ plugins.forEach((plugin)=>{
86
+ hookInstances.forEach((hookInstance)=>{
87
+ hookInstance.applyPlugin(plugin);
88
+ });
89
+ });
90
+ }
91
+ return plugins;
85
92
  }
93
+
86
94
  async function loadEsmEntry({ entry, remoteEntryExports }) {
87
95
  return new Promise((resolve, reject)=>{
88
96
  try {
@@ -245,7 +253,7 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
245
253
  return share.globalLoading[uniqueKey];
246
254
  }
247
255
  function getRemoteInfo(remote) {
248
- return _extends$7({}, remote, {
256
+ return _extends._({}, remote, {
249
257
  entry: 'entry' in remote ? remote.entry : '',
250
258
  type: remote.type || share.DEFAULT_REMOTE_TYPE,
251
259
  entryGlobalName: remote.entryGlobalName || remote.name,
@@ -253,20 +261,6 @@ function getRemoteInfo(remote) {
253
261
  });
254
262
  }
255
263
 
256
- function _extends$6() {
257
- _extends$6 = Object.assign || function(target) {
258
- for(var i = 1; i < arguments.length; i++){
259
- var source = arguments[i];
260
- for(var key in source){
261
- if (Object.prototype.hasOwnProperty.call(source, key)) {
262
- target[key] = source[key];
263
- }
264
- }
265
- }
266
- return target;
267
- };
268
- return _extends$6.apply(this, arguments);
269
- }
270
264
  let Module = class Module {
271
265
  async getEntry() {
272
266
  if (this.remoteEntryExports) {
@@ -278,7 +272,7 @@ let Module = class Module {
278
272
  remoteInfo: this.remoteInfo,
279
273
  remoteEntryExports: this.remoteEntryExports
280
274
  });
281
- share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${share.safeToString(this.remoteInfo)}`);
275
+ share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${sdk.safeToString(this.remoteInfo)}`);
282
276
  this.remoteEntryExports = remoteEntryExports;
283
277
  return this.remoteEntryExports;
284
278
  }
@@ -318,7 +312,7 @@ let Module = class Module {
318
312
  console.error('The remote entry interface does not contain "init"', '\n', 'Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]', '\n', 'Ensure that window[nameOfRemote] is returning a {get,init} object.');
319
313
  }
320
314
  await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
321
- await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
315
+ await this.host.hooks.lifecycle.initContainer.emit(_extends._({}, initContainerOptions, {
322
316
  remoteEntryExports
323
317
  }));
324
318
  }
@@ -367,22 +361,195 @@ let Module = class Module {
367
361
  }
368
362
  };
369
363
 
370
- function _extends$5() {
371
- _extends$5 = Object.assign || function(target) {
372
- for(var i = 1; i < arguments.length; i++){
373
- var source = arguments[i];
374
- for(var key in source){
375
- if (Object.prototype.hasOwnProperty.call(source, key)) {
376
- target[key] = source[key];
364
+ class SyncHook {
365
+ on(fn) {
366
+ if (typeof fn === 'function') {
367
+ this.listeners.add(fn);
368
+ }
369
+ }
370
+ once(fn) {
371
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
372
+ const self = this;
373
+ this.on(function wrapper(...args) {
374
+ self.remove(wrapper);
375
+ // eslint-disable-next-line prefer-spread
376
+ return fn.apply(null, args);
377
+ });
378
+ }
379
+ emit(...data) {
380
+ let result;
381
+ if (this.listeners.size > 0) {
382
+ // eslint-disable-next-line prefer-spread
383
+ this.listeners.forEach((fn)=>{
384
+ result = fn(...data);
385
+ });
386
+ }
387
+ return result;
388
+ }
389
+ remove(fn) {
390
+ this.listeners.delete(fn);
391
+ }
392
+ removeAll() {
393
+ this.listeners.clear();
394
+ }
395
+ constructor(type){
396
+ this.type = '';
397
+ this.listeners = new Set();
398
+ if (type) {
399
+ this.type = type;
400
+ }
401
+ }
402
+ }
403
+
404
+ class AsyncHook extends SyncHook {
405
+ emit(...data) {
406
+ let result;
407
+ const ls = Array.from(this.listeners);
408
+ if (ls.length > 0) {
409
+ let i = 0;
410
+ const call = (prev)=>{
411
+ if (prev === false) {
412
+ return false; // Abort process
413
+ } else if (i < ls.length) {
414
+ return Promise.resolve(ls[i++].apply(null, data)).then(call);
415
+ } else {
416
+ return prev;
377
417
  }
418
+ };
419
+ result = call();
420
+ }
421
+ return Promise.resolve(result);
422
+ }
423
+ }
424
+
425
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
426
+ function checkReturnData(originalData, returnedData) {
427
+ if (!share.isObject(returnedData)) {
428
+ return false;
429
+ }
430
+ if (originalData !== returnedData) {
431
+ // eslint-disable-next-line no-restricted-syntax
432
+ for(const key in originalData){
433
+ if (!(key in returnedData)) {
434
+ return false;
378
435
  }
379
436
  }
380
- return target;
381
- };
382
- return _extends$5.apply(this, arguments);
437
+ }
438
+ return true;
439
+ }
440
+ class SyncWaterfallHook extends SyncHook {
441
+ emit(data) {
442
+ if (!share.isObject(data)) {
443
+ share.error(`The data for the "${this.type}" hook should be an object.`);
444
+ }
445
+ for (const fn of this.listeners){
446
+ try {
447
+ const tempData = fn(data);
448
+ if (checkReturnData(data, tempData)) {
449
+ data = tempData;
450
+ } else {
451
+ this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
452
+ break;
453
+ }
454
+ } catch (e) {
455
+ share.warn(e);
456
+ this.onerror(e);
457
+ }
458
+ }
459
+ return data;
460
+ }
461
+ constructor(type){
462
+ super();
463
+ this.onerror = share.error;
464
+ this.type = type;
465
+ }
466
+ }
467
+
468
+ class AsyncWaterfallHook extends SyncHook {
469
+ emit(data) {
470
+ if (!share.isObject(data)) {
471
+ share.error(`The response data for the "${this.type}" hook must be an object.`);
472
+ }
473
+ const ls = Array.from(this.listeners);
474
+ if (ls.length > 0) {
475
+ let i = 0;
476
+ const processError = (e)=>{
477
+ share.warn(e);
478
+ this.onerror(e);
479
+ return data;
480
+ };
481
+ const call = (prevData)=>{
482
+ if (checkReturnData(data, prevData)) {
483
+ data = prevData;
484
+ if (i < ls.length) {
485
+ try {
486
+ return Promise.resolve(ls[i++](data)).then(call, processError);
487
+ } catch (e) {
488
+ return processError(e);
489
+ }
490
+ }
491
+ } else {
492
+ this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
493
+ }
494
+ return data;
495
+ };
496
+ return Promise.resolve(call(data));
497
+ }
498
+ return Promise.resolve(data);
499
+ }
500
+ constructor(type){
501
+ super();
502
+ this.onerror = share.error;
503
+ this.type = type;
504
+ }
505
+ }
506
+
507
+ class PluginSystem {
508
+ applyPlugin(plugin) {
509
+ share.assert(share.isPlainObject(plugin), 'Plugin configuration is invalid.');
510
+ // The plugin's name is mandatory and must be unique
511
+ const pluginName = plugin.name;
512
+ share.assert(pluginName, 'A name must be provided by the plugin.');
513
+ if (!this.registerPlugins[pluginName]) {
514
+ this.registerPlugins[pluginName] = plugin;
515
+ Object.keys(this.lifecycle).forEach((key)=>{
516
+ const pluginLife = plugin[key];
517
+ if (pluginLife) {
518
+ this.lifecycle[key].on(pluginLife);
519
+ }
520
+ });
521
+ }
522
+ }
523
+ removePlugin(pluginName) {
524
+ share.assert(pluginName, 'A name is required.');
525
+ const plugin = this.registerPlugins[pluginName];
526
+ share.assert(plugin, `The plugin "${pluginName}" is not registered.`);
527
+ Object.keys(plugin).forEach((key)=>{
528
+ if (key !== 'name') {
529
+ this.lifecycle[key].remove(plugin[key]);
530
+ }
531
+ });
532
+ }
533
+ // eslint-disable-next-line @typescript-eslint/no-shadow
534
+ inherit({ lifecycle, registerPlugins }) {
535
+ Object.keys(lifecycle).forEach((hookName)=>{
536
+ share.assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`);
537
+ this.lifecycle[hookName] = lifecycle[hookName];
538
+ });
539
+ Object.keys(registerPlugins).forEach((pluginName)=>{
540
+ share.assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
541
+ this.applyPlugin(registerPlugins[pluginName]);
542
+ });
543
+ }
544
+ constructor(lifecycle){
545
+ this.registerPlugins = {};
546
+ this.lifecycle = lifecycle;
547
+ this.lifecycleKeys = Object.keys(lifecycle);
548
+ }
383
549
  }
550
+
384
551
  function defaultPreloadArgs(preloadConfig) {
385
- return _extends$5({
552
+ return _extends._({
386
553
  resourceCategory: 'sync',
387
554
  share: true,
388
555
  depsRemote: true,
@@ -392,7 +559,7 @@ function defaultPreloadArgs(preloadConfig) {
392
559
  function formatPreloadArgs(remotes, preloadArgs) {
393
560
  return preloadArgs.map((args)=>{
394
561
  const remoteInfo = matchRemote(remotes, args.nameOrAlias);
395
- share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && share.safeToString({
562
+ share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && sdk.safeToString({
396
563
  remoteInfo,
397
564
  remotes
398
565
  })}`);
@@ -538,27 +705,13 @@ useLinkPreload = true) {
538
705
  }
539
706
  }
540
707
 
541
- function _extends$4() {
542
- _extends$4 = Object.assign || function(target) {
543
- for(var i = 1; i < arguments.length; i++){
544
- var source = arguments[i];
545
- for(var key in source){
546
- if (Object.prototype.hasOwnProperty.call(source, key)) {
547
- target[key] = source[key];
548
- }
549
- }
550
- }
551
- return target;
552
- };
553
- return _extends$4.apply(this, arguments);
554
- }
555
708
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
556
709
  const remoteEntryInfo = share.getRemoteEntryInfoFromSnapshot(remoteSnapshot);
557
710
  if (!remoteEntryInfo.url) {
558
711
  share.error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
559
712
  }
560
713
  let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
561
- if (!share.isBrowserEnv() && !entryUrl.startsWith('http')) {
714
+ if (!sdk.isBrowserEnv() && !entryUrl.startsWith('http')) {
562
715
  entryUrl = `https:${entryUrl}`;
563
716
  }
564
717
  remoteInfo.type = remoteEntryInfo.type;
@@ -599,7 +752,7 @@ function snapshotPlugin() {
599
752
  if (assets) {
600
753
  preloadAssets(remoteInfo, origin, assets, false);
601
754
  }
602
- return _extends$4({}, args, {
755
+ return _extends._({}, args, {
603
756
  remoteSnapshot
604
757
  });
605
758
  }
@@ -820,20 +973,6 @@ const generatePreloadAssetsPlugin = function() {
820
973
  };
821
974
  };
822
975
 
823
- function _extends$3() {
824
- _extends$3 = Object.assign || function(target) {
825
- for(var i = 1; i < arguments.length; i++){
826
- var source = arguments[i];
827
- for(var key in source){
828
- if (Object.prototype.hasOwnProperty.call(source, key)) {
829
- target[key] = source[key];
830
- }
831
- }
832
- }
833
- return target;
834
- };
835
- return _extends$3.apply(this, arguments);
836
- }
837
976
  function getGlobalRemoteInfo(moduleInfo, origin) {
838
977
  const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
839
978
  name: origin.options.name,
@@ -901,7 +1040,7 @@ class SnapshotHandler {
901
1040
  // 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.
902
1041
  if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
903
1042
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
904
- hostSnapshot.remotesInfo = _extends$3({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
1043
+ hostSnapshot.remotesInfo = _extends._({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
905
1044
  [moduleInfo.name]: {
906
1045
  matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
907
1046
  }
@@ -916,21 +1055,21 @@ class SnapshotHandler {
916
1055
  remoteSnapshot,
917
1056
  globalSnapshot
918
1057
  });
919
- let mSnapshot;
920
- let gSnapshot;
921
1058
  // global snapshot includes manifest or module info includes manifest
922
1059
  if (globalRemoteSnapshot) {
923
1060
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
924
- const remoteEntry = share.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
1061
+ const remoteEntry = sdk.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
925
1062
  const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
926
1063
  // eslint-disable-next-line @typescript-eslint/no-shadow
927
- const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
1064
+ const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends._({}, moduleInfo, {
928
1065
  // The global remote may be overridden
929
1066
  // Therefore, set the snapshot key to the global address of the actual request
930
1067
  entry: remoteEntry
931
1068
  }), moduleSnapshot);
932
- mSnapshot = moduleSnapshot;
933
- gSnapshot = globalSnapshotRes;
1069
+ return {
1070
+ remoteSnapshot: moduleSnapshot,
1071
+ globalSnapshot: globalSnapshotRes
1072
+ };
934
1073
  } else {
935
1074
  const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
936
1075
  options: this.HostInstance.options,
@@ -938,8 +1077,10 @@ class SnapshotHandler {
938
1077
  remoteSnapshot: globalRemoteSnapshot,
939
1078
  from: 'global'
940
1079
  });
941
- mSnapshot = remoteSnapshotRes;
942
- gSnapshot = globalSnapshotRes;
1080
+ return {
1081
+ remoteSnapshot: remoteSnapshotRes,
1082
+ globalSnapshot: globalSnapshotRes
1083
+ };
943
1084
  }
944
1085
  } else {
945
1086
  if (share.isRemoteInfoWithEntry(moduleInfo)) {
@@ -953,8 +1094,10 @@ class SnapshotHandler {
953
1094
  remoteSnapshot: moduleSnapshot,
954
1095
  from: 'global'
955
1096
  });
956
- mSnapshot = remoteSnapshotRes;
957
- gSnapshot = globalSnapshotRes;
1097
+ return {
1098
+ remoteSnapshot: remoteSnapshotRes,
1099
+ globalSnapshot: globalSnapshotRes
1100
+ };
958
1101
  } else {
959
1102
  share.error(`
960
1103
  Cannot get remoteSnapshot with the name: '${moduleInfo.name}', version: '${moduleInfo.version}' from __FEDERATION__.moduleInfo. The following reasons may be causing the problem:\n
@@ -964,15 +1107,6 @@ class SnapshotHandler {
964
1107
  `);
965
1108
  }
966
1109
  }
967
- await this.hooks.lifecycle.afterLoadSnapshot.emit({
968
- options,
969
- moduleInfo,
970
- remoteSnapshot: mSnapshot
971
- });
972
- return {
973
- remoteSnapshot: mSnapshot,
974
- globalSnapshot: gSnapshot
975
- };
976
1110
  }
977
1111
  getGlobalRemoteInfo(moduleInfo) {
978
1112
  return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
@@ -1022,11 +1156,10 @@ class SnapshotHandler {
1022
1156
  constructor(HostInstance){
1023
1157
  this.loadingHostSnapshot = null;
1024
1158
  this.manifestCache = new Map();
1025
- this.hooks = new share.PluginSystem({
1026
- beforeLoadRemoteSnapshot: new share.AsyncHook('beforeLoadRemoteSnapshot'),
1027
- loadSnapshot: new share.AsyncWaterfallHook('loadGlobalSnapshot'),
1028
- loadRemoteSnapshot: new share.AsyncWaterfallHook('loadRemoteSnapshot'),
1029
- afterLoadSnapshot: new share.AsyncWaterfallHook('afterLoadSnapshot')
1159
+ this.hooks = new PluginSystem({
1160
+ beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
1161
+ loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
1162
+ loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot')
1030
1163
  });
1031
1164
  this.manifestLoading = share.Global.__FEDERATION__.__MANIFEST_LOADING__;
1032
1165
  this.HostInstance = HostInstance;
@@ -1034,32 +1167,6 @@ class SnapshotHandler {
1034
1167
  }
1035
1168
  }
1036
1169
 
1037
- function _extends$2() {
1038
- _extends$2 = Object.assign || function(target) {
1039
- for(var i = 1; i < arguments.length; i++){
1040
- var source = arguments[i];
1041
- for(var key in source){
1042
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1043
- target[key] = source[key];
1044
- }
1045
- }
1046
- }
1047
- return target;
1048
- };
1049
- return _extends$2.apply(this, arguments);
1050
- }
1051
- function _object_without_properties_loose(source, excluded) {
1052
- if (source == null) return {};
1053
- var target = {};
1054
- var sourceKeys = Object.keys(source);
1055
- var key, i;
1056
- for(i = 0; i < sourceKeys.length; i++){
1057
- key = sourceKeys[i];
1058
- if (excluded.indexOf(key) >= 0) continue;
1059
- target[key] = source[key];
1060
- }
1061
- return target;
1062
- }
1063
1170
  class SharedHandler {
1064
1171
  // register shared in shareScopeMap
1065
1172
  registerShared(globalOptions, userOptions) {
@@ -1099,7 +1206,9 @@ class SharedHandler {
1099
1206
  });
1100
1207
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1101
1208
  await Promise.all(shareInfo.scope.map(async (shareScope)=>{
1102
- await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
1209
+ await Promise.all(this.initializeSharing(shareScope, {
1210
+ strategy: shareInfo.strategy
1211
+ }));
1103
1212
  return;
1104
1213
  }));
1105
1214
  }
@@ -1187,8 +1296,22 @@ class SharedHandler {
1187
1296
  * It accepts one argument, the name of the share scope.
1188
1297
  * If the share scope does not exist, it creates one.
1189
1298
  */ // eslint-disable-next-line @typescript-eslint/member-ordering
1190
- initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
1299
+ initializeSharing(shareScopeName = share.DEFAULT_SCOPE, extraOptions) {
1191
1300
  const { host } = this;
1301
+ const from = extraOptions == null ? void 0 : extraOptions.from;
1302
+ const strategy = extraOptions == null ? void 0 : extraOptions.strategy;
1303
+ let initScope = extraOptions == null ? void 0 : extraOptions.initScope;
1304
+ const promises = [];
1305
+ if (from !== 'build') {
1306
+ const { initTokens } = this;
1307
+ if (!initScope) initScope = [];
1308
+ let initToken = initTokens[shareScopeName];
1309
+ if (!initToken) initToken = initTokens[shareScopeName] = {
1310
+ from: this.host.name
1311
+ };
1312
+ if (initScope.indexOf(initToken) >= 0) return promises;
1313
+ initScope.push(initToken);
1314
+ }
1192
1315
  const shareScope = this.shareScopeMap;
1193
1316
  const hostName = host.options.name;
1194
1317
  // Creates a new share scope if necessary
@@ -1208,8 +1331,7 @@ class SharedHandler {
1208
1331
  versions[version] = shared;
1209
1332
  }
1210
1333
  };
1211
- const promises = [];
1212
- const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
1334
+ const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
1213
1335
  const initRemoteModule = async (key)=>{
1214
1336
  const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
1215
1337
  id: key
@@ -1217,7 +1339,7 @@ class SharedHandler {
1217
1339
  if (module.getEntry) {
1218
1340
  const entry = await module.getEntry();
1219
1341
  if (!module.inited) {
1220
- initFn(entry);
1342
+ await initFn(entry);
1221
1343
  module.inited = true;
1222
1344
  }
1223
1345
  }
@@ -1253,7 +1375,9 @@ class SharedHandler {
1253
1375
  });
1254
1376
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1255
1377
  shareInfo.scope.forEach((shareScope)=>{
1256
- this.initializeSharing(shareScope, shareInfo.strategy);
1378
+ this.initializeSharing(shareScope, {
1379
+ strategy: shareInfo.strategy
1380
+ });
1257
1381
  });
1258
1382
  }
1259
1383
  const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
@@ -1334,7 +1458,7 @@ class SharedHandler {
1334
1458
  });
1335
1459
  }
1336
1460
  setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
1337
- const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
1461
+ const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose._(shared, [
1338
1462
  "version",
1339
1463
  "scope"
1340
1464
  ]);
@@ -1351,7 +1475,7 @@ class SharedHandler {
1351
1475
  if (this.shareScopeMap[sc][pkgName][version]) {
1352
1476
  return;
1353
1477
  }
1354
- this.shareScopeMap[sc][pkgName][version] = _extends$2({
1478
+ this.shareScopeMap[sc][pkgName][version] = _extends._({
1355
1479
  version,
1356
1480
  scope: [
1357
1481
  'default'
@@ -1374,35 +1498,22 @@ class SharedHandler {
1374
1498
  }
1375
1499
  }
1376
1500
  constructor(host){
1377
- this.hooks = new share.PluginSystem({
1378
- afterResolve: new share.AsyncWaterfallHook('afterResolve'),
1379
- beforeLoadShare: new share.AsyncWaterfallHook('beforeLoadShare'),
1501
+ this.hooks = new PluginSystem({
1502
+ afterResolve: new AsyncWaterfallHook('afterResolve'),
1503
+ beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
1380
1504
  // not used yet
1381
- loadShare: new share.AsyncHook(),
1382
- resolveShare: new share.SyncWaterfallHook('resolveShare'),
1505
+ loadShare: new AsyncHook(),
1506
+ resolveShare: new SyncWaterfallHook('resolveShare'),
1383
1507
  // maybe will change, temporarily for internal use only
1384
- initContainerShareScopeMap: new share.SyncWaterfallHook('initContainerShareScopeMap')
1508
+ initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
1385
1509
  });
1386
1510
  this.host = host;
1387
1511
  this.shareScopeMap = {};
1512
+ this.initTokens = {};
1388
1513
  this._setGlobalShareScopeMap(host.options);
1389
1514
  }
1390
1515
  }
1391
1516
 
1392
- function _extends$1() {
1393
- _extends$1 = Object.assign || function(target) {
1394
- for(var i = 1; i < arguments.length; i++){
1395
- var source = arguments[i];
1396
- for(var key in source){
1397
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1398
- target[key] = source[key];
1399
- }
1400
- }
1401
- }
1402
- return target;
1403
- };
1404
- return _extends$1.apply(this, arguments);
1405
- }
1406
1517
  class RemoteHandler {
1407
1518
  formatAndRegisterRemote(globalOptions, userOptions) {
1408
1519
  const userRemotes = userOptions.remotes || [];
@@ -1559,7 +1670,7 @@ class RemoteHandler {
1559
1670
  `);
1560
1671
  const { remote: rawRemote } = remoteSplitInfo;
1561
1672
  const remoteInfo = getRemoteInfo(rawRemote);
1562
- const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends$1({
1673
+ const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends._({
1563
1674
  id: idRes
1564
1675
  }, remoteSplitInfo, {
1565
1676
  options: host.options,
@@ -1728,7 +1839,8 @@ class RemoteHandler {
1728
1839
  const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
1729
1840
  if (remoteKey) {
1730
1841
  delete hostGlobalSnapshot.remotesInfo[remoteKey];
1731
- if (Boolean(share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
1842
+ if (//eslint-disable-next-line no-extra-boolean-cast
1843
+ Boolean(share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
1732
1844
  delete share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
1733
1845
  }
1734
1846
  }
@@ -1740,38 +1852,24 @@ class RemoteHandler {
1740
1852
  }
1741
1853
  }
1742
1854
  constructor(host){
1743
- this.hooks = new share.PluginSystem({
1744
- beforeRegisterRemote: new share.SyncWaterfallHook('beforeRegisterRemote'),
1745
- registerRemote: new share.SyncWaterfallHook('registerRemote'),
1746
- beforeRequest: new share.AsyncWaterfallHook('beforeRequest'),
1747
- onLoad: new share.AsyncHook('onLoad'),
1748
- handlePreloadModule: new share.SyncHook('handlePreloadModule'),
1749
- errorLoadRemote: new share.AsyncHook('errorLoadRemote'),
1750
- beforePreloadRemote: new share.AsyncHook('beforePreloadRemote'),
1751
- generatePreloadAssets: new share.AsyncHook('generatePreloadAssets'),
1855
+ this.hooks = new PluginSystem({
1856
+ beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
1857
+ registerRemote: new SyncWaterfallHook('registerRemote'),
1858
+ beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1859
+ onLoad: new AsyncHook('onLoad'),
1860
+ handlePreloadModule: new SyncHook('handlePreloadModule'),
1861
+ errorLoadRemote: new AsyncHook('errorLoadRemote'),
1862
+ beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
1863
+ generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
1752
1864
  // not used yet
1753
- afterPreloadRemote: new share.AsyncHook(),
1754
- loadEntry: new share.AsyncHook()
1865
+ afterPreloadRemote: new AsyncHook(),
1866
+ loadEntry: new AsyncHook()
1755
1867
  });
1756
1868
  this.host = host;
1757
1869
  this.idToRemoteMap = {};
1758
1870
  }
1759
1871
  }
1760
1872
 
1761
- function _extends() {
1762
- _extends = Object.assign || function(target) {
1763
- for(var i = 1; i < arguments.length; i++){
1764
- var source = arguments[i];
1765
- for(var key in source){
1766
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1767
- target[key] = source[key];
1768
- }
1769
- }
1770
- }
1771
- return target;
1772
- };
1773
- return _extends.apply(this, arguments);
1774
- }
1775
1873
  class FederationHost {
1776
1874
  initOptions(userOptions) {
1777
1875
  this.registerPlugins(userOptions.plugins);
@@ -1789,8 +1887,8 @@ class FederationHost {
1789
1887
  loadShareSync(pkgName, extraOptions) {
1790
1888
  return this.sharedHandler.loadShareSync(pkgName, extraOptions);
1791
1889
  }
1792
- initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
1793
- return this.sharedHandler.initializeSharing(shareScopeName, strategy);
1890
+ initializeSharing(shareScopeName = share.DEFAULT_SCOPE, extraOptions) {
1891
+ return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);
1794
1892
  }
1795
1893
  initRawContainer(name, url, container) {
1796
1894
  const remoteInfo = getRemoteInfo({
@@ -1837,7 +1935,7 @@ class FederationHost {
1837
1935
  }
1838
1936
  });
1839
1937
  }
1840
- const optionsRes = _extends({}, globalOptions, userOptions, {
1938
+ const optionsRes = _extends._({}, globalOptions, userOptions, {
1841
1939
  plugins,
1842
1940
  remotes,
1843
1941
  shared: handledShared
@@ -1849,7 +1947,7 @@ class FederationHost {
1849
1947
  return optionsRes;
1850
1948
  }
1851
1949
  registerPlugins(plugins) {
1852
- const pluginRes = share.registerPlugins(plugins, [
1950
+ const pluginRes = registerPlugins$1(plugins, [
1853
1951
  this.hooks,
1854
1952
  this.remoteHandler.hooks,
1855
1953
  this.sharedHandler.hooks,
@@ -1869,23 +1967,23 @@ class FederationHost {
1869
1967
  return this.remoteHandler.registerRemotes(remotes, options);
1870
1968
  }
1871
1969
  constructor(userOptions){
1872
- this.hooks = new share.PluginSystem({
1873
- beforeInit: new share.SyncWaterfallHook('beforeInit'),
1874
- init: new share.SyncHook(),
1970
+ this.hooks = new PluginSystem({
1971
+ beforeInit: new SyncWaterfallHook('beforeInit'),
1972
+ init: new SyncHook(),
1875
1973
  // maybe will change, temporarily for internal use only
1876
- beforeInitContainer: new share.AsyncWaterfallHook('beforeInitContainer'),
1974
+ beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
1877
1975
  // maybe will change, temporarily for internal use only
1878
- initContainer: new share.AsyncWaterfallHook('initContainer')
1976
+ initContainer: new AsyncWaterfallHook('initContainer')
1879
1977
  });
1880
- this.version = "0.5.1";
1978
+ this.version = "0.6.0";
1881
1979
  this.moduleCache = new Map();
1882
- this.loaderHook = new share.PluginSystem({
1980
+ this.loaderHook = new PluginSystem({
1883
1981
  // FIXME: may not be suitable , not open to the public yet
1884
- getModuleInfo: new share.SyncHook(),
1885
- createScript: new share.SyncHook(),
1886
- createLink: new share.SyncHook(),
1982
+ getModuleInfo: new SyncHook(),
1983
+ createScript: new SyncHook(),
1984
+ createLink: new SyncHook(),
1887
1985
  // only work for manifest , so not open to the public yet
1888
- fetch: new share.AsyncHook()
1986
+ fetch: new AsyncHook()
1889
1987
  });
1890
1988
  // TODO: Validate the details of the options
1891
1989
  // Initialize options with default values
@@ -1898,7 +1996,7 @@ class FederationHost {
1898
1996
  ],
1899
1997
  remotes: [],
1900
1998
  shared: {},
1901
- inBrowser: share.isBrowserEnv()
1999
+ inBrowser: sdk.isBrowserEnv()
1902
2000
  };
1903
2001
  this.name = userOptions.name;
1904
2002
  this.options = defaultOptions;
@@ -1972,7 +2070,6 @@ function getInstance() {
1972
2070
  // Inject for debug
1973
2071
  share.setGlobalFederationConstructor(FederationHost);
1974
2072
 
1975
- exports.registerGlobalPlugins = share.registerGlobalPlugins;
1976
2073
  Object.defineProperty(exports, 'loadScript', {
1977
2074
  enumerable: true,
1978
2075
  get: function () { return sdk.loadScript; }
@@ -1981,6 +2078,7 @@ Object.defineProperty(exports, 'loadScriptNode', {
1981
2078
  enumerable: true,
1982
2079
  get: function () { return sdk.loadScriptNode; }
1983
2080
  });
2081
+ exports.registerGlobalPlugins = share.registerGlobalPlugins;
1984
2082
  exports.FederationHost = FederationHost;
1985
2083
  exports.getInstance = getInstance;
1986
2084
  exports.getRemoteEntry = getRemoteEntry;