@module-federation/runtime 0.0.7 → 0.0.8

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.esm.js CHANGED
@@ -1,6 +1,7 @@
1
- import { g as getGlobalHostPlugins, D as DEFAULT_REMOTE_TYPE, a as DEFAULT_SCOPE, b as globalLoading, c as getRemoteEntryExports, d as assert, s as safeToString, G as Global, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getGlobalShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, r as getGlobalSnapshot, t as addUniqueItem, u as formatShareConfigs, v as isBrowserEnv, x as getGlobalShareScope, y as getBuilderId, z as setGlobalFederationConstructor, A as getGlobalFederationInstance, B as getGlobalFederationConstructor, C as setGlobalFederationInstance } from './share.esm.js';
1
+ import { g as getGlobalHostPlugins, D as DEFAULT_REMOTE_TYPE, a as DEFAULT_SCOPE, b as globalLoading, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getRegisteredShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, r as getGlobalSnapshot, G as Global, t as getGlobalShareScope, u as formatShareConfigs, v as isBrowserEnv, x as getBuilderId, y as addUniqueItem, z as setGlobalFederationConstructor, A as getGlobalFederationInstance, B as getGlobalFederationConstructor, C as setGlobalFederationInstance } from './share.esm.js';
2
2
  export { E as registerGlobalPlugins } from './share.esm.js';
