@module-federation/runtime 0.0.0-next-20240528115713 → 0.0.0-next-20240529015908

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,4 +1,4 @@
1
- import { q as getRegisteredShare, A as getGlobalShareScope, G as Global, K as nativeGlobal, L as resetFederationGlobalInfo, F as getGlobalFederationInstance, I as setGlobalFederationInstance, H as getGlobalFederationConstructor, E as setGlobalFederationConstructor, n as getInfoWithoutType, x as getGlobalSnapshot, M as getTargetSnapshotInfoByModuleInfo, t as getGlobalSnapshotInfoByModuleInfo, v as setGlobalSnapshotInfoByModuleInfo, u as addGlobalSnapshot, c as getRemoteEntryExports, J as registerGlobalPlugins, g as getGlobalHostPlugins, o as getPreloaded, p as setPreloaded } from './share.esm.js';
1
+ import { o as getRegisteredShare, y as getGlobalShareScope, G as Global, J as nativeGlobal, K as resetFederationGlobalInfo, E as getGlobalFederationInstance, H as setGlobalFederationInstance, F as getGlobalFederationConstructor, C as setGlobalFederationConstructor, l as getInfoWithoutType, u as getGlobalSnapshot, L as getTargetSnapshotInfoByModuleInfo, q as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, c as getRemoteEntryExports, I as registerGlobalPlugins, g as getGlobalHostPlugins, m as getPreloaded, n as setPreloaded } from './share.esm.js';
2
2
 
3
3
  const ShareUtils = {
4
4
  getRegisteredShare,
package/dist/index.cjs.js CHANGED
@@ -142,7 +142,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
142
142
  `);
143
143
  return entryExports;
144
144
  }).catch((e)=>{
145
- throw e;
145
+ return e;
146
146
  });
147
147
  }
148
148
  return sdk.loadScript(entry, {
@@ -158,7 +158,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
158
158
  `);
159
159
  return entryExports;
160
160
  }).catch((e)=>{
161
- throw e;
161
+ return e;
162
162
  });
163
163
  }
164
164
  function getRemoteEntryUniqueKey(remoteInfo) {
@@ -638,16 +638,13 @@ function _extends$4() {
638
638
  return _extends$4.apply(this, arguments);
639
639
  }
640
640
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
641
- const remoteEntryInfo = share.getRemoteEntryInfoFromSnapshot(remoteSnapshot);
642
- if (!remoteEntryInfo.url) {
643
- share.error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
641
+ if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
642
+ share.error(`The attribute remoteEntry of ${name} must not be undefined.`);
644
643
  }
645
- let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
646
- if (!share.isBrowserEnv() && !entryUrl.startsWith('http')) {
647
- entryUrl = `https:${entryUrl}`;
648
- }
649
- remoteInfo.type = remoteEntryInfo.type;
650
- remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
644
+ const { remoteEntry } = remoteSnapshot;
645
+ const entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntry);
646
+ remoteInfo.type = remoteSnapshot.remoteEntryType;
647
+ remoteInfo.entryGlobalName = remoteSnapshot.globalName;
651
648
  remoteInfo.entry = entryUrl;
652
649
  remoteInfo.version = remoteSnapshot.version;
653
650
  remoteInfo.buildVersion = remoteSnapshot.buildVersion;
@@ -772,7 +769,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
772
769
  return;
773
770
  }
774
771
  }
