@module-federation/runtime 0.2.8 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers.esm.js +1 -1
- package/dist/index.cjs.js +154 -93
- package/dist/index.esm.js +156 -96
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +24 -1
- package/dist/share.esm.js +24 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +10 -1
- package/dist/src/remote/index.d.ts +9 -0
- package/dist/src/utils/tool.d.ts +6 -1
- package/package.json +2 -2
package/dist/helpers.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
2
2
|
|
|
3
3
|
const ShareUtils = {
|
|
4
4
|
getRegisteredShare,
|
package/dist/index.cjs.js
CHANGED
|
@@ -746,16 +746,16 @@ function _extends$4() {
|
|
|
746
746
|
return _extends$4.apply(this, arguments);
|
|
747
747
|
}
|
|
748
748
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
749
|
-
|
|
750
|
-
|
|
749
|
+
const remoteEntryInfo = share.getRemoteEntryInfoFromSnapshot(remoteSnapshot);
|
|
750
|
+
if (!remoteEntryInfo.url) {
|
|
751
|
+
share.error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
|
|
751
752
|
}
|
|
752
|
-
|
|
753
|
-
let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntry);
|
|
753
|
+
let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
|
|
754
754
|
if (!share.isBrowserEnv() && !entryUrl.startsWith('http')) {
|
|
755
755
|
entryUrl = `https:${entryUrl}`;
|
|
756
756
|
}
|
|
757
|
-
remoteInfo.type =
|
|
758
|
-
remoteInfo.entryGlobalName =
|
|
757
|
+
remoteInfo.type = remoteEntryInfo.type;
|
|
758
|
+
remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
|
|
759
759
|
remoteInfo.entry = entryUrl;
|
|
760
760
|
remoteInfo.version = remoteSnapshot.version;
|
|
761
761
|
remoteInfo.buildVersion = remoteSnapshot.buildVersion;
|
|
@@ -880,7 +880,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
880
880
|
return;
|
|
881
881
|
}
|
|
882
882
|
}
|
|
883
|
-
const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot,
|
|
883
|
+
const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, share.getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
|
|
884
884
|
if (remoteEntryUrl) {
|
|
885
885
|
entryAssets.push({
|
|
886
886
|
name: remoteInfo.name,
|
|
@@ -1027,6 +1027,32 @@ function _extends$3() {
|
|
|
1027
1027
|
};
|
|
1028
1028
|
return _extends$3.apply(this, arguments);
|
|
1029
1029
|
}
|
|
1030
|
+
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
1031
|
+
const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
|
|
1032
|
+
name: origin.options.name,
|
|
1033
|
+
version: origin.options.version
|
|
1034
|
+
});
|
|
1035
|
+
// get remote detail info from global
|
|
1036
|
+
const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
1037
|
+
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
|
|
1038
|
+
return {
|
|
1039
|
+
hostGlobalSnapshot,
|
|
1040
|
+
globalSnapshot: share.getGlobalSnapshot(),
|
|
1041
|
+
remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
|
|
1042
|
+
name: moduleInfo.name,
|
|
1043
|
+
version: globalRemoteInfo.matchedVersion
|
|
1044
|
+
})
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
return {
|
|
1048
|
+
hostGlobalSnapshot: undefined,
|
|
1049
|
+
globalSnapshot: share.getGlobalSnapshot(),
|
|
1050
|
+
remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
|
|
1051
|
+
name: moduleInfo.name,
|
|
1052
|
+
version: 'version' in moduleInfo ? moduleInfo.version : undefined
|
|
1053
|
+
})
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1030
1056
|
class SnapshotHandler {
|
|
1031
1057
|
async loadSnapshot(moduleInfo) {
|
|
1032
1058
|
const { options } = this.HostInstance;
|
|
@@ -1086,12 +1112,13 @@ class SnapshotHandler {
|
|
|
1086
1112
|
// global snapshot includes manifest or module info includes manifest
|
|
1087
1113
|
if (globalRemoteSnapshot) {
|
|
1088
1114
|
if (sdk.isManifestProvider(globalRemoteSnapshot)) {
|
|
1089
|
-
const
|
|
1115
|
+
const remoteEntry = share.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
|
|
1116
|
+
const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
|
|
1090
1117
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1091
1118
|
const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
|
|
1092
1119
|
// The global remote may be overridden
|
|
1093
1120
|
// Therefore, set the snapshot key to the global address of the actual request
|
|
1094
|
-
entry:
|
|
1121
|
+
entry: remoteEntry
|
|
1095
1122
|
}), moduleSnapshot);
|
|
1096
1123
|
return {
|
|
1097
1124
|
remoteSnapshot: moduleSnapshot,
|
|
@@ -1136,30 +1163,7 @@ class SnapshotHandler {
|
|
|
1136
1163
|
}
|
|
1137
1164
|
}
|
|
1138
1165
|
getGlobalRemoteInfo(moduleInfo) {
|
|
1139
|
-
|
|
1140
|
-
name: this.HostInstance.options.name,
|
|
1141
|
-
version: this.HostInstance.options.version
|
|
1142
|
-
});
|
|
1143
|
-
// get remote detail info from global
|
|
1144
|
-
const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
1145
|
-
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
|
|
1146
|
-
return {
|
|
1147
|
-
hostGlobalSnapshot,
|
|
1148
|
-
globalSnapshot: share.getGlobalSnapshot(),
|
|
1149
|
-
remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
|
|
1150
|
-
name: moduleInfo.name,
|
|
1151
|
-
version: globalRemoteInfo.matchedVersion
|
|
1152
|
-
})
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
return {
|
|
1156
|
-
hostGlobalSnapshot: undefined,
|
|
1157
|
-
globalSnapshot: share.getGlobalSnapshot(),
|
|
1158
|
-
remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
|
|
1159
|
-
name: moduleInfo.name,
|
|
1160
|
-
version: 'version' in moduleInfo ? moduleInfo.version : undefined
|
|
1161
|
-
})
|
|
1162
|
-
};
|
|
1166
|
+
return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
|
|
1163
1167
|
}
|
|
1164
1168
|
async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
|
|
1165
1169
|
const getManifest = async ()=>{
|
|
@@ -1595,6 +1599,29 @@ class RemoteHandler {
|
|
|
1595
1599
|
return res;
|
|
1596
1600
|
}, globalOptions.remotes);
|
|
1597
1601
|
}
|
|
1602
|
+
setIdToRemoteMap(id, remoteMatchInfo) {
|
|
1603
|
+
const { remote, expose } = remoteMatchInfo;
|
|
1604
|
+
const { name, alias } = remote;
|
|
1605
|
+
this.idToRemoteMap[id] = {
|
|
1606
|
+
name: remote.name,
|
|
1607
|
+
expose
|
|
1608
|
+
};
|
|
1609
|
+
if (alias && id.startsWith(name)) {
|
|
1610
|
+
const idWithAlias = id.replace(name, alias);
|
|
1611
|
+
this.idToRemoteMap[idWithAlias] = {
|
|
1612
|
+
name: remote.name,
|
|
1613
|
+
expose
|
|
1614
|
+
};
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
if (alias && id.startsWith(alias)) {
|
|
1618
|
+
const idWithName = id.replace(alias, name);
|
|
1619
|
+
this.idToRemoteMap[idWithName] = {
|
|
1620
|
+
name: remote.name,
|
|
1621
|
+
expose
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1598
1625
|
// eslint-disable-next-line max-lines-per-function
|
|
1599
1626
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1600
1627
|
async loadRemote(id, options) {
|
|
@@ -1626,6 +1653,7 @@ class RemoteHandler {
|
|
|
1626
1653
|
moduleInstance: module,
|
|
1627
1654
|
origin: host
|
|
1628
1655
|
});
|
|
1656
|
+
this.setIdToRemoteMap(id, remoteMatchInfo);
|
|
1629
1657
|
if (typeof moduleWrapper === 'function') {
|
|
1630
1658
|
return moduleWrapper;
|
|
1631
1659
|
}
|
|
@@ -1766,6 +1794,10 @@ class RemoteHandler {
|
|
|
1766
1794
|
remote.type = share.DEFAULT_REMOTE_TYPE;
|
|
1767
1795
|
}
|
|
1768
1796
|
};
|
|
1797
|
+
this.hooks.lifecycle.beforeRegisterRemote.emit({
|
|
1798
|
+
remote,
|
|
1799
|
+
origin: host
|
|
1800
|
+
});
|
|
1769
1801
|
const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
|
|
1770
1802
|
if (!registeredRemote) {
|
|
1771
1803
|
normalizeRemote();
|
|
@@ -1793,49 +1825,67 @@ class RemoteHandler {
|
|
|
1793
1825
|
}
|
|
1794
1826
|
}
|
|
1795
1827
|
removeRemote(remote) {
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
const loadedModule = host.moduleCache.get(remote.name);
|
|
1803
|
-
if (loadedModule) {
|
|
1804
|
-
var _Object_getOwnPropertyDescriptor;
|
|
1805
|
-
const remoteInfo = loadedModule.remoteInfo;
|
|
1806
|
-
const key = remoteInfo.entryGlobalName;
|
|
1807
|
-
if (globalThis[key] && ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable)) {
|
|
1808
|
-
delete globalThis[key];
|
|
1809
|
-
}
|
|
1810
|
-
const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
1811
|
-
if (share.globalLoading[remoteEntryUniqueKey]) {
|
|
1812
|
-
delete share.globalLoading[remoteEntryUniqueKey];
|
|
1828
|
+
try {
|
|
1829
|
+
const { host } = this;
|
|
1830
|
+
const { name } = remote;
|
|
1831
|
+
const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
|
|
1832
|
+
if (remoteIndex !== -1) {
|
|
1833
|
+
host.options.remotes.splice(remoteIndex, 1);
|
|
1813
1834
|
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1835
|
+
const loadedModule = host.moduleCache.get(remote.name);
|
|
1836
|
+
if (loadedModule) {
|
|
1837
|
+
const remoteInfo = loadedModule.remoteInfo;
|
|
1838
|
+
const key = remoteInfo.entryGlobalName;
|
|
1839
|
+
if (globalThis[key]) {
|
|
1840
|
+
var _Object_getOwnPropertyDescriptor;
|
|
1841
|
+
if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
|
|
1842
|
+
delete globalThis[key];
|
|
1843
|
+
} else {
|
|
1844
|
+
// @ts-ignore
|
|
1845
|
+
globalThis[key] = undefined;
|
|
1846
|
+
}
|
|
1821
1847
|
}
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1848
|
+
const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
1849
|
+
if (share.globalLoading[remoteEntryUniqueKey]) {
|
|
1850
|
+
delete share.globalLoading[remoteEntryUniqueKey];
|
|
1851
|
+
}
|
|
1852
|
+
host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
|
|
1853
|
+
// delete unloaded shared and instance
|
|
1854
|
+
let remoteInsId = remoteInfo.buildVersion ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
|
|
1855
|
+
const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
|
|
1856
|
+
if (remoteInfo.buildVersion) {
|
|
1857
|
+
return ins.options.id === remoteInsId;
|
|
1858
|
+
} else {
|
|
1859
|
+
return ins.name === remoteInsId;
|
|
1860
|
+
}
|
|
1861
|
+
});
|
|
1862
|
+
if (remoteInsIndex !== -1) {
|
|
1863
|
+
const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
|
|
1864
|
+
remoteInsId = remoteIns.options.id || remoteInsId;
|
|
1865
|
+
const globalShareScopeMap = share.getGlobalShareScope();
|
|
1866
|
+
let isAllSharedNotUsed = true;
|
|
1867
|
+
const needDeleteKeys = [];
|
|
1868
|
+
Object.keys(globalShareScopeMap).forEach((instId)=>{
|
|
1869
|
+
const shareScopeMap = globalShareScopeMap[instId];
|
|
1870
|
+
shareScopeMap && Object.keys(shareScopeMap).forEach((shareScope)=>{
|
|
1871
|
+
const shareScopeVal = shareScopeMap[shareScope];
|
|
1872
|
+
shareScopeVal && Object.keys(shareScopeVal).forEach((shareName)=>{
|
|
1873
|
+
const sharedPkgs = shareScopeVal[shareName];
|
|
1874
|
+
sharedPkgs && Object.keys(sharedPkgs).forEach((shareVersion)=>{
|
|
1875
|
+
const shared = sharedPkgs[shareVersion];
|
|
1876
|
+
if (shared && typeof shared === 'object' && shared.from === remoteInfo.name) {
|
|
1877
|
+
if (shared.loaded || shared.loading) {
|
|
1878
|
+
shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
|
|
1879
|
+
if (shared.useIn.length) {
|
|
1880
|
+
isAllSharedNotUsed = false;
|
|
1881
|
+
} else {
|
|
1882
|
+
needDeleteKeys.push([
|
|
1883
|
+
instId,
|
|
1884
|
+
shareScope,
|
|
1885
|
+
shareName,
|
|
1886
|
+
shareVersion
|
|
1887
|
+
]);
|
|
1888
|
+
}
|
|
1839
1889
|
} else {
|
|
1840
1890
|
needDeleteKeys.push([
|
|
1841
1891
|
instId,
|
|
@@ -1844,34 +1894,40 @@ class RemoteHandler {
|
|
|
1844
1894
|
shareVersion
|
|
1845
1895
|
]);
|
|
1846
1896
|
}
|
|
1847
|
-
} else {
|
|
1848
|
-
needDeleteKeys.push([
|
|
1849
|
-
instId,
|
|
1850
|
-
shareScope,
|
|
1851
|
-
shareName,
|
|
1852
|
-
shareVersion
|
|
1853
|
-
]);
|
|
1854
1897
|
}
|
|
1855
|
-
}
|
|
1898
|
+
});
|
|
1856
1899
|
});
|
|
1857
1900
|
});
|
|
1858
1901
|
});
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1902
|
+
if (isAllSharedNotUsed) {
|
|
1903
|
+
remoteIns.shareScopeMap = {};
|
|
1904
|
+
delete globalShareScopeMap[remoteInsId];
|
|
1905
|
+
}
|
|
1906
|
+
needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
|
|
1907
|
+
var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
|
|
1908
|
+
(_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];
|
|
1909
|
+
});
|
|
1910
|
+
globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
|
|
1863
1911
|
}
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1912
|
+
const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
|
|
1913
|
+
if (hostGlobalSnapshot) {
|
|
1914
|
+
const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
1915
|
+
if (remoteKey) {
|
|
1916
|
+
delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
1917
|
+
if (Boolean(share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
1918
|
+
delete share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
host.moduleCache.delete(remote.name);
|
|
1869
1923
|
}
|
|
1870
|
-
|
|
1924
|
+
} catch (err) {
|
|
1925
|
+
console.log('removeRemote fail: ', err);
|
|
1871
1926
|
}
|
|
1872
1927
|
}
|
|
1873
1928
|
constructor(host){
|
|
1874
1929
|
this.hooks = new PluginSystem({
|
|
1930
|
+
beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
|
|
1875
1931
|
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
1876
1932
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1877
1933
|
onLoad: new AsyncHook('onLoad'),
|
|
@@ -1883,6 +1939,7 @@ class RemoteHandler {
|
|
|
1883
1939
|
afterPreloadRemote: new AsyncHook()
|
|
1884
1940
|
});
|
|
1885
1941
|
this.host = host;
|
|
1942
|
+
this.idToRemoteMap = {};
|
|
1886
1943
|
}
|
|
1887
1944
|
}
|
|
1888
1945
|
|
|
@@ -2005,7 +2062,7 @@ class FederationHost {
|
|
|
2005
2062
|
// maybe will change, temporarily for internal use only
|
|
2006
2063
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2007
2064
|
});
|
|
2008
|
-
this.version = "0.
|
|
2065
|
+
this.version = "0.3.1";
|
|
2009
2066
|
this.moduleCache = new Map();
|
|
2010
2067
|
this.loaderHook = new PluginSystem({
|
|
2011
2068
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -2094,6 +2151,9 @@ function registerPlugins(...args) {
|
|
|
2094
2151
|
// eslint-disable-next-line prefer-spread
|
|
2095
2152
|
return FederationInstance.registerPlugins.apply(FederationInstance, args);
|
|
2096
2153
|
}
|
|
2154
|
+
function getInstance() {
|
|
2155
|
+
return FederationInstance;
|
|
2156
|
+
}
|
|
2097
2157
|
// Inject for debug
|
|
2098
2158
|
share.setGlobalFederationConstructor(FederationHost);
|
|
2099
2159
|
|
|
@@ -2107,6 +2167,7 @@ Object.defineProperty(exports, 'loadScriptNode', {
|
|
|
2107
2167
|
get: function () { return sdk.loadScriptNode; }
|
|
2108
2168
|
});
|
|
2109
2169
|
exports.FederationHost = FederationHost;
|
|
2170
|
+
exports.getInstance = getInstance;
|
|
2110
2171
|
exports.getRemoteEntry = getRemoteEntry;
|
|
2111
2172
|
exports.getRemoteInfo = getRemoteInfo;
|
|
2112
2173
|
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
|
|
2
|
-
export {
|
|
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';
|
|
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
|
|
|
@@ -744,16 +744,16 @@ function _extends$4() {
|
|
|
744
744
|
return _extends$4.apply(this, arguments);
|
|
745
745
|
}
|
|
746
746
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
747
|
-
|
|
748
|
-
|
|
747
|
+
const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
|
|
748
|
+
if (!remoteEntryInfo.url) {
|
|
749
|
+
error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
|
|
749
750
|
}
|
|
750
|
-
|
|
751
|
-
let entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);
|
|
751
|
+
let entryUrl = getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
|
|
752
752
|
if (!isBrowserEnv() && !entryUrl.startsWith('http')) {
|
|
753
753
|
entryUrl = `https:${entryUrl}`;
|
|
754
754
|
}
|
|
755
|
-
remoteInfo.type =
|
|
756
|
-
remoteInfo.entryGlobalName =
|
|
755
|
+
remoteInfo.type = remoteEntryInfo.type;
|
|
756
|
+
remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
|
|
757
757
|
remoteInfo.entry = entryUrl;
|
|
758
758
|
remoteInfo.version = remoteSnapshot.version;
|
|
759
759
|
remoteInfo.buildVersion = remoteSnapshot.buildVersion;
|
|
@@ -878,7 +878,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
878
878
|
return;
|
|
879
879
|
}
|
|
880
880
|
}
|
|
881
|
-
const remoteEntryUrl = getResourceUrl(moduleInfoSnapshot,
|
|
881
|
+
const remoteEntryUrl = getResourceUrl(moduleInfoSnapshot, getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
|
|
882
882
|
if (remoteEntryUrl) {
|
|
883
883
|
entryAssets.push({
|
|
884
884
|
name: remoteInfo.name,
|
|
@@ -1025,6 +1025,32 @@ function _extends$3() {
|
|
|
1025
1025
|
};
|
|
1026
1026
|
return _extends$3.apply(this, arguments);
|
|
1027
1027
|
}
|
|
1028
|
+
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
1029
|
+
const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
1030
|
+
name: origin.options.name,
|
|
1031
|
+
version: origin.options.version
|
|
1032
|
+
});
|
|
1033
|
+
// get remote detail info from global
|
|
1034
|
+
const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
1035
|
+
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
|
|
1036
|
+
return {
|
|
1037
|
+
hostGlobalSnapshot,
|
|
1038
|
+
globalSnapshot: getGlobalSnapshot(),
|
|
1039
|
+
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
1040
|
+
name: moduleInfo.name,
|
|
1041
|
+
version: globalRemoteInfo.matchedVersion
|
|
1042
|
+
})
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
return {
|
|
1046
|
+
hostGlobalSnapshot: undefined,
|
|
1047
|
+
globalSnapshot: getGlobalSnapshot(),
|
|
1048
|
+
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
1049
|
+
name: moduleInfo.name,
|
|
1050
|
+
version: 'version' in moduleInfo ? moduleInfo.version : undefined
|
|
1051
|
+
})
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1028
1054
|
class SnapshotHandler {
|
|
1029
1055
|
async loadSnapshot(moduleInfo) {
|
|
1030
1056
|
const { options } = this.HostInstance;
|
|
@@ -1084,12 +1110,13 @@ class SnapshotHandler {
|
|
|
1084
1110
|
// global snapshot includes manifest or module info includes manifest
|
|
1085
1111
|
if (globalRemoteSnapshot) {
|
|
1086
1112
|
if (isManifestProvider(globalRemoteSnapshot)) {
|
|
1087
|
-
const
|
|
1113
|
+
const remoteEntry = isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
|
|
1114
|
+
const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
|
|
1088
1115
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1089
1116
|
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
|
|
1090
1117
|
// The global remote may be overridden
|
|
1091
1118
|
// Therefore, set the snapshot key to the global address of the actual request
|
|
1092
|
-
entry:
|
|
1119
|
+
entry: remoteEntry
|
|
1093
1120
|
}), moduleSnapshot);
|
|
1094
1121
|
return {
|
|
1095
1122
|
remoteSnapshot: moduleSnapshot,
|
|
@@ -1134,30 +1161,7 @@ class SnapshotHandler {
|
|
|
1134
1161
|
}
|
|
1135
1162
|
}
|
|
1136
1163
|
getGlobalRemoteInfo(moduleInfo) {
|
|
1137
|
-
|
|
1138
|
-
name: this.HostInstance.options.name,
|
|
1139
|
-
version: this.HostInstance.options.version
|
|
1140
|
-
});
|
|
1141
|
-
// get remote detail info from global
|
|
1142
|
-
const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
1143
|
-
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
|
|
1144
|
-
return {
|
|
1145
|
-
hostGlobalSnapshot,
|
|
1146
|
-
globalSnapshot: getGlobalSnapshot(),
|
|
1147
|
-
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
1148
|
-
name: moduleInfo.name,
|
|
1149
|
-
version: globalRemoteInfo.matchedVersion
|
|
1150
|
-
})
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
return {
|
|
1154
|
-
hostGlobalSnapshot: undefined,
|
|
1155
|
-
globalSnapshot: getGlobalSnapshot(),
|
|
1156
|
-
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
1157
|
-
name: moduleInfo.name,
|
|
1158
|
-
version: 'version' in moduleInfo ? moduleInfo.version : undefined
|
|
1159
|
-
})
|
|
1160
|
-
};
|
|
1164
|
+
return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
|
|
1161
1165
|
}
|
|
1162
1166
|
async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
|
|
1163
1167
|
const getManifest = async ()=>{
|
|
@@ -1593,6 +1597,29 @@ class RemoteHandler {
|
|
|
1593
1597
|
return res;
|
|
1594
1598
|
}, globalOptions.remotes);
|
|
1595
1599
|
}
|
|
1600
|
+
setIdToRemoteMap(id, remoteMatchInfo) {
|
|
1601
|
+
const { remote, expose } = remoteMatchInfo;
|
|
1602
|
+
const { name, alias } = remote;
|
|
1603
|
+
this.idToRemoteMap[id] = {
|
|
1604
|
+
name: remote.name,
|
|
1605
|
+
expose
|
|
1606
|
+
};
|
|
1607
|
+
if (alias && id.startsWith(name)) {
|
|
1608
|
+
const idWithAlias = id.replace(name, alias);
|
|
1609
|
+
this.idToRemoteMap[idWithAlias] = {
|
|
1610
|
+
name: remote.name,
|
|
1611
|
+
expose
|
|
1612
|
+
};
|
|
1613
|
+
return;
|
|
1614
|
+
}
|
|
1615
|
+
if (alias && id.startsWith(alias)) {
|
|
1616
|
+
const idWithName = id.replace(alias, name);
|
|
1617
|
+
this.idToRemoteMap[idWithName] = {
|
|
1618
|
+
name: remote.name,
|
|
1619
|
+
expose
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1596
1623
|
// eslint-disable-next-line max-lines-per-function
|
|
1597
1624
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1598
1625
|
async loadRemote(id, options) {
|
|
@@ -1624,6 +1651,7 @@ class RemoteHandler {
|
|
|
1624
1651
|
moduleInstance: module,
|
|
1625
1652
|
origin: host
|
|
1626
1653
|
});
|
|
1654
|
+
this.setIdToRemoteMap(id, remoteMatchInfo);
|
|
1627
1655
|
if (typeof moduleWrapper === 'function') {
|
|
1628
1656
|
return moduleWrapper;
|
|
1629
1657
|
}
|
|
@@ -1764,6 +1792,10 @@ class RemoteHandler {
|
|
|
1764
1792
|
remote.type = DEFAULT_REMOTE_TYPE;
|
|
1765
1793
|
}
|
|
1766
1794
|
};
|
|
1795
|
+
this.hooks.lifecycle.beforeRegisterRemote.emit({
|
|
1796
|
+
remote,
|
|
1797
|
+
origin: host
|
|
1798
|
+
});
|
|
1767
1799
|
const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
|
|
1768
1800
|
if (!registeredRemote) {
|
|
1769
1801
|
normalizeRemote();
|
|
@@ -1791,49 +1823,67 @@ class RemoteHandler {
|
|
|
1791
1823
|
}
|
|
1792
1824
|
}
|
|
1793
1825
|
removeRemote(remote) {
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
const loadedModule = host.moduleCache.get(remote.name);
|
|
1801
|
-
if (loadedModule) {
|
|
1802
|
-
var _Object_getOwnPropertyDescriptor;
|
|
1803
|
-
const remoteInfo = loadedModule.remoteInfo;
|
|
1804
|
-
const key = remoteInfo.entryGlobalName;
|
|
1805
|
-
if (globalThis[key] && ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable)) {
|
|
1806
|
-
delete globalThis[key];
|
|
1807
|
-
}
|
|
1808
|
-
const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
1809
|
-
if (globalLoading[remoteEntryUniqueKey]) {
|
|
1810
|
-
delete globalLoading[remoteEntryUniqueKey];
|
|
1826
|
+
try {
|
|
1827
|
+
const { host } = this;
|
|
1828
|
+
const { name } = remote;
|
|
1829
|
+
const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
|
|
1830
|
+
if (remoteIndex !== -1) {
|
|
1831
|
+
host.options.remotes.splice(remoteIndex, 1);
|
|
1811
1832
|
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1833
|
+
const loadedModule = host.moduleCache.get(remote.name);
|
|
1834
|
+
if (loadedModule) {
|
|
1835
|
+
const remoteInfo = loadedModule.remoteInfo;
|
|
1836
|
+
const key = remoteInfo.entryGlobalName;
|
|
1837
|
+
if (globalThis[key]) {
|
|
1838
|
+
var _Object_getOwnPropertyDescriptor;
|
|
1839
|
+
if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
|
|
1840
|
+
delete globalThis[key];
|
|
1841
|
+
} else {
|
|
1842
|
+
// @ts-ignore
|
|
1843
|
+
globalThis[key] = undefined;
|
|
1844
|
+
}
|
|
1819
1845
|
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1846
|
+
const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
1847
|
+
if (globalLoading[remoteEntryUniqueKey]) {
|
|
1848
|
+
delete globalLoading[remoteEntryUniqueKey];
|
|
1849
|
+
}
|
|
1850
|
+
host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
|
|
1851
|
+
// delete unloaded shared and instance
|
|
1852
|
+
let remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
|
|
1853
|
+
const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
|
|
1854
|
+
if (remoteInfo.buildVersion) {
|
|
1855
|
+
return ins.options.id === remoteInsId;
|
|
1856
|
+
} else {
|
|
1857
|
+
return ins.name === remoteInsId;
|
|
1858
|
+
}
|
|
1859
|
+
});
|
|
1860
|
+
if (remoteInsIndex !== -1) {
|
|
1861
|
+
const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
|
|
1862
|
+
remoteInsId = remoteIns.options.id || remoteInsId;
|
|
1863
|
+
const globalShareScopeMap = getGlobalShareScope();
|
|
1864
|
+
let isAllSharedNotUsed = true;
|
|
1865
|
+
const needDeleteKeys = [];
|
|
1866
|
+
Object.keys(globalShareScopeMap).forEach((instId)=>{
|
|
1867
|
+
const shareScopeMap = globalShareScopeMap[instId];
|
|
1868
|
+
shareScopeMap && Object.keys(shareScopeMap).forEach((shareScope)=>{
|
|
1869
|
+
const shareScopeVal = shareScopeMap[shareScope];
|
|
1870
|
+
shareScopeVal && Object.keys(shareScopeVal).forEach((shareName)=>{
|
|
1871
|
+
const sharedPkgs = shareScopeVal[shareName];
|
|
1872
|
+
sharedPkgs && Object.keys(sharedPkgs).forEach((shareVersion)=>{
|
|
1873
|
+
const shared = sharedPkgs[shareVersion];
|
|
1874
|
+
if (shared && typeof shared === 'object' && shared.from === remoteInfo.name) {
|
|
1875
|
+
if (shared.loaded || shared.loading) {
|
|
1876
|
+
shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
|
|
1877
|
+
if (shared.useIn.length) {
|
|
1878
|
+
isAllSharedNotUsed = false;
|
|
1879
|
+
} else {
|
|
1880
|
+
needDeleteKeys.push([
|
|
1881
|
+
instId,
|
|
1882
|
+
shareScope,
|
|
1883
|
+
shareName,
|
|
1884
|
+
shareVersion
|
|
1885
|
+
]);
|
|
1886
|
+
}
|
|
1837
1887
|
} else {
|
|
1838
1888
|
needDeleteKeys.push([
|
|
1839
1889
|
instId,
|
|
@@ -1842,34 +1892,40 @@ class RemoteHandler {
|
|
|
1842
1892
|
shareVersion
|
|
1843
1893
|
]);
|
|
1844
1894
|
}
|
|
1845
|
-
} else {
|
|
1846
|
-
needDeleteKeys.push([
|
|
1847
|
-
instId,
|
|
1848
|
-
shareScope,
|
|
1849
|
-
shareName,
|
|
1850
|
-
shareVersion
|
|
1851
|
-
]);
|
|
1852
1895
|
}
|
|
1853
|
-
}
|
|
1896
|
+
});
|
|
1854
1897
|
});
|
|
1855
1898
|
});
|
|
1856
1899
|
});
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1900
|
+
if (isAllSharedNotUsed) {
|
|
1901
|
+
remoteIns.shareScopeMap = {};
|
|
1902
|
+
delete globalShareScopeMap[remoteInsId];
|
|
1903
|
+
}
|
|
1904
|
+
needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
|
|
1905
|
+
var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
|
|
1906
|
+
(_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];
|
|
1907
|
+
});
|
|
1908
|
+
globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
|
|
1861
1909
|
}
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1910
|
+
const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
|
|
1911
|
+
if (hostGlobalSnapshot) {
|
|
1912
|
+
const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
1913
|
+
if (remoteKey) {
|
|
1914
|
+
delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
1915
|
+
if (Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
1916
|
+
delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
host.moduleCache.delete(remote.name);
|
|
1867
1921
|
}
|
|
1868
|
-
|
|
1922
|
+
} catch (err) {
|
|
1923
|
+
console.log('removeRemote fail: ', err);
|
|
1869
1924
|
}
|
|
1870
1925
|
}
|
|
1871
1926
|
constructor(host){
|
|
1872
1927
|
this.hooks = new PluginSystem({
|
|
1928
|
+
beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
|
|
1873
1929
|
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
1874
1930
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1875
1931
|
onLoad: new AsyncHook('onLoad'),
|
|
@@ -1881,6 +1937,7 @@ class RemoteHandler {
|
|
|
1881
1937
|
afterPreloadRemote: new AsyncHook()
|
|
1882
1938
|
});
|
|
1883
1939
|
this.host = host;
|
|
1940
|
+
this.idToRemoteMap = {};
|
|
1884
1941
|
}
|
|
1885
1942
|
}
|
|
1886
1943
|
|
|
@@ -2003,7 +2060,7 @@ class FederationHost {
|
|
|
2003
2060
|
// maybe will change, temporarily for internal use only
|
|
2004
2061
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2005
2062
|
});
|
|
2006
|
-
this.version = "0.
|
|
2063
|
+
this.version = "0.3.1";
|
|
2007
2064
|
this.moduleCache = new Map();
|
|
2008
2065
|
this.loaderHook = new PluginSystem({
|
|
2009
2066
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -2092,7 +2149,10 @@ function registerPlugins(...args) {
|
|
|
2092
2149
|
// eslint-disable-next-line prefer-spread
|
|
2093
2150
|
return FederationInstance.registerPlugins.apply(FederationInstance, args);
|
|
2094
2151
|
}
|
|
2152
|
+
function getInstance() {
|
|
2153
|
+
return FederationInstance;
|
|
2154
|
+
}
|
|
2095
2155
|
// Inject for debug
|
|
2096
2156
|
setGlobalFederationConstructor(FederationHost);
|
|
2097
2157
|
|
|
2098
|
-
export { FederationHost, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerPlugins, registerRemotes };
|
|
2158
|
+
export { FederationHost, getInstance, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerPlugins, registerRemotes };
|
package/dist/package.json
CHANGED
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.
|
|
215
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.3.1";
|
|
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.
|
|
213
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.3.1";
|
|
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 {
|
|
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 };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -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;
|
|
@@ -3,6 +3,11 @@ 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
|
+
};
|
|
6
11
|
export declare class SnapshotHandler {
|
|
7
12
|
loadingHostSnapshot: Promise<GlobalModuleInfo | void> | null;
|
|
8
13
|
HostInstance: FederationHost;
|
|
@@ -39,6 +44,10 @@ export declare class SnapshotHandler {
|
|
|
39
44
|
remoteSnapshot: ModuleInfo;
|
|
40
45
|
globalSnapshot: GlobalModuleInfo;
|
|
41
46
|
}> | never;
|
|
42
|
-
|
|
47
|
+
getGlobalRemoteInfo(moduleInfo: Remote): {
|
|
48
|
+
hostGlobalSnapshot: ModuleInfo | undefined;
|
|
49
|
+
globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
|
|
50
|
+
remoteSnapshot: GlobalModuleInfo[string] | undefined;
|
|
51
|
+
};
|
|
43
52
|
private getManifestJson;
|
|
44
53
|
}
|
|
@@ -15,7 +15,15 @@ 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
|
+
}>;
|
|
18
22
|
hooks: PluginSystem<{
|
|
23
|
+
beforeRegisterRemote: SyncWaterfallHook<{
|
|
24
|
+
remote: Remote;
|
|
25
|
+
origin: FederationHost;
|
|
26
|
+
}>;
|
|
19
27
|
registerRemote: SyncWaterfallHook<{
|
|
20
28
|
remote: Remote;
|
|
21
29
|
origin: FederationHost;
|
|
@@ -73,6 +81,7 @@ export declare class RemoteHandler {
|
|
|
73
81
|
}>;
|
|
74
82
|
constructor(host: FederationHost);
|
|
75
83
|
formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions): Remote[];
|
|
84
|
+
setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch): void;
|
|
76
85
|
loadRemote<T>(id: string, options?: {
|
|
77
86
|
loadFactory?: boolean;
|
|
78
87
|
from: 'build' | 'runtime';
|
package/dist/src/utils/tool.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.3.1",
|
|
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.
|
|
48
|
+
"@module-federation/sdk": "0.3.1"
|
|
49
49
|
}
|
|
50
50
|
}
|