3
- import { composeKeyWithSeparator, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
3
+ import { composeKeyWithSeparator, loadScriptNode, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
4
+ export { loadScript } from '@module-federation/sdk';
4
5
 
5
6
  // Function to match a remote with its name and expose
6
7
  // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
@@ -118,6 +119,27 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
118
119
  if (remoteEntryExports) {
119
120
  return remoteEntryExports;
120
121
  }
122
+ if (typeof document === 'undefined') {
123
+ return loadScriptNode(entry, {
124
+ attrs: {
125
+ name,
126
+ globalName
127
+ },
128
+ createScriptHook
129
+ }).then(()=>{
130
+ const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
131
+ assert(entryExports, `
132
+ Unable to use the ${name}'s '${entry}' URL with ${remoteEntryKey}'s globalName to get remoteEntry exports.
133
+ Possible reasons could be:\n
134
+ 1. '${entry}' is not the correct URL, or the remoteEntry resource or name is incorrect.\n
135
+ 2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
136
+ `);
137
+ console.log(entryExports);
138
+ return entryExports;
139
+ }).catch((e)=>{
140
+ return e;
141
+ });
142
+ }
121
143
  return loadScript(entry, {
122
144
  attrs: {},
123
145
  createScriptHook
@@ -130,6 +152,8 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
130
152
  2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
131
153
  `);
132
154
  return entryExports;
155
+ }).catch((e)=>{
156
+ return e;
133
157
  });
134
158
  }
135
159
  async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
@@ -191,6 +215,10 @@ let Module = class Module {
191
215
  const res = this.host.loaderHook.lifecycle.createScript.emit({
192
216
  url
193
217
  });
218
+ if (typeof document === 'undefined') {
219
+ //todo: needs real fix
220
+ return res;
221
+ }
194
222
  if (res instanceof HTMLScriptElement) {
195
223
  return res;
196
224
  }
@@ -209,18 +237,25 @@ let Module = class Module {
209
237
  // Get remoteEntry.js
210
238
  const remoteEntryExports = await this.getEntry();
211
239
  if (!this.inited) {
212
- const globalShareScope = Global.__FEDERATION__.__SHARE__;
240
+ const localShareScopeMap = this.host.shareScopeMap;
213
241
  const remoteShareScope = this.remoteInfo.shareScope || 'default';
214
- if (!globalShareScope[remoteShareScope]) {
215
- globalShareScope[remoteShareScope] = {};
242
+ if (!localShareScopeMap[remoteShareScope]) {
243
+ localShareScopeMap[remoteShareScope] = {};
216
244
  }
217
- const shareScope = globalShareScope[remoteShareScope];
245
+ const shareScope = localShareScopeMap[remoteShareScope];
218
246
  const initScope = [];
219
247
  const remoteEntryInitOptions = {
220
248
  version: this.remoteInfo.version || ''
221
249
  };
250
+ // Help to find host instance
251
+ Object.defineProperty(remoteEntryInitOptions, 'hostId', {
252
+ value: this.host.options.id || this.host.name,
253
+ // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
254
+ enumerable: false
255
+ });
222
256
  const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
223
257
  shareScope,
258
+ // @ts-ignore hostId will be set by Object.defineProperty
224
259
  remoteEntryInitOptions,
225
260
  initScope,
226
261
  remoteInfo: this.remoteInfo,
@@ -773,9 +808,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
773
808
  if (!shareInfo) {
774
809
  return;
775
810
  }
776
- const globalShare = getGlobalShare(shared.sharedName, shareInfo);
811
+ const registeredShared = getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
777
812
  // 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.
778
- if (globalShare && typeof globalShare.lib === 'function') {
813
+ if (registeredShared && typeof registeredShared.lib === 'function') {
779
814
  shared.assets.js.sync.forEach((asset)=>{
780
815
  loadedSharedJsAssets.add(asset);
781
816
  });
@@ -1102,13 +1137,19 @@ function _object_without_properties_loose(source, excluded) {
1102
1137
  return target;
1103
1138
  }
1104
1139
  class FederationHost {
1140
+ _setGlobalShareScopeMap() {
1141
+ const globalShareScopeMap = getGlobalShareScope();
1142
+ const identifier = this.options.id || this.options.name;
1143
+ if (identifier && !globalShareScopeMap[identifier]) {
1144
+ globalShareScopeMap[identifier] = this.shareScopeMap;
1145
+ }
1146
+ }
1105
1147
  initOptions(userOptions) {
1106
1148
  this.registerPlugins(userOptions.plugins);
1107
1149
  const options = this.formatOptions(this.options, userOptions);
1108
1150
  this.options = options;
1109
1151
  return options;
1110
1152
  }
1111
- // overrideSharedOptions(shareScope: GlobalShareScope[string]): void {}
1112
1153
  async loadShare(pkgName, customShareInfo) {
1113
1154
  var _this_options_shared;
1114
1155
  // This function performs the following steps:
@@ -1116,6 +1157,12 @@ class FederationHost {
1116
1157
  // 2. Searches globally for a matching share, if found, it uses it directly
1117
1158
  // 3. If not found, it retrieves it from the current share and stores the obtained share globally.
1118
1159
  const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1160
+ if (shareInfo == null ? void 0 : shareInfo.scope) {
1161
+ await Promise.all(shareInfo.scope.map(async (shareScope)=>{
1162
+ await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
1163
+ return;
1164
+ }));
1165
+ }
1119
1166
  const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
1120
1167
  pkgName,
1121
1168
  shareInfo,
@@ -1126,30 +1173,42 @@ class FederationHost {
1126
1173
  // Assert that shareInfoRes exists, if not, throw an error
1127
1174
  assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
1128
1175
  // Retrieve from cache
1129
- const globalShare = getGlobalShare(pkgName, shareInfoRes);
1130
- if (globalShare && globalShare.lib) {
1131
- addUniqueItem(globalShare.useIn, this.options.name);
1132
- return globalShare.lib;
1133
- } else if (globalShare && globalShare.loading) {
1134
- const factory = await globalShare.loading;
1135
- addUniqueItem(globalShare.useIn, this.options.name);
1176
+ const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
1177
+ const addUseIn = (shared)=>{
1178
+ if (!shared.useIn) {
1179
+ shared.useIn = [];
1180
+ }
1181
+ addUniqueItem(shared.useIn, this.options.name);
1182
+ };
1183
+ if (registeredShared && registeredShared.lib) {
1184
+ addUseIn(registeredShared);
1185
+ return registeredShared.lib;
1186
+ } else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
1187
+ const factory = await registeredShared.loading;
1188
+ registeredShared.loaded = true;
1189
+ if (!registeredShared.lib) {
1190
+ registeredShared.lib = factory;
1191
+ }
1192
+ addUseIn(registeredShared);
1136
1193
  return factory;
1137
- } else if (globalShare) {
1194
+ } else if (registeredShared) {
1138
1195
  const asyncLoadProcess = async ()=>{
1139
- const factory = await globalShare.get();
1196
+ const factory = await registeredShared.get();
1140
1197
  shareInfoRes.lib = factory;
1141
- addUniqueItem(shareInfoRes.useIn, this.options.name);
1142
- const gShared = getGlobalShare(pkgName, shareInfoRes);
1198
+ shareInfoRes.loaded = true;
1199
+ addUseIn(shareInfoRes);
1200
+ const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
1143
1201
  if (gShared) {
1144
1202
  gShared.lib = factory;
1203
+ gShared.loaded = true;
1145
1204
  }
1146
1205
  return factory;
1147
1206
  };
1148
1207
  const loading = asyncLoadProcess();
1149
1208
  this.setShared({
1150
1209
  pkgName,
1151
- loaded: true,
1152
- shared: shareInfoRes,
1210
+ loaded: false,
1211
+ shared: registeredShared,
1153
1212
  from: this.options.name,
1154
1213
  lib: null,
1155
1214
  loading
@@ -1162,17 +1221,19 @@ class FederationHost {
1162
1221
  const asyncLoadProcess = async ()=>{
1163
1222
  const factory = await shareInfoRes.get();
1164
1223
  shareInfoRes.lib = factory;
1165
- addUniqueItem(shareInfoRes.useIn, this.options.name);
1166
- const gShared = getGlobalShare(pkgName, shareInfoRes);
1224
+ shareInfoRes.loaded = true;
1225
+ addUseIn(shareInfoRes);
1226
+ const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
1167
1227
  if (gShared) {
1168
1228
  gShared.lib = factory;
1229
+ gShared.loaded = true;
1169
1230
  }
1170
1231
  return factory;
1171
1232
  };
1172
1233
  const loading = asyncLoadProcess();
1173
1234
  this.setShared({
1174
1235
  pkgName,
1175
- loaded: true,
1236
+ loaded: false,
1176
1237
  shared: shareInfoRes,
1177
1238
  from: this.options.name,
1178
1239
  lib: null,
@@ -1185,19 +1246,46 @@ class FederationHost {
1185
1246
  // 1. If the loaded shared already exists globally, then it will be reused
1186
1247
  // 2. If lib exists in local shared, it will be used directly
1187
1248
  // 3. If the local get returns something other than Promise, then it will be used directly
1188
- loadShareSync(pkgName) {
1249
+ loadShareSync(pkgName, customShareInfo) {
1189
1250
  var _this_options_shared;
1190
- const shareInfo = (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName];
1191
- const globalShare = getGlobalShare(pkgName, shareInfo);
1192
- if (globalShare && typeof globalShare.lib === 'function') {
1193
- addUniqueItem(globalShare.useIn, this.options.name);
1194
- if (!globalShare.loaded) {
1195
- globalShare.loaded = true;
1196
- if (globalShare.from === this.options.name) {
1197
- shareInfo.loaded = true;
1251
+ const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1252
+ if (shareInfo == null ? void 0 : shareInfo.scope) {
1253
+ shareInfo.scope.forEach((shareScope)=>{
1254
+ this.initializeSharing(shareScope, shareInfo.strategy);
1255
+ });
1256
+ }
1257
+ const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
1258
+ const addUseIn = (shared)=>{
1259
+ if (!shared.useIn) {
1260
+ shared.useIn = [];
1261
+ }
1262
+ addUniqueItem(shared.useIn, this.options.name);
1263
+ };
1264
+ if (registeredShared) {
1265
+ if (typeof registeredShared.lib === 'function') {
1266
+ addUseIn(registeredShared);
1267
+ if (!registeredShared.loaded) {
1268
+ registeredShared.loaded = true;
1269
+ if (registeredShared.from === this.options.name) {
1270
+ shareInfo.loaded = true;
1271
+ }
1272
+ }
1273
+ return registeredShared.lib;
1274
+ }
1275
+ if (typeof registeredShared.get === 'function') {
1276
+ const module = registeredShared.get();
1277
+ if (!(module instanceof Promise)) {
1278
+ addUseIn(registeredShared);
1279
+ this.setShared({
1280
+ pkgName,
1281
+ loaded: true,
1282
+ from: this.options.name,
1283
+ lib: module,
1284
+ shared: registeredShared
1285
+ });
1286
+ return module;
1198
1287
  }
1199
1288
  }
1200
- return globalShare.lib;
1201
1289
  }
1202
1290
  if (shareInfo.lib) {
1203
1291
  if (!shareInfo.loaded) {
@@ -1304,11 +1392,19 @@ class FederationHost {
1304
1392
  });
1305
1393
  return moduleOrFactory;
1306
1394
  } catch (error) {
1307
- this.hooks.lifecycle.errorLoadRemote.emit({
1395
+ const { from = 'runtime' } = options || {
1396
+ from: 'runtime'
1397
+ };
1398
+ const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
1308
1399
  id,
1309
- error
1400
+ error,
1401
+ from,
1402
+ origin: this
1310
1403
  });
1311
- throw error;
1404
+ if (!failOver) {
1405
+ throw error;
1406
+ }
1407
+ return failOver;
1312
1408
  }
1313
1409
  }
1314
1410
  // eslint-disable-next-line @typescript-eslint/member-ordering
@@ -1342,14 +1438,9 @@ class FederationHost {
1342
1438
  * It accepts one argument, the name of the share scope.
1343
1439
  * If the share scope does not exist, it creates one.
1344
1440
  */ // eslint-disable-next-line @typescript-eslint/member-ordering
1345
- initializeSharing(shareScopeName = DEFAULT_SCOPE) {
1346
- const shareScopeLoading = Global.__FEDERATION__.__SHARE_SCOPE_LOADING__;
1347
- const shareScope = Global.__FEDERATION__.__SHARE__;
1441
+ initializeSharing(shareScopeName = DEFAULT_SCOPE, strategy) {
1442
+ const shareScope = this.shareScopeMap;
1348
1443
  const hostName = this.options.name;
1349
- // Executes only once
1350
- if (shareScopeLoading[shareScopeName]) {
1351
- return shareScopeLoading[shareScopeName];
1352
- }
1353
1444
  // Creates a new share scope if necessary
1354
1445
  if (!shareScope[shareScopeName]) {
1355
1446
  shareScope[shareScopeName] = {};
@@ -1357,21 +1448,27 @@ class FederationHost {
1357
1448
  // Executes all initialization snippets from all accessible modules
1358
1449
  const scope = shareScope[shareScopeName];
1359
1450
  const register = (name, shared)=>{
1451
+ var _activeVersion_shareConfig;
1360
1452
  const { version, eager } = shared;
1361
1453
  scope[name] = scope[name] || {};
1362
1454
  const versions = scope[name];
1363
1455
  const activeVersion = versions[version];
1364
- const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
1456
+ const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
1365
1457
  if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
1366
1458
  versions[version] = shared;
1367
1459
  }
1368
1460
  };
1369
1461
  const promises = [];
1462
+ const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
1370
1463
  const initRemoteModule = async (key)=>{
1371
1464
  const { module } = await this._getRemoteModuleAndOptions(key);
1372
- const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
1373
- const entry = await module.getEntry();
1374
- initFn(entry);
1465
+ if (module.getEntry) {
1466
+ const entry = await module.getEntry();
1467
+ if (!module.inited) {
1468
+ initFn(entry);
1469
+ module.inited = true;
1470
+ }
1471
+ }
1375
1472
  };
1376
1473
  Object.keys(this.options.shared).forEach((shareName)=>{
1377
1474
  const shared = this.options.shared[shareName];
@@ -1379,15 +1476,22 @@ class FederationHost {
1379
1476
  register(shareName, shared);
1380
1477
  }
1381
1478
  });
1382
- this.options.remotes.forEach((remote)=>{
1383
- if (remote.shareScope === shareScopeName) {
1384
- promises.push(initRemoteModule(remote.name));
1385
- }
1386
- });
1387
- if (!promises.length) {
1388
- return shareScopeLoading[shareScopeName] = true;
1479
+ if (strategy === 'version-first') {
1480
+ this.options.remotes.forEach((remote)=>{
1481
+ if (remote.shareScope === shareScopeName) {
1482
+ promises.push(initRemoteModule(remote.name));
1483
+ }
1484
+ });
1389
1485
  }
1390
- return shareScopeLoading[shareScopeName] = Promise.all(promises).then(()=>shareScopeLoading[shareScopeName] = true);
1486
+ return promises;
1487
+ }
1488
+ initShareScopeMap(scopeName, shareScope) {
1489
+ this.shareScopeMap[scopeName] = shareScope;
1490
+ this.hooks.lifecycle.initContainerShareScopeMap.emit({
1491
+ shareScope,
1492
+ options: this.options,
1493
+ origin: this
1494
+ });
1391
1495
  }
1392
1496
  formatOptions(globalOptions, userOptions) {
1393
1497
  const formatShareOptions = formatShareConfigs(userOptions.shared || {}, userOptions.name);
@@ -1420,23 +1524,23 @@ class FederationHost {
1420
1524
  remote.shareScope = DEFAULT_SCOPE;
1421
1525
  }
1422
1526
  if (!remote.type) {
1423
- // FIXME: The build plugin needs to support this field
1424
1527
  remote.type = DEFAULT_REMOTE_TYPE;
1425
1528
  }
1426
1529
  res.push(remote);
1427
1530
  }
1428
1531
  return res;
1429
1532
  }, globalOptionsRes.remotes);
1430
- // register shared include lib
1533
+ // register shared in shareScopeMap
1431
1534
  const sharedKeys = Object.keys(formatShareOptions);
1432
1535
  sharedKeys.forEach((sharedKey)=>{
1433
1536
  const sharedVal = formatShareOptions[sharedKey];
1434
- const globalShare = getGlobalShare(sharedKey, sharedVal);
1435
- if (!globalShare && sharedVal && sharedVal.lib) {
1537
+ const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
1538
+ if (!registeredShared && sharedVal && sharedVal.lib) {
1436
1539
  this.setShared({
1437
1540
  pkgName: sharedKey,
1438
1541
  lib: sharedVal.lib,
1439
1542
  get: sharedVal.get,
1543
+ loaded: true,
1440
1544
  shared: sharedVal,
1441
1545
  from: userOptions.name
1442
1546
  });
@@ -1471,7 +1575,6 @@ class FederationHost {
1471
1575
  ]);
1472
1576
  }
1473
1577
  setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
1474
- const target = getGlobalShareScope();
1475
1578
  const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
1476
1579
  "version",
1477
1580
  "scope"
@@ -1480,23 +1583,16 @@ class FederationHost {
1480
1583
  scope
1481
1584
  ];
1482
1585
  scopes.forEach((sc)=>{
1483
- if (!target[sc]) {
1484
- target[sc] = {};
1586
+ if (!this.shareScopeMap[sc]) {
1587
+ this.shareScopeMap[sc] = {};
1485
1588
  }
1486
- if (!target[sc][pkgName]) {
1487
- target[sc][pkgName] = {};
1589
+ if (!this.shareScopeMap[sc][pkgName]) {
1590
+ this.shareScopeMap[sc][pkgName] = {};
1488
1591
  }
1489
- if (target[sc][pkgName][version]) {
1490
- warn(// eslint-disable-next-line max-len
1491
- `The share \n ${safeToString({
1492
- scope: sc,
1493
- pkgName,
1494
- version,
1495
- from: target[sc][pkgName][version].from
1496
- })} has been registered`);
1592
+ if (this.shareScopeMap[sc][pkgName][version]) {
1497
1593
  return;
1498
1594
  }
1499
- target[sc][pkgName][version] = _extends({
1595
+ this.shareScopeMap[sc][pkgName][version] = _extends({
1500
1596
  version,
1501
1597
  scope: [
1502
1598
  'default'
@@ -1507,7 +1603,7 @@ class FederationHost {
1507
1603
  loading
1508
1604
  });
1509
1605
  if (get) {
1510
- target[sc][pkgName][version].get = get;
1606
+ this.shareScopeMap[sc][pkgName][version].get = get;
1511
1607
  }
1512
1608
  });
1513
1609
  }
@@ -1517,26 +1613,33 @@ class FederationHost {
1517
1613
  init: new SyncHook(),
1518
1614
  beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1519
1615
  afterResolve: new AsyncWaterfallHook('afterResolve'),
1616
+ // maybe will change, temporarily for internal use only
1520
1617
  beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
1618
+ // maybe will change, temporarily for internal use only
1619
+ initContainerShareScopeMap: new AsyncWaterfallHook('initContainer'),
1620
+ // maybe will change, temporarily for internal use only
1521
1621
  initContainer: new AsyncWaterfallHook('initContainer'),
1522
1622
  onLoad: new AsyncHook('onLoad'),
1523
1623
  handlePreloadModule: new SyncHook('handlePreloadModule'),
1524
1624
  errorLoadRemote: new AsyncHook('errorLoadRemote'),
1525
1625
  beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
1626
+ // not used yet
1526
1627
  loadShare: new AsyncHook(),
1628
+ resolveShare: new SyncWaterfallHook('resolveShare'),
1527
1629
  beforePreloadRemote: new AsyncHook(),
1528
1630
  generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
1631
+ // not used yet
1529
1632
  afterPreloadRemote: new AsyncHook()
1530
1633
  });
1531
- this.version = '0.0.7';
1634
+ this.version = "0.0.8";
1532
1635
  this.moduleCache = new Map();
1533
1636
  this.loaderHook = new PluginSystem({
1534
- // FIXME: may not be suitable
1637
+ // FIXME: may not be suitable , not open to the public yet
1535
1638
  getModuleInfo: new SyncHook(),
1536
1639
  createScript: new SyncHook(),
1640
+ // only work for manifest , so not open to the public yet
1537
1641
  fetch: new AsyncHook('fetch')
1538
1642
  });
1539
- this.loadingShare = {};
1540
1643
  // TODO: Validate the details of the options
1541
1644
  // Initialize options with default values
1542
1645
  const defaultOptions = {
@@ -1552,6 +1655,8 @@ class FederationHost {
1552
1655
  };
1553
1656
  this.name = userOptions.name;
1554
1657
  this.options = defaultOptions;
1658
+ this.shareScopeMap = {};
1659
+ this._setGlobalShareScopeMap();
1555
1660
  this.snapshotHandler = new SnapshotHandler(this);
1556
1661
  this.registerPlugins([
1557
1662
  ...defaultOptions.plugins,
@@ -1574,6 +1679,9 @@ function init(options) {
1574
1679
  } else {
1575
1680
  // Merge options
1576
1681
  instance.initOptions(options);
1682
+ if (!FederationInstance) {
1683
+ FederationInstance = instance;
1684
+ }
1577
1685
  return instance;
1578
1686
  }
1579
1687
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
@@ -39,8 +39,8 @@
39
39
  "helpers": [
40
40
  "./dist/helpers.cjs.d.ts"
41
41
  ],
42
- "type": [
43
- "./dist/type.cjs.d.ts"
42
+ "types": [
43
+ "./dist/types.cjs.d.ts"
44
44
  ]
45
45
  }
46
46
  },