775
- const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, share.getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
772
+ const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, 'remoteEntry' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntry : '');
776
773
  if (remoteEntryUrl) {
777
774
  entryAssets.push({
778
775
  name: remoteInfo.name,
@@ -978,13 +975,12 @@ class SnapshotHandler {
978
975
  // global snapshot includes manifest or module info includes manifest
979
976
  if (globalRemoteSnapshot) {
980
977
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
981
- const remoteEntry = share.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
982
- const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
978
+ const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
983
979
  // eslint-disable-next-line @typescript-eslint/no-shadow
984
980
  const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
985
981
  // The global remote may be overridden
986
982
  // Therefore, set the snapshot key to the global address of the actual request
987
- entry: remoteEntry
983
+ entry: globalRemoteSnapshot.remoteEntry
988
984
  }), moduleSnapshot);
989
985
  return {
990
986
  remoteSnapshot: moduleSnapshot,
@@ -1516,10 +1512,6 @@ class RemoteHandler {
1516
1512
  moduleInstance: module,
1517
1513
  origin: host
1518
1514
  });
1519
- this.idToRemoteMap[id] = {
1520
- name: remote.name,
1521
- expose
1522
- };
1523
1515
  if (typeof moduleWrapper === 'function') {
1524
1516
  return moduleWrapper;
1525
1517
  }
@@ -1678,60 +1670,49 @@ class RemoteHandler {
1678
1670
  }
1679
1671
  }
1680
1672
  removeRemote(remote) {
1681
- try {
1682
- const { host } = this;
1683
- const { name } = remote;
1684
- const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1685
- if (remoteIndex !== -1) {
1686
- host.options.remotes.splice(remoteIndex, 1);
1673
+ const { host } = this;
1674
+ const { name } = remote;
1675
+ const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1676
+ if (remoteIndex !== -1) {
1677
+ host.options.remotes.splice(remoteIndex, 1);
1678
+ }
1679
+ const loadedModule = host.moduleCache.get(remote.name);
1680
+ if (loadedModule) {
1681
+ var _Object_getOwnPropertyDescriptor;
1682
+ const remoteInfo = loadedModule.remoteInfo;
1683
+ const key = remoteInfo.entryGlobalName;
1684
+ if (globalThis[key] && ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable)) {
1685
+ delete globalThis[key];
1687
1686
  }
1688
- const loadedModule = host.moduleCache.get(remote.name);
1689
- if (loadedModule) {
1690
- const remoteInfo = loadedModule.remoteInfo;
1691
- const key = remoteInfo.entryGlobalName;
1692
- if (globalThis[key]) {
1693
- delete globalThis[key];
1694
- }
1695
- const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1696
- if (share.globalLoading[remoteEntryUniqueKey]) {
1697
- delete share.globalLoading[remoteEntryUniqueKey];
1687
+ const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1688
+ if (share.globalLoading[remoteEntryUniqueKey]) {
1689
+ delete share.globalLoading[remoteEntryUniqueKey];
1690
+ }
1691
+ // delete un loaded shared and instance
1692
+ let remoteInsId = remoteInfo.buildVersion ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1693
+ const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1694
+ if (remoteInfo.buildVersion) {
1695
+ return ins.options.id === remoteInsId;
1696
+ } else {
1697
+ return ins.name === remoteInsId;
1698
1698
  }
1699
- // delete un loaded shared and instance
1700
- let remoteInsId = remoteInfo.buildVersion ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1701
- const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1702
- if (remoteInfo.buildVersion) {
1703
- return ins.options.id === remoteInsId;
1704
- } else {
1705
- return ins.name === remoteInsId;
1706
- }
1707
- });
1708
- if (remoteInsIndex !== -1) {
1709
- const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1710
- remoteInsId = remoteIns.options.id || remoteInsId;
1711
- const globalShareScopeMap = share.getGlobalShareScope();
1712
- let isAllSharedNotUsed = true;
1713
- const needDeleteKeys = [];
1714
- Object.keys(globalShareScopeMap).forEach((instId)=>{
1715
- const shareScopeMap = globalShareScopeMap[instId];
1716
- shareScopeMap && Object.keys(shareScopeMap).forEach((shareScope)=>{
1717
- const shareScopeVal = shareScopeMap[shareScope];
1718
- shareScopeVal && Object.keys(shareScopeVal).forEach((shareName)=>{
1719
- const sharedPkgs = shareScopeVal[shareName];
1720
- sharedPkgs && Object.keys(sharedPkgs).forEach((shareVersion)=>{
1721
- const shared = sharedPkgs[shareVersion];
1722
- if (shared && typeof shared === 'object' && shared.from === remoteInfo.name) {
1723
- if (shared.loaded || shared.loading) {
1724
- shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1725
- if (shared.useIn.length) {
1726
- isAllSharedNotUsed = false;
1727
- } else {
1728
- needDeleteKeys.push([
1729
- instId,
1730
- shareScope,
1731
- shareName,
1732
- shareVersion
1733
- ]);
1734
- }
1699
+ });
1700
+ if (remoteInsIndex !== -1) {
1701
+ const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1702
+ remoteInsId = remoteIns.options.id || remoteInsId;
1703
+ const globalShareScopeMap = share.getGlobalShareScope();
1704
+ let isAllSharedNotUsed = true;
1705
+ const needDeleteKeys = [];
1706
+ Object.keys(globalShareScopeMap).forEach((instId)=>{
1707
+ Object.keys(globalShareScopeMap[instId]).forEach((shareScope)=>{
1708
+ Object.keys(globalShareScopeMap[instId][shareScope]).forEach((shareName)=>{
1709
+ Object.keys(globalShareScopeMap[instId][shareScope][shareName]).forEach((shareVersion)=>{
1710
+ const shared = globalShareScopeMap[instId][shareScope][shareName][shareVersion];
1711
+ if (shared.from === remoteInfo.name) {
1712
+ if (shared.loaded || shared.loading) {
1713
+ shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1714
+ if (shared.useIn.length) {
1715
+ isAllSharedNotUsed = false;
1735
1716
  } else {
1736
1717
  needDeleteKeys.push([
1737
1718
  instId,
@@ -1740,25 +1721,30 @@ class RemoteHandler {
1740
1721
  shareVersion
1741
1722
  ]);
1742
1723
  }
1724
+ } else {
1725
+ needDeleteKeys.push([
1726
+ instId,
1727
+ shareScope,
1728
+ shareName,
1729
+ shareVersion
1730
+ ]);
1743
1731
  }
1744
- });
1732
+ }
1745
1733
  });
1746
1734
  });
1747
1735
  });
1748
- if (isAllSharedNotUsed) {
1749
- remoteIns.shareScopeMap = {};
1750
- delete globalShareScopeMap[remoteInsId];
1751
- }
1752
- needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1753
- var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1754
- (_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];
1755
- });
1756
- globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1736
+ });
1737
+ if (isAllSharedNotUsed) {
1738
+ remoteIns.shareScopeMap = {};
1739
+ delete globalShareScopeMap[remoteInsId];
1757
1740
  }
1758
- host.moduleCache.delete(remote.name);
1741
+ needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1742
+ var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1743
+ (_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];
1744
+ });
1745
+ globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1759
1746
  }
1760
- } catch (err) {
1761
- console.log('removeRemote fail: ', err);
1747
+ host.moduleCache.delete(remote.name);
1762
1748
  }
1763
1749
  }
1764
1750
  constructor(host){
@@ -1773,7 +1759,6 @@ class RemoteHandler {
1773
1759
  afterPreloadRemote: new AsyncHook()
1774
1760
  });
1775
1761
  this.host = host;
1776
- this.idToRemoteMap = {};
1777
1762
  }
1778
1763
  }
1779
1764
 
@@ -1985,9 +1970,6 @@ function registerPlugins(...args) {
1985
1970
  // eslint-disable-next-line prefer-spread
1986
1971
  return FederationInstance.registerPlugins.apply(FederationInstance, args);
1987
1972
  }
1988
- function getInstance() {
1989
- return FederationInstance;
1990
- }
1991
1973
  // Inject for debug
1992
1974
  share.setGlobalFederationConstructor(FederationHost);
1993
1975
 
@@ -2001,7 +1983,6 @@ Object.defineProperty(exports, 'loadScriptNode', {
2001
1983
  get: function () { return sdk.loadScriptNode; }
2002
1984
  });
2003
1985
  exports.FederationHost = FederationHost;
2004
- exports.getInstance = getInstance;
2005
1986
  exports.getRemoteEntry = getRemoteEntry;
2006
1987
  exports.getRemoteInfo = getRemoteInfo;
2007
1988
  exports.init = init;
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
- import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, 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 getRemoteEntryInfoFromSnapshot, m as isBrowserEnv, n as getInfoWithoutType, o as getPreloaded, p as setPreloaded, q as getRegisteredShare, r as arrayOptions, t as getGlobalSnapshotInfoByModuleInfo, u as addGlobalSnapshot, v as setGlobalSnapshotInfoByModuleInfo, x as getGlobalSnapshot, G as Global, y as formatShareConfigs, z as getTargetSharedOptions, A as getGlobalShareScope, B as addUniqueItem, C as getBuilderId, E as setGlobalFederationConstructor, F as getGlobalFederationInstance, H as getGlobalFederationConstructor, I as setGlobalFederationInstance } from './share.esm.js';
2
- export { J as registerGlobalPlugins } from './share.esm.js';
3
- import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1, isBrowserEnv as isBrowserEnv$1 } from '@module-federation/sdk';
1
+ import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, 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 getInfoWithoutType, m as getPreloaded, n as setPreloaded, o as getRegisteredShare, p as arrayOptions, q as getGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, t as setGlobalSnapshotInfoByModuleInfo, u as getGlobalSnapshot, G as Global, v as formatShareConfigs, x as getTargetSharedOptions, y as getGlobalShareScope, z as addUniqueItem, A as getBuilderId, B as isBrowserEnv$1, C as setGlobalFederationConstructor, E as getGlobalFederationInstance, F as getGlobalFederationConstructor, H as setGlobalFederationInstance } from './share.esm.js';
2
+ export { I as registerGlobalPlugins } from './share.esm.js';
3
+ import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1, isBrowserEnv } from '@module-federation/sdk';
4
4
  export { loadScript, loadScriptNode } from '@module-federation/sdk';
