@module-federation/runtime 0.0.0-next-20240701075157 → 0.0.0-next-20240702090143

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 { p as getRegisteredShare, z as getGlobalShareScope, G as Global, J as nativeGlobal, K as resetFederationGlobalInfo, E as getGlobalFederationInstance, H as setGlobalFederationInstance, F as getGlobalFederationConstructor, C as setGlobalFederationConstructor, m as getInfoWithoutType, v as getGlobalSnapshot, L as getTargetSnapshotInfoByModuleInfo, r as getGlobalSnapshotInfoByModuleInfo, u as setGlobalSnapshotInfoByModuleInfo, t as addGlobalSnapshot, c as getRemoteEntryExports, I 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
@@ -223,9 +223,10 @@ let Module = class Module {
223
223
  const remoteEntryExports = await getRemoteEntry({
224
224
  remoteInfo: this.remoteInfo,
225
225
  remoteEntryExports: this.remoteEntryExports,
226
- createScriptHook: (url)=>{
226
+ createScriptHook: (url, attrs)=>{
227
227
  const res = this.host.loaderHook.lifecycle.createScript.emit({
228
- url
228
+ url,
229
+ attrs
229
230
  });
230
231
  if (!res) return;
231
232
  if (typeof document === 'undefined') {
@@ -246,7 +247,7 @@ let Module = class Module {
246
247
  return this.remoteEntryExports;
247
248
  }
248
249
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
249
- async get(id, expose, options) {
250
+ async get(id, expose, options, remoteSnapshot) {
250
251
  const { loadFactory = true } = options || {
251
252
  loadFactory: true
252
253
  };
@@ -279,6 +280,8 @@ let Module = class Module {
279
280
  });
280
281
  await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
281
282
  await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
283
+ id,
284
+ remoteSnapshot,
282
285
  remoteEntryExports
283
286
  }));
284
287
  }
@@ -724,16 +727,16 @@ function _extends$4() {
724
727
  return _extends$4.apply(this, arguments);
725
728
  }
726
729
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
727
- const remoteEntryInfo = share.getRemoteEntryInfoFromSnapshot(remoteSnapshot);
728
- if (!remoteEntryInfo.url) {
729
- share.error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
730
+ if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
731
+ share.error(`The attribute remoteEntry of ${name} must not be undefined.`);
730
732
  }
731
- let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
733
+ const { remoteEntry } = remoteSnapshot;
734
+ let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntry);
732
735
  if (!share.isBrowserEnv() && !entryUrl.startsWith('http')) {
733
736
  entryUrl = `https:${entryUrl}`;
734
737
  }
735
- remoteInfo.type = remoteEntryInfo.type;
736
- remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
738
+ remoteInfo.type = remoteSnapshot.remoteEntryType;
739
+ remoteInfo.entryGlobalName = remoteSnapshot.globalName;
737
740
  remoteInfo.entry = entryUrl;
738
741
  remoteInfo.version = remoteSnapshot.version;
739
742
  remoteInfo.buildVersion = remoteSnapshot.buildVersion;
@@ -858,7 +861,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
858
861
  return;
859
862
  }
860
863
  }
861
- const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, share.getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
864
+ const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, 'remoteEntry' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntry : '');
862
865
  if (remoteEntryUrl) {
863
866
  entryAssets.push({
864
867
  name: remoteInfo.name,
@@ -1005,32 +1008,6 @@ function _extends$3() {
1005
1008
  };
1006
1009
  return _extends$3.apply(this, arguments);
1007
1010
  }
1008
- function getGlobalRemoteInfo(moduleInfo, origin) {
1009
- const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
1010
- name: origin.options.name,
1011
- version: origin.options.version
1012
- });
1013
- // get remote detail info from global
1014
- const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
1015
- if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
1016
- return {
1017
- hostGlobalSnapshot,
1018
- globalSnapshot: share.getGlobalSnapshot(),
1019
- remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
1020
- name: moduleInfo.name,
1021
- version: globalRemoteInfo.matchedVersion
1022
- })
1023
- };
1024
- }
1025
- return {
1026
- hostGlobalSnapshot: undefined,
1027
- globalSnapshot: share.getGlobalSnapshot(),
1028
- remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
1029
- name: moduleInfo.name,
1030
- version: 'version' in moduleInfo ? moduleInfo.version : undefined
1031
- })
1032
- };
1033
- }
1034
1011
  class SnapshotHandler {
1035
1012
  async loadSnapshot(moduleInfo) {
1036
1013
  const { options } = this.HostInstance;
@@ -1090,13 +1067,12 @@ class SnapshotHandler {
1090
1067
  // global snapshot includes manifest or module info includes manifest
1091
1068
  if (globalRemoteSnapshot) {
1092
1069
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
1093
- const remoteEntry = share.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
1094
- const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
1070
+ const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
1095
1071
  // eslint-disable-next-line @typescript-eslint/no-shadow
1096
1072
  const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
1097
1073
  // The global remote may be overridden
1098
1074
  // Therefore, set the snapshot key to the global address of the actual request
1099
- entry: remoteEntry
1075
+ entry: globalRemoteSnapshot.remoteEntry
1100
1076
  }), moduleSnapshot);
1101
1077
  return {
1102
1078
  remoteSnapshot: moduleSnapshot,
@@ -1141,7 +1117,30 @@ class SnapshotHandler {
1141
1117
  }
1142
1118
  }
1143
1119
  getGlobalRemoteInfo(moduleInfo) {
1144
- return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
1120
+ const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
1121
+ name: this.HostInstance.options.name,
1122
+ version: this.HostInstance.options.version
1123
+ });
1124
+ // get remote detail info from global
1125
+ const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
1126
+ if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
1127
+ return {
1128
+ hostGlobalSnapshot,
1129
+ globalSnapshot: share.getGlobalSnapshot(),
1130
+ remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
1131
+ name: moduleInfo.name,
1132
+ version: globalRemoteInfo.matchedVersion
1133
+ })
1134
+ };
1135
+ }
1136
+ return {
1137
+ hostGlobalSnapshot: undefined,
1138
+ globalSnapshot: share.getGlobalSnapshot(),
1139
+ remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
1140
+ name: moduleInfo.name,
1141
+ version: 'version' in moduleInfo ? moduleInfo.version : undefined
1142
+ })
1143
+ };
1145
1144
  }
