@module-federation/runtime 0.0.0-next-20240511031741 → 0.0.0-next-20240515062211

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 { 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';
1
+ import { p 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, m as getInfoWithoutType, x as getGlobalSnapshot, M as getTargetSnapshotInfoByModuleInfo, r as getGlobalSnapshotInfoByModuleInfo, v as setGlobalSnapshotInfoByModuleInfo, t as addGlobalSnapshot, c as getRemoteEntryExports, J as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
2
2
 
3
3
  const ShareUtils = {
4
4
  getRegisteredShare,
package/dist/index.cjs.js CHANGED
@@ -618,13 +618,13 @@ function _extends$4() {
618
618
  return _extends$4.apply(this, arguments);
619
619
  }
620
620
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
621
- if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
622
- share.error(`The attribute remoteEntry of ${name} must not be undefined.`);
621
+ const remoteEntryInfo = share.getRemoteEntryInfoFromSnapshot(remoteSnapshot);
622
+ if (!remoteEntryInfo.url) {
623
+ share.error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
623
624
  }
624
- const { remoteEntry } = remoteSnapshot;
625
- const entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntry);
626
- remoteInfo.type = remoteSnapshot.remoteEntryType;
627
- remoteInfo.entryGlobalName = remoteSnapshot.globalName;
625
+ const entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
626
+ remoteInfo.type = remoteEntryInfo.type;
627
+ remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
628
628
  remoteInfo.entry = entryUrl;
629
629
  remoteInfo.version = remoteSnapshot.version;
630
630
  remoteInfo.buildVersion = remoteSnapshot.buildVersion;
@@ -749,7 +749,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
749
749
  return;
750
750
  }
751
751
  }
752
- const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, 'remoteEntry' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntry : '');
752
+ const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, share.getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
753
753
  if (remoteEntryUrl) {
754
754
  entryAssets.push({
755
755
  name: remoteInfo.name,
@@ -955,12 +955,13 @@ class SnapshotHandler {
955
955
  // global snapshot includes manifest or module info includes manifest
956
956
  if (globalRemoteSnapshot) {
957
957
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
958
- const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
958
+ const remoteEntry = share.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || '';
959
+ const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
959
960
  // eslint-disable-next-line @typescript-eslint/no-shadow
960
961
  const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
961
962
  // The global remote may be overridden
962
963
  // Therefore, set the snapshot key to the global address of the actual request
963
- entry: globalRemoteSnapshot.remoteEntry
964
+ entry: remoteEntry
964
965
  }), moduleSnapshot);
965
966
  return {
966
967
  remoteSnapshot: moduleSnapshot,
@@ -1492,6 +1493,7 @@ class RemoteHandler {
1492
1493
  moduleInstance: module,
1493
1494
  origin: host
1494
1495
  });
1496
+ this.idToModuleNameMap[id] = remote.name;
1495
1497
  if (typeof moduleWrapper === 'function') {
1496
1498
  return moduleWrapper;
1497
1499
  }
@@ -1658,7 +1660,8 @@ class RemoteHandler {
1658
1660
  }
1659
1661
  const loadedModule = host.moduleCache.get(remote.name);
1660
1662
  if (loadedModule) {
1661
- const key = loadedModule.remoteInfo.entryGlobalName;
1663
+ const remoteInfo = loadedModule.remoteInfo;
1664
+ const key = remoteInfo.entryGlobalName;
1662
1665
  if (globalThis[key]) {
1663
1666
  delete globalThis[key];
1664
1667
  }
@@ -1666,6 +1669,62 @@ class RemoteHandler {
1666
1669
  if (share.globalLoading[remoteEntryUniqueKey]) {
1667
1670
  delete share.globalLoading[remoteEntryUniqueKey];
1668
1671
  }
1672
+ // delete un loaded shared and instance
1673
+ let remoteInsId = remoteInfo.buildVersion ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1674
+ const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1675
+ if (remoteInfo.buildVersion) {
1676
+ return ins.options.id === remoteInsId;
1677
+ } else {
1678
+ return ins.name === remoteInsId;
1679
+ }
1680
+ });
1681
+ if (remoteInsIndex !== -1) {
1682
+ const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1683
+ remoteInsId = remoteIns.options.id || remoteInsId;
1684
+ const globalShareScopeMap = share.getGlobalShareScope();
1685
+ let isAllSharedNotUsed = true;
1686
+ const needDeleteKeys = [];
1687
+ Object.keys(globalShareScopeMap).forEach((instId)=>{
1688
+ Object.keys(globalShareScopeMap[instId]).forEach((shareScope)=>{
1689
+ Object.keys(globalShareScopeMap[instId][shareScope]).forEach((shareName)=>{
1690
+ Object.keys(globalShareScopeMap[instId][shareScope][shareName]).forEach((shareVersion)=>{
1691
+ const shared = globalShareScopeMap[instId][shareScope][shareName][shareVersion];
1692
+ if (shared.from === remoteInfo.name) {
1693
+ if (shared.loaded || shared.loading) {
1694
+ shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1695
+ if (shared.useIn.length) {
1696
+ isAllSharedNotUsed = false;
1697
+ } else {
1698
+ needDeleteKeys.push([
1699
+ instId,
1700
+ shareScope,
1701
+ shareName,
1702
+ shareVersion
1703
+ ]);
1704
+ }
1705
+ } else {
1706
+ needDeleteKeys.push([
1707
+ instId,
1708
+ shareScope,
1709
+ shareName,
1710
+ shareVersion
1711
+ ]);
1712
+ }
1713
+ }
1714
+ });
1715
+ });
1716
+ });
1717
+ });
1718
+ if (isAllSharedNotUsed) {
1719
+ remoteIns.shareScopeMap = {};
1720
+ delete globalShareScopeMap[remoteInsId];
1721
+ }
1722
+ needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1723
+ var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1724
+ (_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];
1725
+ });
1726
+ globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1727
+ }
1669
1728
  host.moduleCache.delete(remote.name);
