@module-federation/runtime 0.0.0-next-20240508024041 → 0.0.0-next-20240511023318

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
@@ -89,8 +89,8 @@ function registerPlugins$1(plugins, hookInstances) {
89
89
  return plugins;
90
90
  }
91
91
 
92
- function _extends$6() {
93
- _extends$6 = Object.assign || function(target) {
92
+ function _extends$7() {
93
+ _extends$7 = Object.assign || function(target) {
94
94
  for(var i = 1; i < arguments.length; i++){
95
95
  var source = arguments[i];
96
96
  for(var key in source){
@@ -101,7 +101,7 @@ function _extends$6() {
101
101
  }
102
102
  return target;
103
103
  };
104
- return _extends$6.apply(this, arguments);
104
+ return _extends$7.apply(this, arguments);
105
105
  }
106
106
  async function loadEsmEntry({ entry, remoteEntryExports }) {
107
107
  return new Promise((resolve, reject)=>{
@@ -189,7 +189,7 @@ async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook
189
189
  return share.globalLoading[uniqueKey];
190
190
  }
191
191
  function getRemoteInfo(remote) {
192
- return _extends$6({}, remote, {
192
+ return _extends$7({}, remote, {
193
193
  entry: 'entry' in remote ? remote.entry : '',
194
194
  type: remote.type || share.DEFAULT_REMOTE_TYPE,
195
195
  entryGlobalName: remote.entryGlobalName || remote.name,
@@ -197,8 +197,8 @@ function getRemoteInfo(remote) {
197
197
  });
198
198
  }
199
199
 
200
- function _extends$5() {
201
- _extends$5 = Object.assign || function(target) {
200
+ function _extends$6() {
201
+ _extends$6 = Object.assign || function(target) {
202
202
  for(var i = 1; i < arguments.length; i++){
203
203
  var source = arguments[i];
204
204
  for(var key in source){
@@ -209,7 +209,7 @@ function _extends$5() {
209
209
  }
210
210
  return target;
211
211
  };
212
- return _extends$5.apply(this, arguments);
212
+ return _extends$6.apply(this, arguments);
213
213
  }
214
214
  let Module = class Module {
215
215
  async getEntry() {
@@ -271,7 +271,7 @@ let Module = class Module {
271
271
  origin: this.host
272
272
  });
273
273
  await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
274
- await this.host.hooks.lifecycle.initContainer.emit(_extends$5({}, initContainerOptions, {
274
+ await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
275
275
  remoteEntryExports
276
276
  }));
277
277
  }
@@ -481,8 +481,8 @@ class PluginSystem {
481
481
  }
482
482
  }
483
483
 
484
- function _extends$4() {
485
- _extends$4 = Object.assign || function(target) {
484
+ function _extends$5() {
485
+ _extends$5 = Object.assign || function(target) {
486
486
  for(var i = 1; i < arguments.length; i++){
487
487
  var source = arguments[i];
488
488
  for(var key in source){
@@ -493,10 +493,10 @@ function _extends$4() {
493
493
  }
494
494
  return target;
495
495
  };
496
- return _extends$4.apply(this, arguments);
496
+ return _extends$5.apply(this, arguments);
497
497
  }
498
498
  function defaultPreloadArgs(preloadConfig) {
499
- return _extends$4({
499
+ return _extends$5({
500
500
  resourceCategory: 'sync',
501
501
  share: true,
502
502
  depsRemote: true,
@@ -603,8 +603,8 @@ function preloadAssets(remoteInfo, host, assets) {
603
603
  }
604
604
  }
605
605
 
606
- function _extends$3() {
607
- _extends$3 = Object.assign || function(target) {
606
+ function _extends$4() {
607
+ _extends$4 = Object.assign || function(target) {
608
608
  for(var i = 1; i < arguments.length; i++){
609
609
  var source = arguments[i];
610
610
  for(var key in source){
@@ -615,7 +615,7 @@ function _extends$3() {
615
615
  }
616
616
  return target;
617
617
  };
618
- return _extends$3.apply(this, arguments);
618
+ return _extends$4.apply(this, arguments);
619
619
  }
620
620
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
621
621
  if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
@@ -661,7 +661,7 @@ function snapshotPlugin() {
661
661
  if (assets) {
662
662
  preloadAssets(remoteInfo, origin, assets);
663
663
  }
664
- return _extends$3({}, args, {
664
+ return _extends$4({}, args, {
665
665
  remoteSnapshot
666
666
  });
667
667
  }
@@ -882,8 +882,8 @@ const generatePreloadAssetsPlugin = function() {
882
882
  };
883
883
  };
884
884
 
885
- function _extends$2() {
886
- _extends$2 = Object.assign || function(target) {
885
+ function _extends$3() {
886
+ _extends$3 = Object.assign || function(target) {
887
887
  for(var i = 1; i < arguments.length; i++){
888
888
  var source = arguments[i];
889
889
  for(var key in source){
@@ -894,7 +894,7 @@ function _extends$2() {
894
894
  }
895
895
  return target;
896
896
  };
897
- return _extends$2.apply(this, arguments);
897
+ return _extends$3.apply(this, arguments);
898
898
  }
899
899
  class SnapshotHandler {
900
900
  async loadSnapshot(moduleInfo) {
@@ -937,7 +937,7 @@ class SnapshotHandler {
937
937
  // 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.
938
938
  if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
939
939
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
940
- hostSnapshot.remotesInfo = _extends$2({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
940
+ hostSnapshot.remotesInfo = _extends$3({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
941
941
  [moduleInfo.name]: {
942
942
  matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
943
943
  }
@@ -957,7 +957,7 @@ class SnapshotHandler {
957
957
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
958
958
  const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
959
959
  // eslint-disable-next-line @typescript-eslint/no-shadow
960
- const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$2({}, moduleInfo, {
960
+ const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
961
961
  // The global remote may be overridden
962
962
  // Therefore, set the snapshot key to the global address of the actual request
963
963
  entry: globalRemoteSnapshot.remoteEntry
@@ -1085,8 +1085,8 @@ class SnapshotHandler {
1085
1085
  }
1086
1086
  }
1087
1087
 
1088
- function _extends$1() {
1089
- _extends$1 = Object.assign || function(target) {
1088
+ function _extends$2() {
1089
+ _extends$2 = Object.assign || function(target) {
1090
1090
  for(var i = 1; i < arguments.length; i++){
1091
1091
  var source = arguments[i];
1092
1092
  for(var key in source){
@@ -1097,7 +1097,7 @@ function _extends$1() {
1097
1097
  }
1098
1098
  return target;
1099
1099
  };
1100
- return _extends$1.apply(this, arguments);
1100
+ return _extends$2.apply(this, arguments);
1101
1101
  }
1102
1102
  function _object_without_properties_loose(source, excluded) {
1103
1103
  if (source == null) return {};
@@ -1114,7 +1114,7 @@ function _object_without_properties_loose(source, excluded) {
1114
1114
  class SharedHandler {
1115
1115
  formatShareConfigs(globalOptions, userOptions) {
1116
1116
  const shareInfos = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
1117
- const shared = _extends$1({}, globalOptions.shared);
1117
+ const shared = _extends$2({}, globalOptions.shared);
1118
1118
  Object.keys(shareInfos).forEach((shareKey)=>{
1119
1119
  if (!shared[shareKey]) {
1120
1120
  shared[shareKey] = shareInfos[shareKey];
@@ -1152,7 +1152,8 @@ class SharedHandler {
1152
1152
  });
1153
1153
  });
1154
1154
  }
1155
- async loadShare(origin, pkgName, extraOptions) {
1155
+ async loadShare(pkgName, extraOptions) {
1156
+ const { host } = this;
1156
1157
  // This function performs the following steps:
1157
1158
  // 1. Checks if the currently loaded share already exists, if not, it throws an error
1158
1159
  // 2. Searches globally for a matching share, if found, it uses it directly
@@ -1160,30 +1161,30 @@ class SharedHandler {
1160
1161
  const shareInfo = share.getTargetSharedOptions({
1161
1162
  pkgName,
1162
1163
  extraOptions,
1163
- shareInfos: origin.options.shared
1164
+ shareInfos: host.options.shared
1164
1165
  });
1165
1166
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1166
1167
  await Promise.all(shareInfo.scope.map(async (shareScope)=>{
1167
- await Promise.all(this.initializeSharing(origin, shareScope, shareInfo.strategy));
1168
+ await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
1168
1169
  return;
1169
1170
  }));
1170
1171
  }
1171
1172
  const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
1172
1173
  pkgName,
1173
1174
  shareInfo,
1174
- shared: origin.options.shared,
1175
- origin: origin
1175
+ shared: host.options.shared,
1176
+ origin: host
1176
1177
  });
1177
1178
  const { shareInfo: shareInfoRes } = loadShareRes;
1178
1179
  // Assert that shareInfoRes exists, if not, throw an error
1179
- share.assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${origin.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
1180
+ share.assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
1180
1181
  // Retrieve from cache
1181
1182
  const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
1182
1183
  const addUseIn = (shared)=>{
1183
1184
  if (!shared.useIn) {
1184
1185
  shared.useIn = [];
1185
1186
  }
1186
- share.addUniqueItem(shared.useIn, origin.options.name);
1187
+ share.addUniqueItem(shared.useIn, host.options.name);
1187
1188
  };
1188
1189
  if (registeredShared && registeredShared.lib) {
1189
1190
  addUseIn(registeredShared);
@@ -1214,7 +1215,7 @@ class SharedHandler {
1214
1215
  pkgName,
1215
1216
  loaded: false,
1216
1217
  shared: registeredShared,
1217
- from: origin.options.name,
1218
+ from: host.options.name,
1218
1219
  lib: null,
1219
1220
  loading
1220
1221
  });
@@ -1240,7 +1241,7 @@ class SharedHandler {
1240
1241
  pkgName,
1241
1242
  loaded: false,
1242
1243
  shared: shareInfoRes,
1243
- from: origin.options.name,
1244
+ from: host.options.name,
1244
1245
  lib: null,
1245
1246
  loading
1246
1247
  });
@@ -1252,9 +1253,10 @@ class SharedHandler {
1252
1253
  * It accepts one argument, the name of the share scope.
1253
1254
  * If the share scope does not exist, it creates one.
1254
1255
  */ // eslint-disable-next-line @typescript-eslint/member-ordering
1255
- initializeSharing(origin, shareScopeName = share.DEFAULT_SCOPE, strategy) {
1256
+ initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
1257
+ const { host } = this;
1256
1258
  const shareScope = this.shareScopeMap;
1257
- const hostName = origin.options.name;
1259
+ const hostName = host.options.name;
1258
1260
  // Creates a new share scope if necessary
1259
1261
  if (!shareScope[shareScopeName]) {
1260
1262
  shareScope[shareScopeName] = {};
@@ -1275,9 +1277,8 @@ class SharedHandler {
1275
1277
  const promises = [];
1276
1278
  const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
1277
1279
  const initRemoteModule = async (key)=>{
1278
- const { module } = await getRemoteModuleAndOptions({
1279
- id: key,
1280
- origin
1280
+ const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
1281
+ id: key
1281
1282
  });
1282
1283
  if (module.getEntry) {
1283
1284
  const entry = await module.getEntry();
@@ -1287,8 +1288,8 @@ class SharedHandler {
1287
1288
  }
1288
1289
  }
1289
1290
  };
1290
- Object.keys(origin.options.shared).forEach((shareName)=>{
1291
- const sharedArr = origin.options.shared[shareName];
1291
+ Object.keys(host.options.shared).forEach((shareName)=>{
1292
+ const sharedArr = host.options.shared[shareName];
1292
1293
  sharedArr.forEach((shared)=>{
1293
1294
  if (shared.scope.includes(shareScopeName)) {
1294
1295
  register(shareName, shared);
@@ -1296,7 +1297,7 @@ class SharedHandler {
1296
1297
  });
1297
1298
  });
1298
1299
  if (strategy === 'version-first') {
1299
- origin.options.remotes.forEach((remote)=>{
1300
+ host.options.remotes.forEach((remote)=>{
1300
1301
  if (remote.shareScope === shareScopeName) {
1301
1302
  promises.push(initRemoteModule(remote.name));
1302
1303
  }
@@ -1308,15 +1309,16 @@ class SharedHandler {
1308
1309
  // 1. If the loaded shared already exists globally, then it will be reused
1309
1310
  // 2. If lib exists in local shared, it will be used directly
1310
1311
  // 3. If the local get returns something other than Promise, then it will be used directly
1311
- loadShareSync(origin, pkgName, extraOptions) {
1312
+ loadShareSync(pkgName, extraOptions) {
1313
+ const { host } = this;
1312
1314
  const shareInfo = share.getTargetSharedOptions({
1313
1315
  pkgName,
1314
1316
  extraOptions,
1315
- shareInfos: origin.options.shared
1317
+ shareInfos: host.options.shared
1316
1318
  });
1317
1319
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1318
1320
  shareInfo.scope.forEach((shareScope)=>{
1319
- this.initializeSharing(origin, shareScope, shareInfo.strategy);
1321
+ this.initializeSharing(shareScope, shareInfo.strategy);
1320
1322
  });
1321
1323
  }
1322
1324
  const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
@@ -1324,14 +1326,14 @@ class SharedHandler {
1324
1326
  if (!shared.useIn) {
1325
1327
  shared.useIn = [];
1326
1328
  }
1327
- share.addUniqueItem(shared.useIn, origin.options.name);
1329
+ share.addUniqueItem(shared.useIn, host.options.name);
1328
1330
  };
1329
1331
  if (registeredShared) {
1330
1332
  if (typeof registeredShared.lib === 'function') {
1331
1333
  addUseIn(registeredShared);
1332
1334
  if (!registeredShared.loaded) {
1333
1335
  registeredShared.loaded = true;
1334
- if (registeredShared.from === origin.options.name) {
1336
+ if (registeredShared.from === host.options.name) {
1335
1337
  shareInfo.loaded = true;
1336
1338
  }
1337
1339
  }
@@ -1344,7 +1346,7 @@ class SharedHandler {
1344
1346
  this.setShared({
1345
1347
  pkgName,
1346
1348
  loaded: true,
1347
- from: origin.options.name,
1349
+ from: host.options.name,
1348
1350
  lib: module,
1349
1351
  shared: registeredShared
1350
1352
  });
@@ -1362,7 +1364,7 @@ class SharedHandler {
1362
1364
  const module = shareInfo.get();
1363
1365
  if (module instanceof Promise) {
1364
1366
  throw new Error(`
1365
- The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${origin.options.name}.
1367
+ The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${host.options.name}.
1366
1368
  Possible reasons for failure: \n
1367
1369
  1. The ${pkgName} share was registered with the 'get' attribute, but loadShare was not used beforehand.\n
1368
1370
  2. The ${pkgName} share was not registered with the 'lib' attribute.\n
@@ -1372,25 +1374,26 @@ class SharedHandler {
1372
1374
  this.setShared({
1373
1375
  pkgName,
1374
1376
  loaded: true,
1375
- from: origin.options.name,
1377
+ from: host.options.name,
1376
1378
  lib: shareInfo.lib,
1377
1379
  shared: shareInfo
1378
1380
  });
1379
1381
  return shareInfo.lib;
1380
1382
  }
1381
1383
  throw new Error(`
1382
- The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${origin.options.name}.
1384
+ The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${host.options.name}.
1383
1385
  Possible reasons for failure: \n
1384
1386
  1. The ${pkgName} share was registered with the 'get' attribute, but loadShare was not used beforehand.\n
1385
1387
  2. The ${pkgName} share was not registered with the 'lib' attribute.\n
1386
1388
  `);
1387
1389
  }
1388
- initShareScopeMap(origin, scopeName, shareScope) {
1390
+ initShareScopeMap(scopeName, shareScope) {
1391
+ const { host } = this;
1389
1392
  this.shareScopeMap[scopeName] = shareScope;
1390
1393
  this.hooks.lifecycle.initContainerShareScopeMap.emit({
1391
1394
  shareScope,
1392
- options: origin.options,
1393
- origin: origin
1395
+ options: host.options,
1396
+ origin: host
1394
1397
  });
1395
1398
  }
1396
1399
  setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
@@ -1411,7 +1414,7 @@ class SharedHandler {
1411
1414
  if (this.shareScopeMap[sc][pkgName][version]) {
1412
1415
  return;
1413
1416
  }
1414
- this.shareScopeMap[sc][pkgName][version] = _extends$1({
1417
+ this.shareScopeMap[sc][pkgName][version] = _extends$2({
1415
1418
  version,
1416
1419
  scope: [
1417
1420
  'default'
@@ -1433,7 +1436,7 @@ class SharedHandler {
1433
1436
  globalShareScopeMap[identifier] = this.shareScopeMap;
1434
1437
  }
1435
1438
  }
1436
- constructor(hostOptions){
1439
+ constructor(host){
1437
1440
  this.hooks = new PluginSystem({
1438
1441
  afterResolve: new AsyncWaterfallHook('afterResolve'),
1439
1442
  beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
@@ -1443,16 +1446,31 @@ class SharedHandler {
1443
1446
  // maybe will change, temporarily for internal use only
1444
1447
  initContainerShareScopeMap: new AsyncWaterfallHook('initContainer')
1445
1448
  });
1449
+ this.host = host;
1446
1450
  this.shareScopeMap = {};
1447
- this._setGlobalShareScopeMap(hostOptions);
1451
+ this._setGlobalShareScopeMap(host.options);
1448
1452
  }
1449
1453
  }
1450
1454
 
1455
+ function _extends$1() {
1456
+ _extends$1 = Object.assign || function(target) {
1457
+ for(var i = 1; i < arguments.length; i++){
1458
+ var source = arguments[i];
1459
+ for(var key in source){
1460
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1461
+ target[key] = source[key];
1462
+ }
1463
+ }
1464
+ }
1465
+ return target;
1466
+ };
1467
+ return _extends$1.apply(this, arguments);
1468
+ }
1451
1469
  class RemoteHandler {
1452
- formatRemote(origin, globalOptions, userOptions) {
1470
+ formatAndRegisterRemote(globalOptions, userOptions) {
1453
1471
  const userRemotes = userOptions.remotes || [];
1454
1472
  return userRemotes.reduce((res, remote)=>{
1455
- this.registerRemote(origin, remote, res, {
1473
+ this.registerRemote(remote, res, {
1456
1474
  force: false
1457
1475
  });
1458
1476
  return res;
@@ -1460,7 +1478,8 @@ class RemoteHandler {
1460
1478
  }
1461
1479
  // eslint-disable-next-line max-lines-per-function
1462
1480
  // eslint-disable-next-line @typescript-eslint/member-ordering
1463
- async loadRemote(origin, id, options) {
1481
+ async loadRemote(id, options) {
1482
+ const { host } = this;
1464
1483
  try {
1465
1484
  const { loadFactory = true } = options || {
1466
1485
  loadFactory: true
@@ -1472,9 +1491,8 @@ class RemoteHandler {
1472
1491
  // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
1473
1492
  // id: alias(app1) + expose(button) = app1/button
1474
1493
  // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
1475
- const { module, moduleOptions, remoteMatchInfo } = await getRemoteModuleAndOptions({
1476
- id,
1477
- origin: origin
1494
+ const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
1495
+ id
1478
1496
  });
1479
1497
  const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
1480
1498
  const moduleOrFactory = await module.get(expose, options);
@@ -1487,7 +1505,7 @@ class RemoteHandler {
1487
1505
  remote,
1488
1506
  options: moduleOptions,
1489
1507
  moduleInstance: module,
1490
- origin: origin
1508
+ origin: host
1491
1509
  });
1492
1510
  if (typeof moduleWrapper === 'function') {
1493
1511
  return moduleWrapper;
@@ -1502,7 +1520,7 @@ class RemoteHandler {
1502
1520
  error,
1503
1521
  from,
1504
1522
  lifecycle: 'onLoad',
1505
- origin: origin
1523
+ origin: host
1506
1524
  });
1507
1525
  if (!failOver) {
1508
1526
  throw error;
@@ -1511,19 +1529,20 @@ class RemoteHandler {
1511
1529
  }
1512
1530
  }
1513
1531
  // eslint-disable-next-line @typescript-eslint/member-ordering
1514
- async preloadRemote(origin, preloadOptions) {
1532
+ async preloadRemote(preloadOptions) {
1533
+ const { host } = this;
1515
1534
  await this.hooks.lifecycle.beforePreloadRemote.emit({
1516
1535
  preloadOptions,
1517
- options: origin.options,
1518
- origin: origin
1536
+ options: host.options,
1537
+ origin: host
1519
1538
  });
1520
- const preloadOps = formatPreloadArgs(origin.options.remotes, preloadOptions);
1539
+ const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
1521
1540
  await Promise.all(preloadOps.map(async (ops)=>{
1522
1541
  const { remote } = ops;
1523
1542
  const remoteInfo = getRemoteInfo(remote);
1524
- const { globalSnapshot, remoteSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo(remote);
1543
+ const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo(remote);
1525
1544
  const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
1526
- origin: origin,
1545
+ origin: host,
1527
1546
  preloadOptions: ops,
1528
1547
  remote,
1529
1548
  remoteInfo,
@@ -1533,36 +1552,77 @@ class RemoteHandler {
1533
1552
  if (!assets) {
1534
1553
  return;
1535
1554
  }
1536
- preloadAssets(remoteInfo, origin, assets);
1555
+ preloadAssets(remoteInfo, host, assets);
1537
1556
  }));
1538
1557
  }
1539
- registerRemotes(origin, remotes, options) {
1558
+ registerRemotes(remotes, options) {
1559
+ const { host } = this;
1540
1560
  remotes.forEach((remote)=>{
1541
- this.registerRemote(origin, remote, origin.options.remotes, {
1561
+ this.registerRemote(remote, host.options.remotes, {
1542
1562
  force: options == null ? void 0 : options.force
1543
1563
  });
1544
1564
  });
1545
1565
  }
1546
- removeRemote(origin, remote) {
1547
- const { name } = remote;
1548
- const remoteIndex = origin.options.remotes.findIndex((item)=>item.name === name);
1549
- if (remoteIndex !== -1) {
1550
- origin.options.remotes.splice(remoteIndex, 1);
1551
- }
1552
- const loadedModule = origin.moduleCache.get(remote.name);
1553
- if (loadedModule) {
1554
- const key = loadedModule.remoteInfo.entryGlobalName;
1555
- if (globalThis[key]) {
1556
- delete globalThis[key];
1557
- }
1558
- const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1559
- if (share.globalLoading[remoteEntryUniqueKey]) {
1560
- delete share.globalLoading[remoteEntryUniqueKey];
1566
+ async getRemoteModuleAndOptions(options) {
1567
+ const { host } = this;
1568
+ const { id } = options;
1569
+ let loadRemoteArgs;
1570
+ try {
1571
+ loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
1572
+ id,
1573
+ options: host.options,
1574
+ origin: host
1575
+ });
1576
+ } catch (error) {
1577
+ loadRemoteArgs = await this.hooks.lifecycle.errorLoadRemote.emit({
1578
+ id,
1579
+ options: host.options,
1580
+ origin: host,
1581
+ from: 'runtime',
1582
+ error,
1583
+ lifecycle: 'beforeRequest'
1584
+ });
1585
+ if (!loadRemoteArgs) {
1586
+ throw error;
1561
1587
  }
1562
- origin.moduleCache.delete(remote.name);
1563
1588
  }
1589
+ const { id: idRes } = loadRemoteArgs;
1590
+ const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
1591
+ share.assert(remoteSplitInfo, `
1592
+ Unable to locate ${idRes} in ${host.options.name}. Potential reasons for failure include:\n
1593
+ 1. ${idRes} was not included in the 'remotes' parameter of ${host.options.name || 'the host'}.\n
1594
+ 2. ${idRes} could not be found in the 'remotes' of ${host.options.name} with either 'name' or 'alias' attributes.
1595
+ 3. ${idRes} is not online, injected, or loaded.
1596
+ 4. ${idRes} cannot be accessed on the expected.
1597
+ 5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
1598
+ `);
1599
+ const { remote: rawRemote } = remoteSplitInfo;
1600
+ const remoteInfo = getRemoteInfo(rawRemote);
1601
+ const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends$1({
1602
+ id: idRes
1603
+ }, remoteSplitInfo, {
1604
+ options: host.options,
1605
+ origin: host,
1606
+ remoteInfo
1607
+ }));
1608
+ const { remote, expose } = matchInfo;
1609
+ share.assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
1610
+ let module = host.moduleCache.get(remote.name);
1611
+ const moduleOptions = {
1612
+ host: host,
1613
+ remoteInfo
1614
+ };
1615
+ if (!module) {
1616
+ module = new Module(moduleOptions);
1617
+ host.moduleCache.set(remote.name, module);
1618
+ }
1619
+ return {
1620
+ module,
1621
+ moduleOptions,
1622
+ remoteMatchInfo: matchInfo
1623
+ };
1564
1624
  }
1565
- registerRemote(origin, remote, targetRemotes, options) {
1625
+ registerRemote(remote, targetRemotes, options) {
1566
1626
  const normalizeRemote = ()=>{
1567
1627
  if (remote.alias) {
1568
1628
  // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
@@ -1597,14 +1657,34 @@ class RemoteHandler {
1597
1657
  ];
1598
1658
  if (options == null ? void 0 : options.force) {
1599
1659
  // remove registered remote
1600
- this.removeRemote(origin, registeredRemote);
1660
+ this.removeRemote(registeredRemote);
1601
1661
  normalizeRemote();
1602
1662
  targetRemotes.push(remote);
1603
1663
  }
1604
1664
  sdk.warn(messages.join(' '));
1605
1665
  }
1606
1666
  }
1607
- constructor(){
1667
+ removeRemote(remote) {
1668
+ const { host } = this;
1669
+ const { name } = remote;
1670
+ const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1671
+ if (remoteIndex !== -1) {
1672
+ host.options.remotes.splice(remoteIndex, 1);
1673
+ }
1674
+ const loadedModule = host.moduleCache.get(remote.name);
1675
+ if (loadedModule) {
1676
+ const key = loadedModule.remoteInfo.entryGlobalName;
1677
+ if (globalThis[key]) {
1678
+ delete globalThis[key];
1679
+ }
1680
+ const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1681
+ if (share.globalLoading[remoteEntryUniqueKey]) {
1682
+ delete share.globalLoading[remoteEntryUniqueKey];
1683
+ }
1684
+ host.moduleCache.delete(remote.name);
1685
+ }
1686
+ }
1687
+ constructor(host){
1608
1688
  this.hooks = new PluginSystem({
1609
1689
  beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1610
1690
  onLoad: new AsyncHook('onLoad'),
@@ -1615,6 +1695,7 @@ class RemoteHandler {
1615
1695
  // not used yet
1616
1696
  afterPreloadRemote: new AsyncHook()
1617
1697
  });
1698
+ this.host = host;
1618
1699
  }
1619
1700
  }
1620
1701
 
@@ -1632,64 +1713,6 @@ function _extends() {
1632
1713
  };
1633
1714
  return _extends.apply(this, arguments);
1634
1715
  }
1635
- async function getRemoteModuleAndOptions(options) {
1636
- const { id, origin } = options;
1637
- let loadRemoteArgs;
1638
- try {
1639
- loadRemoteArgs = await origin.remoteHandler.hooks.lifecycle.beforeRequest.emit({
1640
- id,
1641
- options: origin.options,
1642
- origin: origin
1643
- });
1644
- } catch (error) {
1645
- loadRemoteArgs = await origin.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
1646
- id,
1647
- options: origin.options,
1648
- origin: origin,
1649
- from: 'runtime',
1650
- error,
1651
- lifecycle: 'beforeRequest'
1652
- });
1653
- if (!loadRemoteArgs) {
1654
- throw error;
1655
- }
1656
- }
1657
- const { id: idRes } = loadRemoteArgs;
1658
- const remoteSplitInfo = matchRemoteWithNameAndExpose(origin.options.remotes, idRes);
1659
- share.assert(remoteSplitInfo, `
1660
- Unable to locate ${idRes} in ${origin.options.name}. Potential reasons for failure include:\n
1661
- 1. ${idRes} was not included in the 'remotes' parameter of ${origin.options.name || 'the host'}.\n
1662
- 2. ${idRes} could not be found in the 'remotes' of ${origin.options.name} with either 'name' or 'alias' attributes.
1663
- 3. ${idRes} is not online, injected, or loaded.
1664
- 4. ${idRes} cannot be accessed on the expected.
1665
- 5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
1666
- `);
1667
- const { remote: rawRemote } = remoteSplitInfo;
1668
- const remoteInfo = getRemoteInfo(rawRemote);
1669
- const matchInfo = await origin.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends({
1670
- id: idRes
1671
- }, remoteSplitInfo, {
1672
- options: origin.options,
1673
- origin: origin,
1674
- remoteInfo
1675
- }));
1676
- const { remote, expose } = matchInfo;
1677
- share.assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
1678
- let module = origin.moduleCache.get(remote.name);
1679
- const moduleOptions = {
1680
- host: origin,
1681
- remoteInfo
1682
- };
1683
- if (!module) {
1684
- module = new Module(moduleOptions);
1685
- origin.moduleCache.set(remote.name, module);
1686
- }
1687
- return {
1688
- module,
1689
- moduleOptions,
1690
- remoteMatchInfo: matchInfo
1691
- };
1692
- }
1693
1716
  class FederationHost {
1694
1717
  initOptions(userOptions) {
1695
1718
  this.registerPlugins(userOptions.plugins);
@@ -1698,17 +1721,17 @@ class FederationHost {
1698
1721
  return options;
1699
1722
  }
1700
1723
  async loadShare(pkgName, extraOptions) {
1701
- return this.sharedHandler.loadShare(this, pkgName, extraOptions);
1724
+ return this.sharedHandler.loadShare(pkgName, extraOptions);
1702
1725
  }
1703
1726
  // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
1704
1727
  // 1. If the loaded shared already exists globally, then it will be reused
1705
1728
  // 2. If lib exists in local shared, it will be used directly
1706
1729
  // 3. If the local get returns something other than Promise, then it will be used directly
1707
1730
  loadShareSync(pkgName, extraOptions) {
1708
- return this.sharedHandler.loadShareSync(this, pkgName, extraOptions);
1731
+ return this.sharedHandler.loadShareSync(pkgName, extraOptions);
1709
1732
  }
1710
1733
  initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
1711
- return this.sharedHandler.initializeSharing(this, shareScopeName, strategy);
1734
+ return this.sharedHandler.initializeSharing(shareScopeName, strategy);
1712
1735
  }
1713
1736
  initRawContainer(name, url, container) {
1714
1737
  const remoteInfo = getRemoteInfo({
@@ -1726,25 +1749,26 @@ class FederationHost {
1726
1749
  // eslint-disable-next-line max-lines-per-function
1727
1750
  // eslint-disable-next-line @typescript-eslint/member-ordering
1728
1751
  async loadRemote(id, options) {
1729
- return this.remoteHandler.loadRemote(this, id, options);
1752
+ return this.remoteHandler.loadRemote(id, options);
1730
1753
  }
1731
1754
  // eslint-disable-next-line @typescript-eslint/member-ordering
1732
1755
  async preloadRemote(preloadOptions) {
1733
- return this.remoteHandler.preloadRemote(this, preloadOptions);
1756
+ return this.remoteHandler.preloadRemote(preloadOptions);
1734
1757
  }
1735
1758
  initShareScopeMap(scopeName, shareScope) {
1736
- this.sharedHandler.initShareScopeMap(this, scopeName, shareScope);
1759
+ this.sharedHandler.initShareScopeMap(scopeName, shareScope);
1737
1760
  }
1738
1761
  formatOptions(globalOptions, userOptions) {
1739
- const { shared, shareInfos } = this.sharedHandler.formatShareConfigs(globalOptions, userOptions);
1762
+ const { shared } = this.sharedHandler.formatShareConfigs(globalOptions, userOptions);
1740
1763
  const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
1741
1764
  origin: this,
1742
1765
  userOptions,
1743
1766
  options: globalOptions,
1744
1767
  shareInfo: shared
1745
1768
  });
1746
- const remotes = this.remoteHandler.formatRemote(this, globalOptionsRes, userOptionsRes);
1747
- this.sharedHandler.registerShared(shareInfos, userOptions);
1769
+ const { shared: handledShared, shareInfos: handledShareInfos } = this.sharedHandler.formatShareConfigs(globalOptions, userOptions);
1770
+ const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
1771
+ this.sharedHandler.registerShared(handledShareInfos, userOptions);
1748
1772
  const plugins = [
1749
1773
  ...globalOptionsRes.plugins
1750
1774
  ];
@@ -1758,7 +1782,7 @@ class FederationHost {
1758
1782
  const optionsRes = _extends({}, globalOptions, userOptions, {
1759
1783
  plugins,
1760
1784
  remotes,
1761
- shared
1785
+ shared: handledShared
1762
1786
  });
1763
1787
  this.hooks.lifecycle.init.emit({
1764
1788
  origin: this,
@@ -1784,7 +1808,7 @@ class FederationHost {
1784
1808
  }, pluginRes || []);
1785
1809
  }
1786
1810
  registerRemotes(remotes, options) {
1787
- return this.remoteHandler.registerRemotes(this, remotes, options);
1811
+ return this.remoteHandler.registerRemotes(remotes, options);
1788
1812
  }
1789
1813
  constructor(userOptions){
1790
1814
  this.hooks = new PluginSystem({
@@ -1795,7 +1819,7 @@ class FederationHost {
1795
1819
  // maybe will change, temporarily for internal use only
1796
1820
  initContainer: new AsyncWaterfallHook('initContainer')
1797
1821
  });
1798
- this.version = "0.1.11";
1822
+ this.version = "0.1.12";
1799
1823
  this.moduleCache = new Map();
1800
1824
  this.loaderHook = new PluginSystem({
1801
1825
  // FIXME: may not be suitable , not open to the public yet
@@ -1821,8 +1845,8 @@ class FederationHost {
1821
1845
  this.name = userOptions.name;
1822
1846
  this.options = defaultOptions;
1823
1847
  this.snapshotHandler = new SnapshotHandler(this);
1824
- this.sharedHandler = new SharedHandler(this.options);
1825
- this.remoteHandler = new RemoteHandler();
1848
+ this.sharedHandler = new SharedHandler(this);
1849
+ this.remoteHandler = new RemoteHandler(this);
1826
1850
  this.shareScopeMap = this.sharedHandler.shareScopeMap;
1827
1851
  this.registerPlugins([
1828
1852
  ...defaultOptions.plugins,