1146
1145
  async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
1147
1146
  const getManifest = async ()=>{
@@ -1577,29 +1576,6 @@ class RemoteHandler {
1577
1576
  return res;
1578
1577
  }, globalOptions.remotes);
1579
1578
  }
1580
- setIdToRemoteMap(id, remoteMatchInfo) {
1581
- const { remote, expose } = remoteMatchInfo;
1582
- const { name, alias } = remote;
1583
- this.idToRemoteMap[id] = {
1584
- name: remote.name,
1585
- expose
1586
- };
1587
- if (alias && id.startsWith(name)) {
1588
- const idWithAlias = id.replace(name, alias);
1589
- this.idToRemoteMap[idWithAlias] = {
1590
- name: remote.name,
1591
- expose
1592
- };
1593
- return;
1594
- }
1595
- if (alias && id.startsWith(alias)) {
1596
- const idWithName = id.replace(alias, name);
1597
- this.idToRemoteMap[idWithName] = {
1598
- name: remote.name,
1599
- expose
1600
- };
1601
- }
1602
- }
1603
1579
  // eslint-disable-next-line max-lines-per-function
1604
1580
  // eslint-disable-next-line @typescript-eslint/member-ordering
1605
1581
  async loadRemote(id, options) {
@@ -1618,8 +1594,8 @@ class RemoteHandler {
1618
1594
  const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
1619
1595
  id
1620
1596
  });
1621
- const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
1622
- const moduleOrFactory = await module.get(idRes, expose, options);
1597
+ const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
1598
+ const moduleOrFactory = await module.get(idRes, expose, options, remoteSnapshot);
1623
1599
  const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
1624
1600
  id: idRes,
1625
1601
  pkgNameOrAlias,
@@ -1631,7 +1607,6 @@ class RemoteHandler {
1631
1607
  moduleInstance: module,
1632
1608
  origin: host
1633
1609
  });
1634
- this.setIdToRemoteMap(id, remoteMatchInfo);
1635
1610
  if (typeof moduleWrapper === 'function') {
1636
1611
  return moduleWrapper;
1637
1612
  }
@@ -1772,10 +1747,6 @@ class RemoteHandler {
1772
1747
  remote.type = share.DEFAULT_REMOTE_TYPE;
1773
1748
  }
1774
1749
  };
1775
- this.hooks.lifecycle.beforeRegisterRemote.emit({
1776
- remote,
1777
- origin: host
1778
- });
1779
1750
  const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
1780
1751
  if (!registeredRemote) {
1781
1752
  normalizeRemote();
@@ -1803,67 +1774,49 @@ class RemoteHandler {
1803
1774
  }
1804
1775
  }