5
5
 
6
6
  // Function to match a remote with its name and expose
@@ -140,7 +140,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
140
140
  `);
141
141
  return entryExports;
142
142
  }).catch((e)=>{
143
- throw e;
143
+ return e;
144
144
  });
145
145
  }
146
146
  return loadScript(entry, {
@@ -156,7 +156,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
156
156
  `);
157
157
  return entryExports;
158
158
  }).catch((e)=>{
159
- throw e;
159
+ return e;
160
160
  });
161
161
  }
162
162
  function getRemoteEntryUniqueKey(remoteInfo) {
@@ -636,16 +636,13 @@ function _extends$4() {
636
636
  return _extends$4.apply(this, arguments);
637
637
  }
638
638
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
639
- const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
640
- if (!remoteEntryInfo.url) {
641
- error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
639
+ if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
640
+ error(`The attribute remoteEntry of ${name} must not be undefined.`);
642
641
  }
643
- let entryUrl = getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
644
- if (!isBrowserEnv() && !entryUrl.startsWith('http')) {
645
- entryUrl = `https:${entryUrl}`;
646
- }
647
- remoteInfo.type = remoteEntryInfo.type;
648
- remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
642
+ const { remoteEntry } = remoteSnapshot;
643
+ const entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);
644
+ remoteInfo.type = remoteSnapshot.remoteEntryType;
645
+ remoteInfo.entryGlobalName = remoteSnapshot.globalName;
649
646
  remoteInfo.entry = entryUrl;