1670
1729
  }
1671
1730
  }
@@ -1681,6 +1740,7 @@ class RemoteHandler {
1681
1740
  afterPreloadRemote: new AsyncHook()
1682
1741
  });
1683
1742
  this.host = host;
1743
+ this.idToModuleNameMap = {};
1684
1744
  }
1685
1745
  }
1686
1746
 
@@ -1803,7 +1863,7 @@ class FederationHost {
1803
1863
  // maybe will change, temporarily for internal use only
1804
1864
  initContainer: new AsyncWaterfallHook('initContainer')
1805
1865
  });
1806
- this.version = "0.1.12";
1866
+ this.version = "0.1.13";
1807
1867
  this.moduleCache = new Map();
1808
1868
  this.loaderHook = new PluginSystem({
1809
1869
  // FIXME: may not be suitable , not open to the public yet
@@ -1892,6 +1952,9 @@ function registerPlugins(...args) {
1892
1952
  // eslint-disable-next-line prefer-spread
1893
1953
  return FederationInstance.registerPlugins.apply(FederationInstance, args);
1894
1954
  }
1955
+ function getInstance() {
1956
+ return FederationInstance;
1957
+ }
1895
1958
  // Inject for debug
1896
1959
  share.setGlobalFederationConstructor(FederationHost);
1897
1960
 
@@ -1905,6 +1968,7 @@ Object.defineProperty(exports, 'loadScriptNode', {
1905
1968
  get: function () { return sdk.loadScriptNode; }
1906
1969
  });
1907
1970
  exports.FederationHost = FederationHost;
1971
+ exports.getInstance = getInstance;
1908
1972
  exports.getRemoteEntry = getRemoteEntry;
1909
1973
  exports.getRemoteInfo = getRemoteInfo;
1910
1974
  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 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';
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 getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getRegisteredShare, q as arrayOptions, r as getGlobalSnapshotInfoByModuleInfo, t as addGlobalSnapshot, u as isBrowserEnv, 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';
4
4
  export { loadScript, loadScriptNode } from '@module-federation/sdk';
5
5
 
6
6
  // Function to match a remote with its name and expose
@@ -616,13 +616,13 @@ function _extends$4() {
616
616
  return _extends$4.apply(this, arguments);
617
617
  }
618
618
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
619
- if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
620
- error(`The attribute remoteEntry of ${name} must not be undefined.`);
619
+ const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
620
+ if (!remoteEntryInfo.url) {
621
+ error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
621
622
  }
622
- const { remoteEntry } = remoteSnapshot;
623
- const entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);
624
- remoteInfo.type = remoteSnapshot.remoteEntryType;
625
- remoteInfo.entryGlobalName = remoteSnapshot.globalName;
623
+ const entryUrl = getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
624
+ remoteInfo.type = remoteEntryInfo.type;
625
+ remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
626
626
  remoteInfo.entry = entryUrl;
627
627
  remoteInfo.version = remoteSnapshot.version;
628
628
  remoteInfo.buildVersion = remoteSnapshot.buildVersion;
@@ -747,7 +747,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
747
747
  return;
748
748
  }
749
749
  }