1805
1776
  removeRemote(remote) {
1806
- try {
1807
- const { host } = this;
1808
- const { name } = remote;
1809
- const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1810
- if (remoteIndex !== -1) {
1811
- host.options.remotes.splice(remoteIndex, 1);
1777
+ const { host } = this;
1778
+ const { name } = remote;
1779
+ const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1780
+ if (remoteIndex !== -1) {
1781
+ host.options.remotes.splice(remoteIndex, 1);
1782
+ }
1783
+ const loadedModule = host.moduleCache.get(remote.name);
1784
+ if (loadedModule) {
1785
+ var _Object_getOwnPropertyDescriptor;
1786
+ const remoteInfo = loadedModule.remoteInfo;
1787
+ const key = remoteInfo.entryGlobalName;
1788
+ if (globalThis[key] && ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable)) {
1789
+ delete globalThis[key];
1812
1790
  }
1813
- const loadedModule = host.moduleCache.get(remote.name);
1814
- if (loadedModule) {
1815
- const remoteInfo = loadedModule.remoteInfo;
1816
- const key = remoteInfo.entryGlobalName;
1817
- if (globalThis[key]) {
1818
- var _Object_getOwnPropertyDescriptor;
1819
- if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
1820
- delete globalThis[key];
1821
- } else {
1822
- // @ts-ignore
1823
- globalThis[key] = undefined;
1824
- }
1825
- }
1826
- const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1827
- if (share.globalLoading[remoteEntryUniqueKey]) {
1828
- delete share.globalLoading[remoteEntryUniqueKey];
1791
+ const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1792
+ if (share.globalLoading[remoteEntryUniqueKey]) {
1793
+ delete share.globalLoading[remoteEntryUniqueKey];
1794
+ }
1795
+ // delete un loaded shared and instance
1796
+ let remoteInsId = remoteInfo.buildVersion ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1797
+ const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1798
+ if (remoteInfo.buildVersion) {
1799
+ return ins.options.id === remoteInsId;
1800
+ } else {
1801
+ return ins.name === remoteInsId;
1829
1802
  }
1830
- host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
1831
- // delete unloaded shared and instance
1832
- let remoteInsId = remoteInfo.buildVersion ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1833
- const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1834
- if (remoteInfo.buildVersion) {
1835
- return ins.options.id === remoteInsId;
1836
- } else {
1837
- return ins.name === remoteInsId;
1838
- }
1839
- });
1840
- if (remoteInsIndex !== -1) {
1841
- const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1842
- remoteInsId = remoteIns.options.id || remoteInsId;
1843
- const globalShareScopeMap = share.getGlobalShareScope();
1844
- let isAllSharedNotUsed = true;
1845
- const needDeleteKeys = [];
1846
- Object.keys(globalShareScopeMap).forEach((instId)=>{
1847
- const shareScopeMap = globalShareScopeMap[instId];
1848
- shareScopeMap && Object.keys(shareScopeMap).forEach((shareScope)=>{
1849
- const shareScopeVal = shareScopeMap[shareScope];
1850
- shareScopeVal && Object.keys(shareScopeVal).forEach((shareName)=>{
1851
- const sharedPkgs = shareScopeVal[shareName];
1852
- sharedPkgs && Object.keys(sharedPkgs).forEach((shareVersion)=>{
1853
- const shared = sharedPkgs[shareVersion];
1854
- if (shared && typeof shared === 'object' && shared.from === remoteInfo.name) {
1855
- if (shared.loaded || shared.loading) {
1856
- shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1857
- if (shared.useIn.length) {
1858
- isAllSharedNotUsed = false;
1859
- } else {
1860
- needDeleteKeys.push([
1861
- instId,
1862
- shareScope,
1863
- shareName,
1864
- shareVersion
1865
- ]);
1866
- }
1803
+ });
1804
+ if (remoteInsIndex !== -1) {
1805
+ const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1806
+ remoteInsId = remoteIns.options.id || remoteInsId;
1807
+ const globalShareScopeMap = share.getGlobalShareScope();
1808
+ let isAllSharedNotUsed = true;
1809
+ const needDeleteKeys = [];
1810
+ Object.keys(globalShareScopeMap).forEach((instId)=>{
1811
+ Object.keys(globalShareScopeMap[instId]).forEach((shareScope)=>{
1812
+ Object.keys(globalShareScopeMap[instId][shareScope]).forEach((shareName)=>{
1813
+ Object.keys(globalShareScopeMap[instId][shareScope][shareName]).forEach((shareVersion)=>{
1814
+ const shared = globalShareScopeMap[instId][shareScope][shareName][shareVersion];
1815
+ if (shared.from === remoteInfo.name) {
1816
+ if (shared.loaded || shared.loading) {
1817
+ shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1818
+ if (shared.useIn.length) {
1819
+ isAllSharedNotUsed = false;
1867
1820
  } else {
1868
1821
  needDeleteKeys.push([
1869
1822
  instId,
@@ -1872,37 +1825,34 @@ class RemoteHandler {
1872
1825
  shareVersion
1873
1826
  ]);
1874
1827
  }
1828
+ } else {
1829
+ needDeleteKeys.push([
1830
+ instId,
1831
+ shareScope,
1832
+ shareName,
1833
+ shareVersion
1834
+ ]);
1875
1835
  }
1876
- });
1836
+ }
1877
1837
  });
1878
1838
  });
1879
1839
  });
1880
- if (isAllSharedNotUsed) {
1881
- remoteIns.shareScopeMap = {};
1882
- delete globalShareScopeMap[remoteInsId];
1883
- }
1884
- needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1885
- var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1886
- (_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];
1887
- });
1888
- globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1889
- }
1890
- const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
1891
- if (hostGlobalSnapshot) {
1892
- const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
1893
- if (remoteKey) {
1894
- delete hostGlobalSnapshot.remotesInfo[remoteKey];
1895
- }
1840
+ });
1841
+ if (isAllSharedNotUsed) {
1842
+ remoteIns.shareScopeMap = {};
1843
+ delete globalShareScopeMap[remoteInsId];
1896
1844
  }
1897
- host.moduleCache.delete(remote.name);
1845
+ needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1846
+ var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1847
+ (_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];
1848
+ });
1849
+ globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1898
1850
  }
1899
- } catch (err) {
1900
- console.log('removeRemote fail: ', err);
1851
+ host.moduleCache.delete(remote.name);
1901
1852
  }
1902
1853
  }
1903
1854
  constructor(host){
1904
1855
  this.hooks = new PluginSystem({
1905
- beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
1906
1856
  registerRemote: new SyncWaterfallHook('registerRemote'),
1907
1857
  beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1908
1858
  onLoad: new AsyncHook('onLoad'),
@@ -1914,7 +1864,6 @@ class RemoteHandler {
1914
1864
  afterPreloadRemote: new AsyncHook()
1915
1865
  });
1916
1866
  this.host = host;
1917
- this.idToRemoteMap = {};
1918
1867
  }
1919
1868
  }
1920
1869
 
@@ -2126,9 +2075,6 @@ function registerPlugins(...args) {
2126
2075
  // eslint-disable-next-line prefer-spread
2127
2076
  return FederationInstance.registerPlugins.apply(FederationInstance, args);
2128
2077
  }
2129
- function getInstance() {
2130
- return FederationInstance;
2131
- }
2132
2078
  // Inject for debug
2133
2079
  share.setGlobalFederationConstructor(FederationHost);
2134
2080
 
@@ -2142,7 +2088,7 @@ Object.defineProperty(exports, 'loadScriptNode', {
2142
2088
  get: function () { return sdk.loadScriptNode; }
2143
2089
  });
2144
2090
  exports.FederationHost = FederationHost;
2145
- exports.getInstance = getInstance;
2091
+ exports.Module = Module;
2146
2092
  exports.getRemoteEntry = getRemoteEntry;
2147
2093
  exports.getRemoteInfo = getRemoteInfo;
2148
2094
  exports.init = init;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
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, G as Global, x as getGlobalSnapshot, 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';
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 isBrowserEnv, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getRegisteredShare, q as arrayOptions, r as getGlobalSnapshotInfoByModuleInfo, t as addGlobalSnapshot, u as setGlobalSnapshotInfoByModuleInfo, v as getGlobalSnapshot, G as Global, x as formatShareConfigs, y as getTargetSharedOptions, z as getGlobalShareScope, A as addUniqueItem, B as getBuilderId, 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
3
  import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, createScript, 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
 
@@ -221,9 +221,10 @@ let Module = class Module {
221
221
  const remoteEntryExports = await getRemoteEntry({
222
222
  remoteInfo: this.remoteInfo,
223
223
  remoteEntryExports: this.remoteEntryExports,
224
- createScriptHook: (url)=>{
224
+ createScriptHook: (url, attrs)=>{
225
225
  const res = this.host.loaderHook.lifecycle.createScript.emit({
226
- url
226
+ url,
227
+ attrs
227
228
  });
228
229
  if (!res) return;
229
230
  if (typeof document === 'undefined') {
@@ -244,7 +245,7 @@ let Module = class Module {
244
245
  return this.remoteEntryExports;
245
246
  }
246
247
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
247
- async get(id, expose, options) {
248
+ async get(id, expose, options, remoteSnapshot) {
248
249
  const { loadFactory = true } = options || {
249
250
  loadFactory: true
250
251
  };
@@ -277,6 +278,8 @@ let Module = class Module {
277
278
  });
278
279
  await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
279
280
  await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
281
+ id,
282
+ remoteSnapshot,
280
283
  remoteEntryExports
281
284
  }));
282
285
  }
@@ -722,16 +725,16 @@ function _extends$4() {
722
725
  return _extends$4.apply(this, arguments);
723
726
  }
724
727
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
725
- const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
726
- if (!remoteEntryInfo.url) {
727
- error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
728
+ if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
729
+ error(`The attribute remoteEntry of ${name} must not be undefined.`);
728
730
  }
729
- let entryUrl = getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
731
+ const { remoteEntry } = remoteSnapshot;
732
+ let entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);
730
733
  if (!isBrowserEnv() && !entryUrl.startsWith('http')) {
731
734
  entryUrl = `https:${entryUrl}`;
732
735
  }
733
- remoteInfo.type = remoteEntryInfo.type;
734
- remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
736
+ remoteInfo.type = remoteSnapshot.remoteEntryType;
737
+ remoteInfo.entryGlobalName = remoteSnapshot.globalName;
735
738
  remoteInfo.entry = entryUrl;
736
739
  remoteInfo.version = remoteSnapshot.version;
737
740
  remoteInfo.buildVersion = remoteSnapshot.buildVersion;
@@ -856,7 +859,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
856
859
  return;
857
860
  }
858
861
  }
859
- const remoteEntryUrl = getResourceUrl(moduleInfoSnapshot, getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
862
+ const remoteEntryUrl = getResourceUrl(moduleInfoSnapshot, 'remoteEntry' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntry : '');
860
863
  if (remoteEntryUrl) {
861
864
  entryAssets.push({
862
865
  name: remoteInfo.name,
@@ -1003,32 +1006,6 @@ function _extends$3() {
1003
1006
  };
1004
1007
  return _extends$3.apply(this, arguments);
1005
1008
  }
1006
- function getGlobalRemoteInfo(moduleInfo, origin) {
1007
- const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
1008
- name: origin.options.name,
1009
- version: origin.options.version
1010
- });
1011
- // get remote detail info from global
1012
- const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
1013
- if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
1014
- return {
1015
- hostGlobalSnapshot,
1016
- globalSnapshot: getGlobalSnapshot(),
1017
- remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
1018
- name: moduleInfo.name,
1019
- version: globalRemoteInfo.matchedVersion
1020
- })
1021
- };
1022
- }
1023
- return {
1024
- hostGlobalSnapshot: undefined,
1025
- globalSnapshot: getGlobalSnapshot(),
1026
- remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
1027
- name: moduleInfo.name,
1028
- version: 'version' in moduleInfo ? moduleInfo.version : undefined
1029
- })
1030
- };
1031
- }
1032
1009
  class SnapshotHandler {
1033
1010
  async loadSnapshot(moduleInfo) {
1034
1011
  const { options } = this.HostInstance;
@@ -1088,13 +1065,12 @@ class SnapshotHandler {
1088
1065
  // global snapshot includes manifest or module info includes manifest
1089
1066
  if (globalRemoteSnapshot) {
1090
1067
  if (isManifestProvider(globalRemoteSnapshot)) {
1091
- const remoteEntry = isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
1092
- const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
1068
+ const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
1093
1069
  // eslint-disable-next-line @typescript-eslint/no-shadow
1094
1070
  const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
1095
1071
  // The global remote may be overridden
1096
1072
  // Therefore, set the snapshot key to the global address of the actual request
1097
- entry: remoteEntry
1073
+ entry: globalRemoteSnapshot.remoteEntry
1098
1074
  }), moduleSnapshot);
1099
1075
  return {
1100
1076
  remoteSnapshot: moduleSnapshot,
@@ -1139,7 +1115,30 @@ class SnapshotHandler {
1139
1115
  }
1140
1116
  }
1141
1117
  getGlobalRemoteInfo(moduleInfo) {
1142
- return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
1118
+ const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
1119
+ name: this.HostInstance.options.name,
1120
+ version: this.HostInstance.options.version
1121
+ });
1122
+ // get remote detail info from global
1123
+ const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
1124
+ if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
1125
+ return {
1126
+ hostGlobalSnapshot,
1127
+ globalSnapshot: getGlobalSnapshot(),
1128
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
1129
+ name: moduleInfo.name,
1130
+ version: globalRemoteInfo.matchedVersion
1131
+ })
1132
+ };
1133
+ }
1134
+ return {
1135
+ hostGlobalSnapshot: undefined,
1136
+ globalSnapshot: getGlobalSnapshot(),
1137
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
1138
+ name: moduleInfo.name,
1139
+ version: 'version' in moduleInfo ? moduleInfo.version : undefined
1140
+ })
1141
+ };
1143
1142
  }