650
647
  remoteInfo.version = remoteSnapshot.version;
651
648
  remoteInfo.buildVersion = remoteSnapshot.buildVersion;
@@ -770,7 +767,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
770
767
  return;
771
768
  }
772
769
  }
773
- const remoteEntryUrl = getResourceUrl(moduleInfoSnapshot, getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
770
+ const remoteEntryUrl = getResourceUrl(moduleInfoSnapshot, 'remoteEntry' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntry : '');
774
771
  if (remoteEntryUrl) {
775
772
  entryAssets.push({
776
773
  name: remoteInfo.name,
@@ -976,13 +973,12 @@ class SnapshotHandler {
976
973
  // global snapshot includes manifest or module info includes manifest
977
974
  if (globalRemoteSnapshot) {
978
975
  if (isManifestProvider(globalRemoteSnapshot)) {
979
- const remoteEntry = isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
980
- const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
976
+ const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
981
977
  // eslint-disable-next-line @typescript-eslint/no-shadow
982
978
  const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
983
979
  // The global remote may be overridden
984
980
  // Therefore, set the snapshot key to the global address of the actual request
985
- entry: remoteEntry
981
+ entry: globalRemoteSnapshot.remoteEntry
986
982
  }), moduleSnapshot);
987
983
  return {
988
984
  remoteSnapshot: moduleSnapshot,
@@ -1514,10 +1510,6 @@ class RemoteHandler {
1514
1510
  moduleInstance: module,
1515
1511
  origin: host
1516
1512
  });
1517
- this.idToRemoteMap[id] = {
1518
- name: remote.name,
1519
- expose
1520
- };
1521
1513
  if (typeof moduleWrapper === 'function') {
1522
1514
  return moduleWrapper;
1523
1515
  }
@@ -1646,7 +1638,7 @@ class RemoteHandler {
1646
1638
  }
1647
1639
  // Set the remote entry to a complete path
1648
1640
  if ('entry' in remote) {
1649
- if (isBrowserEnv$1() && !remote.entry.startsWith('http')) {
1641
+ if (isBrowserEnv() && !remote.entry.startsWith('http')) {
1650
1642
  remote.entry = new URL(remote.entry, window.location.origin).href;
1651
1643
  }
1652
1644
  }
@@ -1676,60 +1668,49 @@ class RemoteHandler {
1676
1668
  }
1677
1669
  }
1678
1670
  removeRemote(remote) {
1679
- try {
1680
- const { host } = this;
1681
- const { name } = remote;
1682
- const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1683
- if (remoteIndex !== -1) {
1684
- host.options.remotes.splice(remoteIndex, 1);
1671
+ const { host } = this;
1672
+ const { name } = remote;
1673
+ const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1674
+ if (remoteIndex !== -1) {
1675
+ host.options.remotes.splice(remoteIndex, 1);
1676
+ }
1677
+ const loadedModule = host.moduleCache.get(remote.name);
1678
+ if (loadedModule) {
1679
+ var _Object_getOwnPropertyDescriptor;
1680
+ const remoteInfo = loadedModule.remoteInfo;
1681
+ const key = remoteInfo.entryGlobalName;
1682
+ if (globalThis[key] && ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable)) {
1683
+ delete globalThis[key];
1685
1684
  }
1686
- const loadedModule = host.moduleCache.get(remote.name);
1687
- if (loadedModule) {
1688
- const remoteInfo = loadedModule.remoteInfo;
1689
- const key = remoteInfo.entryGlobalName;
1690
- if (globalThis[key]) {
1691
- delete globalThis[key];
1692
- }
1693
- const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1694
- if (globalLoading[remoteEntryUniqueKey]) {
1695
- delete globalLoading[remoteEntryUniqueKey];
1685
+ const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1686
+ if (globalLoading[remoteEntryUniqueKey]) {
1687
+ delete globalLoading[remoteEntryUniqueKey];
1688
+ }
1689
+ // delete un loaded shared and instance
1690
+ let remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1691
+ const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1692
+ if (remoteInfo.buildVersion) {
1693
+ return ins.options.id === remoteInsId;
1694
+ } else {
1695
+ return ins.name === remoteInsId;
1696
1696
  }
1697
- // delete un loaded shared and instance
1698
- let remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1699
- const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1700
- if (remoteInfo.buildVersion) {
1701
- return ins.options.id === remoteInsId;
1702
- } else {
1703
- return ins.name === remoteInsId;
1704
- }
1705
- });
1706
- if (remoteInsIndex !== -1) {
1707
- const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1708
- remoteInsId = remoteIns.options.id || remoteInsId;
1709
- const globalShareScopeMap = getGlobalShareScope();
1710
- let isAllSharedNotUsed = true;
1711
- const needDeleteKeys = [];
1712
- Object.keys(globalShareScopeMap).forEach((instId)=>{
1713
- const shareScopeMap = globalShareScopeMap[instId];
1714
- shareScopeMap && Object.keys(shareScopeMap).forEach((shareScope)=>{
1715
- const shareScopeVal = shareScopeMap[shareScope];
1716
- shareScopeVal && Object.keys(shareScopeVal).forEach((shareName)=>{
1717
- const sharedPkgs = shareScopeVal[shareName];
1718
- sharedPkgs && Object.keys(sharedPkgs).forEach((shareVersion)=>{
1719
- const shared = sharedPkgs[shareVersion];
1720
- if (shared && typeof shared === 'object' && shared.from === remoteInfo.name) {
1721
- if (shared.loaded || shared.loading) {
1722
- shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1723
- if (shared.useIn.length) {
1724
- isAllSharedNotUsed = false;
1725
- } else {
1726
- needDeleteKeys.push([
1727
- instId,
1728
- shareScope,
1729
- shareName,
1730
- shareVersion
1731
- ]);
1732
- }
1697
+ });
1698
+ if (remoteInsIndex !== -1) {
1699
+ const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1700
+ remoteInsId = remoteIns.options.id || remoteInsId;
1701
+ const globalShareScopeMap = getGlobalShareScope();
1702
+ let isAllSharedNotUsed = true;
1703
+ const needDeleteKeys = [];
1704
+ Object.keys(globalShareScopeMap).forEach((instId)=>{
1705
+ Object.keys(globalShareScopeMap[instId]).forEach((shareScope)=>{
1706
+ Object.keys(globalShareScopeMap[instId][shareScope]).forEach((shareName)=>{
1707
+ Object.keys(globalShareScopeMap[instId][shareScope][shareName]).forEach((shareVersion)=>{
1708
+ const shared = globalShareScopeMap[instId][shareScope][shareName][shareVersion];
1709
+ if (shared.from === remoteInfo.name) {
1710
+ if (shared.loaded || shared.loading) {
1711
+ shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1712
+ if (shared.useIn.length) {
1713
+ isAllSharedNotUsed = false;
1733
1714
  } else {
1734
1715
  needDeleteKeys.push([
1735
1716
  instId,
@@ -1738,25 +1719,30 @@ class RemoteHandler {
1738
1719
  shareVersion
1739
1720
  ]);
1740
1721
  }
1722
+ } else {
1723
+ needDeleteKeys.push([
1724
+ instId,
1725
+ shareScope,
1726
+ shareName,
1727
+ shareVersion
1728
+ ]);
1741
1729
  }
1742
- });
1730
+ }
1743
1731
  });
1744
1732
  });
1745
1733
  });
1746
- if (isAllSharedNotUsed) {
1747
- remoteIns.shareScopeMap = {};
1748
- delete globalShareScopeMap[remoteInsId];
1749
- }
1750
- needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1751
- var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1752
- (_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];
1753
- });
1754
- globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1734
+ });
1735
+ if (isAllSharedNotUsed) {
1736
+ remoteIns.shareScopeMap = {};
1737
+ delete globalShareScopeMap[remoteInsId];
1755
1738
  }
1756
- host.moduleCache.delete(remote.name);
1739
+ needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1740
+ var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1741
+ (_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];
1742
+ });
1743
+ globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1757
1744
  }
1758
- } catch (err) {
1759
- console.log('removeRemote fail: ', err);
1745
+ host.moduleCache.delete(remote.name);
1760
1746
  }
1761
1747
  }
1762
1748
  constructor(host){
@@ -1771,7 +1757,6 @@ class RemoteHandler {
1771
1757
  afterPreloadRemote: new AsyncHook()
1772
1758
  });
1773
1759
  this.host = host;
1774
- this.idToRemoteMap = {};
1775
1760
  }
1776
1761
  }
1777
1762
 
@@ -1915,7 +1900,7 @@ class FederationHost {
1915
1900
  ],
1916
1901
  remotes: [],
1917
1902
  shared: {},
1918
- inBrowser: isBrowserEnv()
1903
+ inBrowser: isBrowserEnv$1()
1919
1904
  };
1920
1905
  this.name = userOptions.name;
1921
1906
  this.options = defaultOptions;
@@ -1983,10 +1968,7 @@ function registerPlugins(...args) {
1983
1968
  // eslint-disable-next-line prefer-spread
1984
1969
  return FederationInstance.registerPlugins.apply(FederationInstance, args);
1985
1970
  }
1986
- function getInstance() {
1987
- return FederationInstance;
1988
- }
1989
1971
  // Inject for debug
1990
1972
  setGlobalFederationConstructor(FederationHost);
1991
1973
 
1992
- export { FederationHost, getInstance, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerPlugins, registerRemotes };
1974
+ export { FederationHost, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerPlugins, registerRemotes };
package/dist/share.cjs.js CHANGED
@@ -76,28 +76,6 @@ function arrayOptions(options) {
76
76
  options
77
77
  ];
78
78
  }
79
- function getRemoteEntryInfoFromSnapshot(snapshot) {
80
- const defaultRemoteEntryInfo = {
81
- url: '',
82
- type: 'global',
83
- globalName: ''
84
- };
85
- if (isBrowserEnv()) {
86
- return 'remoteEntry' in snapshot ? {
87
- url: snapshot.remoteEntry,
88
- type: snapshot.remoteEntryType,
89
- globalName: snapshot.globalName
90
- } : defaultRemoteEntryInfo;
91
- }
92
- if ('ssrRemoteEntry' in snapshot) {
93
- return {
94
- url: snapshot.ssrRemoteEntry || defaultRemoteEntryInfo.url,
95
- type: snapshot.ssrRemoteEntryType || defaultRemoteEntryInfo.type,
96
- globalName: snapshot.globalName
97
- };
98
- }
99
- return defaultRemoteEntryInfo;
100
- }
101
79
 
102
80
  function _extends$1() {
103
81
  _extends$1 = Object.assign || function(target) {
@@ -915,7 +893,6 @@ exports.getInfoWithoutType = getInfoWithoutType;
915
893
  exports.getPreloaded = getPreloaded;
916
894
  exports.getRegisteredShare = getRegisteredShare;
917
895
  exports.getRemoteEntryExports = getRemoteEntryExports;
918
- exports.getRemoteEntryInfoFromSnapshot = getRemoteEntryInfoFromSnapshot;
919
896
  exports.getTargetSharedOptions = getTargetSharedOptions;
920
897
  exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
921
898
  exports.globalLoading = globalLoading;
package/dist/share.esm.js CHANGED
@@ -74,28 +74,6 @@ function arrayOptions(options) {
74
74
  options
75
75
  ];
76
76
  }
77
- function getRemoteEntryInfoFromSnapshot(snapshot) {
78
- const defaultRemoteEntryInfo = {
79
- url: '',
80
- type: 'global',
81
- globalName: ''
82
- };
83
- if (isBrowserEnv()) {
84
- return 'remoteEntry' in snapshot ? {
85
- url: snapshot.remoteEntry,
86
- type: snapshot.remoteEntryType,
87
- globalName: snapshot.globalName
88
- } : defaultRemoteEntryInfo;
89
- }
90
- if ('ssrRemoteEntry' in snapshot) {
91
- return {
92
- url: snapshot.ssrRemoteEntry || defaultRemoteEntryInfo.url,
93
- type: snapshot.ssrRemoteEntryType || defaultRemoteEntryInfo.type,
94
- globalName: snapshot.globalName
95
- };
96
- }
97
- return defaultRemoteEntryInfo;
98
- }
99
77
 
100
78
  function _extends$1() {
101
79
  _extends$1 = Object.assign || function(target) {
@@ -892,4 +870,4 @@ function getTargetSharedOptions(options) {
892
870
  return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
893
871
  }
894
872
 
895
- export { getGlobalShareScope as A, addUniqueItem as B, getBuilderId as C, DEFAULT_REMOTE_TYPE as D, setGlobalFederationConstructor as E, getGlobalFederationInstance as F, Global as G, getGlobalFederationConstructor as H, setGlobalFederationInstance as I, registerGlobalPlugins as J, nativeGlobal as K, resetFederationGlobalInfo as L, getTargetSnapshotInfoByModuleInfo as M, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getRemoteEntryInfoFromSnapshot as l, isBrowserEnv as m, getInfoWithoutType as n, getPreloaded as o, setPreloaded as p, getRegisteredShare as q, arrayOptions as r, safeToString as s, getGlobalSnapshotInfoByModuleInfo as t, addGlobalSnapshot as u, setGlobalSnapshotInfoByModuleInfo as v, warn as w, getGlobalSnapshot as x, formatShareConfigs as y, getTargetSharedOptions as z };
873
+ export { getBuilderId as A, isBrowserEnv as B, setGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, getGlobalFederationInstance as E, getGlobalFederationConstructor as F, Global as G, setGlobalFederationInstance as H, registerGlobalPlugins as I, nativeGlobal as J, resetFederationGlobalInfo as K, getTargetSnapshotInfoByModuleInfo as L, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getInfoWithoutType as l, getPreloaded as m, setPreloaded as n, getRegisteredShare as o, arrayOptions as p, getGlobalSnapshotInfoByModuleInfo as q, addGlobalSnapshot as r, safeToString as s, setGlobalSnapshotInfoByModuleInfo as t, getGlobalSnapshot as u, formatShareConfigs as v, warn as w, getTargetSharedOptions as x, getGlobalShareScope as y, addUniqueItem as z };
@@ -13,4 +13,3 @@ export declare function loadShareSync<T>(...args: Parameters<FederationHost['loa
13
13
  export declare function preloadRemote(...args: Parameters<FederationHost['preloadRemote']>): ReturnType<FederationHost['preloadRemote']>;
14
14
  export declare function registerRemotes(...args: Parameters<FederationHost['registerRemotes']>): ReturnType<FederationHost['registerRemotes']>;
15
15
  export declare function registerPlugins(...args: Parameters<FederationHost['registerPlugins']>): ReturnType<FederationHost['registerRemotes']>;
16
- export declare function getInstance(): FederationHost | null;
@@ -39,10 +39,6 @@ export declare class SnapshotHandler {
39
39
  remoteSnapshot: ModuleInfo;
40
40
  globalSnapshot: GlobalModuleInfo;
41
41
  }> | never;
42
- getGlobalRemoteInfo(moduleInfo: Remote): {
43
- hostGlobalSnapshot: ModuleInfo | undefined;
44
- globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
45
- remoteSnapshot: GlobalModuleInfo[string] | undefined;
46
- };
42
+ private getGlobalRemoteInfo;
47
43
  private getManifestJson;
48
44
  }
@@ -15,10 +15,6 @@ export interface LoadRemoteMatch {
15
15
  }
16
16
  export declare class RemoteHandler {
17
17
  host: FederationHost;
18
- idToRemoteMap: Record<string, {
19
- name: string;
20
- expose: string;
21
- }>;
22
18
  hooks: PluginSystem<{
23
19
  beforeRequest: AsyncWaterfallHook<{
24
20
  id: string;
@@ -1,4 +1,4 @@
1
- import type { RemoteWithEntry, ModuleInfo, RemoteEntryType } from '@module-federation/sdk';
1
+ import type { RemoteWithEntry } from '@module-federation/sdk';
2
2
  import { Remote, RemoteInfoOptionalVersion } from '../type';
3
3
  export declare function addUniqueItem(arr: Array<string>, item: string): Array<string>;
4
4
  export declare function getFMId(remoteInfo: RemoteInfoOptionalVersion | RemoteWithEntry): string;
@@ -11,8 +11,3 @@ export declare const objectToString: () => string;
11
11
  export declare function isPlainObject(val: any): val is object;
12
12
  export declare function isStaticResourcesEqual(url1: string, url2: string): boolean;
13
13
  export declare function arrayOptions<T>(options: T | Array<T>): Array<T>;
14
- export declare function getRemoteEntryInfoFromSnapshot(snapshot: ModuleInfo): {
15
- url: string;
16
- type: RemoteEntryType;
17
- globalName: string;
18
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.0-next-20240528115713",
3
+ "version": "0.0.0-next-20240529015908",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -45,6 +45,6 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@module-federation/sdk": "0.0.0-next-20240528115713"
48
+ "@module-federation/sdk": "0.0.0-next-20240529015908"
49
49
  }
50
50
  }