750
- const remoteEntryUrl = getResourceUrl(moduleInfoSnapshot, 'remoteEntry' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntry : '');
750
+ const remoteEntryUrl = getResourceUrl(moduleInfoSnapshot, getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
751
751
  if (remoteEntryUrl) {
752
752
  entryAssets.push({
753
753
  name: remoteInfo.name,
@@ -953,12 +953,13 @@ class SnapshotHandler {
953
953
  // global snapshot includes manifest or module info includes manifest
954
954
  if (globalRemoteSnapshot) {
955
955
  if (isManifestProvider(globalRemoteSnapshot)) {
956
- const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
956
+ const remoteEntry = isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || '';
957
+ const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
957
958
  // eslint-disable-next-line @typescript-eslint/no-shadow
958
959
  const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
959
960
  // The global remote may be overridden
960
961
  // Therefore, set the snapshot key to the global address of the actual request
961
- entry: globalRemoteSnapshot.remoteEntry
962
+ entry: remoteEntry
962
963
  }), moduleSnapshot);
963
964
  return {
964
965
  remoteSnapshot: moduleSnapshot,
@@ -1490,6 +1491,7 @@ class RemoteHandler {
1490
1491
  moduleInstance: module,
1491
1492
  origin: host
1492
1493
  });
1494
+ this.idToModuleNameMap[id] = remote.name;
1493
1495
  if (typeof moduleWrapper === 'function') {
1494
1496
  return moduleWrapper;
1495
1497
  }
@@ -1618,7 +1620,7 @@ class RemoteHandler {
1618
1620
  }
1619
1621
  // Set the remote entry to a complete path
1620
1622
  if ('entry' in remote) {
1621
- if (isBrowserEnv() && !remote.entry.startsWith('http')) {
1623
+ if (isBrowserEnv$1() && !remote.entry.startsWith('http')) {
1622
1624
  remote.entry = new URL(remote.entry, window.location.origin).href;
1623
1625
  }
1624
1626
  }
@@ -1656,7 +1658,8 @@ class RemoteHandler {
1656
1658
  }
1657
1659
  const loadedModule = host.moduleCache.get(remote.name);
1658
1660
  if (loadedModule) {
1659
- const key = loadedModule.remoteInfo.entryGlobalName;
1661
+ const remoteInfo = loadedModule.remoteInfo;
1662
+ const key = remoteInfo.entryGlobalName;
1660
1663
  if (globalThis[key]) {
1661
1664
  delete globalThis[key];
1662
1665
  }
@@ -1664,6 +1667,62 @@ class RemoteHandler {
1664
1667
  if (globalLoading[remoteEntryUniqueKey]) {
1665
1668
  delete globalLoading[remoteEntryUniqueKey];
1666
1669
  }
1670
+ // delete un loaded shared and instance
1671
+ let remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1672
+ const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1673
+ if (remoteInfo.buildVersion) {
1674
+ return ins.options.id === remoteInsId;
1675
+ } else {
1676
+ return ins.name === remoteInsId;
1677
+ }
1678
+ });
1679
+ if (remoteInsIndex !== -1) {
1680
+ const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1681
+ remoteInsId = remoteIns.options.id || remoteInsId;
1682
+ const globalShareScopeMap = getGlobalShareScope();
1683
+ let isAllSharedNotUsed = true;
1684
+ const needDeleteKeys = [];
1685
+ Object.keys(globalShareScopeMap).forEach((instId)=>{
1686
+ Object.keys(globalShareScopeMap[instId]).forEach((shareScope)=>{
1687
+ Object.keys(globalShareScopeMap[instId][shareScope]).forEach((shareName)=>{
1688
+ Object.keys(globalShareScopeMap[instId][shareScope][shareName]).forEach((shareVersion)=>{
1689
+ const shared = globalShareScopeMap[instId][shareScope][shareName][shareVersion];
1690
+ if (shared.from === remoteInfo.name) {
1691
+ if (shared.loaded || shared.loading) {
1692
+ shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1693
+ if (shared.useIn.length) {
1694
+ isAllSharedNotUsed = false;
1695
+ } else {
1696
+ needDeleteKeys.push([
1697
+ instId,
1698
+ shareScope,
1699
+ shareName,
1700
+ shareVersion
1701
+ ]);
1702
+ }
1703
+ } else {
1704
+ needDeleteKeys.push([
1705
+ instId,
1706
+ shareScope,
1707
+ shareName,
1708
+ shareVersion
1709
+ ]);
1710
+ }
1711
+ }
1712
+ });
1713
+ });
1714
+ });
1715
+ });
1716
+ if (isAllSharedNotUsed) {
1717
+ remoteIns.shareScopeMap = {};
1718
+ delete globalShareScopeMap[remoteInsId];
1719
+ }
1720
+ needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1721
+ var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1722
+ (_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];
1723
+ });
1724
+ globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1725
+ }
1667
1726
  host.moduleCache.delete(remote.name);
1668
1727
  }
1669
1728
  }
@@ -1679,6 +1738,7 @@ class RemoteHandler {
1679
1738
  afterPreloadRemote: new AsyncHook()
1680
1739
  });
1681
1740
  this.host = host;
1741
+ this.idToModuleNameMap = {};
1682
1742
  }
1683
1743
  }
1684
1744
 