1144
1143
  async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
1145
1144
  const getManifest = async ()=>{
@@ -1575,29 +1574,6 @@ class RemoteHandler {
1575
1574
  return res;
1576
1575
  }, globalOptions.remotes);
1577
1576
  }
1578
- setIdToRemoteMap(id, remoteMatchInfo) {
1579
- const { remote, expose } = remoteMatchInfo;
1580
- const { name, alias } = remote;
1581
- this.idToRemoteMap[id] = {
1582
- name: remote.name,
1583
- expose
1584
- };
1585
- if (alias && id.startsWith(name)) {
1586
- const idWithAlias = id.replace(name, alias);
1587
- this.idToRemoteMap[idWithAlias] = {
1588
- name: remote.name,
1589
- expose
1590
- };
1591
- return;
1592
- }
1593
- if (alias && id.startsWith(alias)) {
1594
- const idWithName = id.replace(alias, name);
1595
- this.idToRemoteMap[idWithName] = {
1596
- name: remote.name,
1597
- expose
1598
- };
1599
- }
1600
- }
1601
1577
  // eslint-disable-next-line max-lines-per-function
1602
1578
  // eslint-disable-next-line @typescript-eslint/member-ordering
1603
1579
  async loadRemote(id, options) {
@@ -1616,8 +1592,8 @@ class RemoteHandler {
1616
1592
  const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
1617
1593
  id
1618
1594
  });