@@ -1801,7 +1861,7 @@ class FederationHost {
1801
1861
  // maybe will change, temporarily for internal use only
1802
1862
  initContainer: new AsyncWaterfallHook('initContainer')
1803
1863
  });
1804
- this.version = "0.1.12";
1864
+ this.version = "0.1.13";
1805
1865
  this.moduleCache = new Map();
1806
1866
  this.loaderHook = new PluginSystem({
1807
1867
  // FIXME: may not be suitable , not open to the public yet
@@ -1822,7 +1882,7 @@ class FederationHost {
1822
1882
  ],
1823
1883
  remotes: [],
1824
1884
  shared: {},
1825
- inBrowser: isBrowserEnv$1()
1885
+ inBrowser: isBrowserEnv()
1826
1886
  };
1827
1887
  this.name = userOptions.name;
1828
1888
  this.options = defaultOptions;
@@ -1890,7 +1950,10 @@ function registerPlugins(...args) {
1890
1950
  // eslint-disable-next-line prefer-spread
1891
1951
  return FederationInstance.registerPlugins.apply(FederationInstance, args);
1892
1952
  }
1953
+ function getInstance() {
1954
+ return FederationInstance;
1955
+ }
1893
1956
  // Inject for debug
1894
1957
  setGlobalFederationConstructor(FederationHost);
1895
1958
 
1896
- export { FederationHost, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerPlugins, registerRemotes };
1959
+ export { FederationHost, getInstance, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerPlugins, registerRemotes };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
package/dist/share.cjs.js CHANGED
@@ -76,6 +76,28 @@ 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
+ }
79
101
 
80
102
  function _extends$1() {
81
103
  _extends$1 = Object.assign || function(target) {
@@ -190,7 +212,7 @@ function getGlobalFederationConstructor() {
190
212
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
191
213
  if (isDebug) {
192
214
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
193
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.12";
215
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.13";
194
216
  }
195
217
  }
196
218
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -893,6 +915,7 @@ exports.getInfoWithoutType = getInfoWithoutType;
893
915
  exports.getPreloaded = getPreloaded;
894
916
  exports.getRegisteredShare = getRegisteredShare;
895
917
  exports.getRemoteEntryExports = getRemoteEntryExports;
918
+ exports.getRemoteEntryInfoFromSnapshot = getRemoteEntryInfoFromSnapshot;
896
919
  exports.getTargetSharedOptions = getTargetSharedOptions;
897
920
  exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
898
921
  exports.globalLoading = globalLoading;
package/dist/share.esm.js CHANGED
@@ -74,6 +74,28 @@ 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
+ }
77
99
 
78
100
  function _extends$1() {
79
101
  _extends$1 = Object.assign || function(target) {
@@ -188,7 +210,7 @@ function getGlobalFederationConstructor() {
188
210
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
189
211
  if (isDebug) {
190
212
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
191
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.12";
213
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.13";
192
214
  }
193
215
  }
194
216
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -870,4 +892,4 @@ function getTargetSharedOptions(options) {
870
892
  return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
871
893
  }
872
894
 
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 };
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, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getRegisteredShare as p, arrayOptions as q, getGlobalSnapshotInfoByModuleInfo as r, safeToString as s, addGlobalSnapshot as t, isBrowserEnv as u, setGlobalSnapshotInfoByModuleInfo as v, warn as w, getGlobalSnapshot as x, formatShareConfigs as y, getTargetSharedOptions as z };
@@ -13,3 +13,4 @@ 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,6 +39,10 @@ export declare class SnapshotHandler {
39
39
  remoteSnapshot: ModuleInfo;
40
40
  globalSnapshot: GlobalModuleInfo;
41
41
  }> | never;
42
- private getGlobalRemoteInfo;
42
+ getGlobalRemoteInfo(moduleInfo: Remote): {
43
+ hostGlobalSnapshot: ModuleInfo | undefined;
44
+ globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
45
+ remoteSnapshot: GlobalModuleInfo[string] | undefined;
46
+ };
43
47
  private getManifestJson;
44
48
  }
@@ -15,6 +15,7 @@ export interface LoadRemoteMatch {
15
15
  }
16
16
  export declare class RemoteHandler {
17
17
  host: FederationHost;
18
+ idToModuleNameMap: Record<string, string>;
18
19
  hooks: PluginSystem<{
19
20
  beforeRequest: AsyncWaterfallHook<{
20
21
  id: string;
@@ -1,4 +1,4 @@
1
- import type { RemoteWithEntry } from '@module-federation/sdk';
1
+ import type { RemoteWithEntry, ModuleInfo, RemoteEntryType } 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,3 +11,8 @@ 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-20240511031741",
3
+ "version": "0.0.0-next-20240515062211",
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-20240511031741"
48
+ "@module-federation/sdk": "0.0.0-next-20240515062211"
49
49
  }
50
50
  }