1619
- const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
1620
- const moduleOrFactory = await module.get(idRes, expose, options);
1595
+ const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
1596
+ const moduleOrFactory = await module.get(idRes, expose, options, remoteSnapshot);
1621
1597
  const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
1622
1598
  id: idRes,
1623
1599
  pkgNameOrAlias,
@@ -1629,7 +1605,6 @@ class RemoteHandler {
1629
1605
  moduleInstance: module,
1630
1606
  origin: host
1631
1607
  });
1632
- this.setIdToRemoteMap(id, remoteMatchInfo);
1633
1608
  if (typeof moduleWrapper === 'function') {
1634
1609
  return moduleWrapper;
1635
1610
  }
@@ -1770,10 +1745,6 @@ class RemoteHandler {
1770
1745
  remote.type = DEFAULT_REMOTE_TYPE;
1771
1746
  }
1772
1747
  };
1773
- this.hooks.lifecycle.beforeRegisterRemote.emit({
1774
- remote,
1775
- origin: host
1776
- });
1777
1748
  const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
1778
1749
  if (!registeredRemote) {
1779
1750
  normalizeRemote();
@@ -1801,67 +1772,49 @@ class RemoteHandler {
1801
1772
  }
1802
1773
  }
1803
1774
  removeRemote(remote) {
1804
- try {
1805
- const { host } = this;
1806
- const { name } = remote;
1807
- const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1808
- if (remoteIndex !== -1) {
1809
- host.options.remotes.splice(remoteIndex, 1);
1775
+ const { host } = this;
1776
+ const { name } = remote;
1777
+ const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
1778
+ if (remoteIndex !== -1) {
1779
+ host.options.remotes.splice(remoteIndex, 1);
1780
+ }
1781
+ const loadedModule = host.moduleCache.get(remote.name);
1782
+ if (loadedModule) {
1783
+ var _Object_getOwnPropertyDescriptor;
1784
+ const remoteInfo = loadedModule.remoteInfo;
1785
+ const key = remoteInfo.entryGlobalName;
1786
+ if (globalThis[key] && ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable)) {
1787
+ delete globalThis[key];
1810
1788
  }
1811
- const loadedModule = host.moduleCache.get(remote.name);
1812
- if (loadedModule) {
1813
- const remoteInfo = loadedModule.remoteInfo;
1814
- const key = remoteInfo.entryGlobalName;
1815
- if (globalThis[key]) {
1816
- var _Object_getOwnPropertyDescriptor;
1817
- if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
1818
- delete globalThis[key];
1819
- } else {
1820
- // @ts-ignore
1821
- globalThis[key] = undefined;
1822
- }
1823
- }
1824
- const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1825
- if (globalLoading[remoteEntryUniqueKey]) {
1826
- delete globalLoading[remoteEntryUniqueKey];
1789
+ const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1790
+ if (globalLoading[remoteEntryUniqueKey]) {
1791
+ delete globalLoading[remoteEntryUniqueKey];
1792
+ }
1793
+ // delete un loaded shared and instance
1794
+ let remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1795
+ const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1796
+ if (remoteInfo.buildVersion) {
1797
+ return ins.options.id === remoteInsId;
1798
+ } else {
1799
+ return ins.name === remoteInsId;
1827
1800
  }
1828
- host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
1829
- // delete unloaded shared and instance
1830
- let remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1831
- const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1832
- if (remoteInfo.buildVersion) {
1833
- return ins.options.id === remoteInsId;
1834
- } else {
1835
- return ins.name === remoteInsId;
1836
- }
1837
- });
1838
- if (remoteInsIndex !== -1) {
1839
- const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1840
- remoteInsId = remoteIns.options.id || remoteInsId;
1841
- const globalShareScopeMap = getGlobalShareScope();
1842
- let isAllSharedNotUsed = true;
1843
- const needDeleteKeys = [];
1844
- Object.keys(globalShareScopeMap).forEach((instId)=>{
1845
- const shareScopeMap = globalShareScopeMap[instId];
1846
- shareScopeMap && Object.keys(shareScopeMap).forEach((shareScope)=>{
1847
- const shareScopeVal = shareScopeMap[shareScope];
1848
- shareScopeVal && Object.keys(shareScopeVal).forEach((shareName)=>{
1849
- const sharedPkgs = shareScopeVal[shareName];
1850
- sharedPkgs && Object.keys(sharedPkgs).forEach((shareVersion)=>{
1851
- const shared = sharedPkgs[shareVersion];
1852
- if (shared && typeof shared === 'object' && shared.from === remoteInfo.name) {
1853
- if (shared.loaded || shared.loading) {
1854
- shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1855
- if (shared.useIn.length) {
1856
- isAllSharedNotUsed = false;
1857
- } else {
1858
- needDeleteKeys.push([
1859
- instId,
1860
- shareScope,
1861
- shareName,
1862
- shareVersion
1863
- ]);
1864
- }
1801
+ });
1802
+ if (remoteInsIndex !== -1) {
1803
+ const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1804
+ remoteInsId = remoteIns.options.id || remoteInsId;
1805
+ const globalShareScopeMap = getGlobalShareScope();
1806
+ let isAllSharedNotUsed = true;
1807
+ const needDeleteKeys = [];
1808
+ Object.keys(globalShareScopeMap).forEach((instId)=>{
1809
+ Object.keys(globalShareScopeMap[instId]).forEach((shareScope)=>{
1810
+ Object.keys(globalShareScopeMap[instId][shareScope]).forEach((shareName)=>{
1811
+ Object.keys(globalShareScopeMap[instId][shareScope][shareName]).forEach((shareVersion)=>{
1812
+ const shared = globalShareScopeMap[instId][shareScope][shareName][shareVersion];
1813
+ if (shared.from === remoteInfo.name) {
1814
+ if (shared.loaded || shared.loading) {
1815
+ shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
1816
+ if (shared.useIn.length) {
1817
+ isAllSharedNotUsed = false;
1865
1818
  } else {
1866
1819
  needDeleteKeys.push([
1867
1820
  instId,
@@ -1870,37 +1823,34 @@ class RemoteHandler {
1870
1823
  shareVersion
1871
1824
  ]);
1872
1825
  }
1826
+ } else {
1827
+ needDeleteKeys.push([
1828
+ instId,
1829
+ shareScope,
1830
+ shareName,
1831
+ shareVersion
1832
+ ]);
1873
1833
  }
1874
- });
1834
+ }
1875
1835
  });
1876
1836
  });
1877
1837
  });
1878
- if (isAllSharedNotUsed) {
1879
- remoteIns.shareScopeMap = {};
1880
- delete globalShareScopeMap[remoteInsId];
1881
- }
1882
- needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1883
- var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1884
- (_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];
1885
- });
1886
- globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1887
- }
1888
- const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
1889
- if (hostGlobalSnapshot) {
1890
- const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
1891
- if (remoteKey) {
1892
- delete hostGlobalSnapshot.remotesInfo[remoteKey];
1893
- }
1838
+ });
1839
+ if (isAllSharedNotUsed) {
1840
+ remoteIns.shareScopeMap = {};
1841
+ delete globalShareScopeMap[remoteInsId];
1894
1842
  }
1895
- host.moduleCache.delete(remote.name);
1843
+ needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
1844
+ var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1845
+ (_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];
1846
+ });
1847
+ globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1896
1848
  }
1897
- } catch (err) {
1898
- console.log('removeRemote fail: ', err);
1849
+ host.moduleCache.delete(remote.name);
1899
1850
  }
1900
1851
  }
1901
1852
  constructor(host){
1902
1853
  this.hooks = new PluginSystem({
1903
- beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
1904
1854
  registerRemote: new SyncWaterfallHook('registerRemote'),
1905
1855
  beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1906
1856
  onLoad: new AsyncHook('onLoad'),
@@ -1912,7 +1862,6 @@ class RemoteHandler {
1912
1862
  afterPreloadRemote: new AsyncHook()
1913
1863
  });
1914
1864
  this.host = host;
1915
- this.idToRemoteMap = {};
1916
1865
  }
1917
1866
  }
1918
1867
 
@@ -2124,10 +2073,7 @@ function registerPlugins(...args) {
2124
2073
  // eslint-disable-next-line prefer-spread
2125
2074
  return FederationInstance.registerPlugins.apply(FederationInstance, args);
2126
2075
  }
2127
- function getInstance() {
2128
- return FederationInstance;
2129
- }
2130
2076
  // Inject for debug
2131
2077
  setGlobalFederationConstructor(FederationHost);
2132
2078
 
2133
- export { FederationHost, getInstance, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerPlugins, registerRemotes };
2079
+ export { FederationHost, Module, 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 { addUniqueItem as A, getBuilderId 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, isBrowserEnv 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, setGlobalSnapshotInfoByModuleInfo as u, getGlobalSnapshot as v, warn as w, formatShareConfigs as x, getTargetSharedOptions as y, getGlobalShareScope as z };
@@ -1,4 +1,4 @@
1
- import type { CreateScriptHookReturn } from '@module-federation/sdk';
1
+ import type { CreateScriptHookReturn, ModuleInfo } from '@module-federation/sdk';
2
2
  import { Options, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions } from './type';
3
3
  import { Module } from './module';
4
4
  import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
@@ -32,6 +32,8 @@ export declare class FederationHost {
32
32
  remoteInfo: RemoteInfo;
33
33
  remoteEntryExports: RemoteEntryExports;
34
34
  origin: FederationHost;
35
+ id: string;
36
+ remoteSnapshot?: ModuleInfo;
35
37
  }>;
36
38
  }>;
37
39
  version: string;
@@ -51,6 +53,7 @@ export declare class FederationHost {
51
53
  }>;
52
54
  createScript: SyncHook<[{
53
55
  url: string;
56
+ attrs?: Record<string, any>;
54
57
  }], CreateScriptHookReturn>;
55
58
  createLink: SyncHook<[{
56
59
  url: string;
@@ -4,6 +4,7 @@ export { FederationHost } from './core';
4
4
  export { registerGlobalPlugins } from './global';
5
5
  export { getRemoteEntry, getRemoteInfo } from './utils';
6
6
  export { loadScript, loadScriptNode } from '@module-federation/sdk';
7
+ export { Module } from './module';
7
8
  export type { Federation } from './global';
8
9
  export type { FederationRuntimePlugin };
9
10
  export declare function init(options: UserOptions): FederationHost;
@@ -13,4 +14,3 @@ export declare function loadShareSync<T>(...args: Parameters<FederationHost['loa
13
14
  export declare function preloadRemote(...args: Parameters<FederationHost['preloadRemote']>): ReturnType<FederationHost['preloadRemote']>;
14
15
  export declare function registerRemotes(...args: Parameters<FederationHost['registerRemotes']>): ReturnType<FederationHost['registerRemotes']>;
15
16
  export declare function registerPlugins(...args: Parameters<FederationHost['registerPlugins']>): ReturnType<FederationHost['registerRemotes']>;
16
- export declare function getInstance(): FederationHost | null;
@@ -1,3 +1,4 @@
1
+ import { ModuleInfo } from '@module-federation/sdk';
1
2
  import { FederationHost } from '../core';
2
3
  import { RemoteEntryExports, RemoteInfo } from '../type';
3
4
  export type ModuleOptions = ConstructorParameters<typeof Module>[0];
@@ -14,7 +15,7 @@ declare class Module {
14
15
  getEntry(): Promise<RemoteEntryExports>;
15
16
  get(id: string, expose: string, options?: {
16
17
  loadFactory?: boolean;
17
- }): Promise<any>;
18
+ }, remoteSnapshot?: ModuleInfo): Promise<any>;
18
19
  private wraperFactory;
19
20
  }
20
21
  export { Module };
@@ -3,11 +3,6 @@ import { Options, Remote } from '../../type';
3
3
  import { getGlobalSnapshot } from '../../global';
4
4
  import { PluginSystem, AsyncHook, AsyncWaterfallHook } from '../../utils/hooks';
5
5
  import { FederationHost } from '../../core';
6
- export declare function getGlobalRemoteInfo(moduleInfo: Remote, origin: FederationHost): {
7
- hostGlobalSnapshot: ModuleInfo | undefined;
8
- globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
9
- remoteSnapshot: GlobalModuleInfo[string] | undefined;
10
- };
11
6
  export declare class SnapshotHandler {
12
7
  loadingHostSnapshot: Promise<GlobalModuleInfo | void> | null;
13
8
  HostInstance: FederationHost;
@@ -44,10 +39,6 @@ export declare class SnapshotHandler {
44
39
  remoteSnapshot: ModuleInfo;
45
40
  globalSnapshot: GlobalModuleInfo;
46
41
  }> | never;
47
- getGlobalRemoteInfo(moduleInfo: Remote): {
48
- hostGlobalSnapshot: ModuleInfo | undefined;
49
- globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
50
- remoteSnapshot: GlobalModuleInfo[string] | undefined;
51
- };
42
+ private getGlobalRemoteInfo;
52
43
  private getManifestJson;
53
44
  }
@@ -15,15 +15,7 @@ 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
- beforeRegisterRemote: SyncWaterfallHook<{
24
- remote: Remote;
25
- origin: FederationHost;
26
- }>;
27
19
  registerRemote: SyncWaterfallHook<{
28
20
  remote: Remote;
29
21
  origin: FederationHost;
@@ -44,14 +36,14 @@ export declare class RemoteHandler {
44
36
  exposeModuleFactory: any;
45
37
  moduleInstance: Module;
46
38
  }], void>;
47
- handlePreloadModule: SyncHook<{
39
+ handlePreloadModule: SyncHook<[{
48
40
  id: string;
49
41
  name: string;
50
42
  remote: Remote;
51
43
  remoteSnapshot: ModuleInfo;
52
44
  preloadConfig: PreloadRemoteArgs;
53
45
  origin: FederationHost;
54
- }, void>;
46
+ }], void>;
55
47
  errorLoadRemote: AsyncHook<[{
56
48
  id: string;
57
49
  error: unknown;
@@ -81,7 +73,6 @@ export declare class RemoteHandler {
81
73
  }>;
82
74
  constructor(host: FederationHost);
83
75
  formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions): Remote[];
84
- setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch): void;
85
76
  loadRemote<T>(id: string, options?: {
86
77
  loadFactory?: boolean;
87
78
  from: 'build' | 'runtime';
@@ -8,12 +8,12 @@ export declare function loadEntryScript({ name, globalName, entry, createScriptH
8
8
  name: string;
9
9
  globalName: string;
10
10
  entry: string;
11
- createScriptHook?: (url: string) => CreateScriptHookReturn;
11
+ createScriptHook?: (url: string, attrs?: Record<string, any> | undefined) => CreateScriptHookReturn;
12
12
  }): Promise<RemoteEntryExports>;
13
13
  export declare function getRemoteEntryUniqueKey(remoteInfo: RemoteInfo): string;
14
14
  export declare function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook, }: {
15
15
  remoteInfo: RemoteInfo;
16
16
  remoteEntryExports?: RemoteEntryExports | undefined;
17
- createScriptHook?: (url: string) => CreateScriptHookReturn;
17
+ createScriptHook?: (url: string, attrs?: Record<string, any> | undefined) => CreateScriptHookReturn;
18
18
  }): Promise<RemoteEntryExports | void>;
19
19
  export declare function getRemoteInfo(remote: Remote): RemoteInfo;
@@ -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-20240701075157",
3
+ "version": "0.0.0-next-20240702090143",
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-20240701075157"
48
+ "@module-federation/sdk": "0.0.0-next-20240702090143"
49
49
  }
50
50
  }