@module-federation/runtime-core 0.0.0-fix-ssr-publicpath-1221-20251221064742 → 0.0.0-fix-webpack-manfest-version-20260202074337
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.cjs +351 -167
- package/dist/index.cjs.cjs.map +1 -1
- package/dist/index.esm.js +351 -167
- package/dist/index.esm.js.map +1 -1
- package/dist/src/core.d.ts +6 -2
- package/dist/src/module/index.d.ts +3 -1
- package/dist/src/shared/index.d.ts +12 -3
- package/dist/src/type/config.d.ts +14 -1
- package/dist/src/utils/share.d.ts +27 -9
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -93,7 +93,7 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
|
93
93
|
type: 'global',
|
|
94
94
|
globalName: '',
|
|
95
95
|
};
|
|
96
|
-
if (isBrowserEnv() || isReactNativeEnv()) {
|
|
96
|
+
if (isBrowserEnv() || isReactNativeEnv() || !('ssrRemoteEntry' in snapshot)) {
|
|
97
97
|
return 'remoteEntry' in snapshot
|
|
98
98
|
? {
|
|
99
99
|
url: snapshot.remoteEntry,
|
|
@@ -200,7 +200,7 @@ function getGlobalFederationConstructor() {
|
|
|
200
200
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
201
201
|
if (isDebug) {
|
|
202
202
|
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
203
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-fix-
|
|
203
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-fix-webpack-manfest-version-20260202074337";
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -807,6 +807,9 @@ function formatShare(shareArgs, from, name, shareStrategy) {
|
|
|
807
807
|
throw new Error(`Can not get shared '${name}'!`);
|
|
808
808
|
});
|
|
809
809
|
}
|
|
810
|
+
if (shareArgs.shareConfig?.eager && shareArgs.treeShaking) {
|
|
811
|
+
throw new Error('Can not set "eager:true" and "treeShaking" at the same time!');
|
|
812
|
+
}
|
|
810
813
|
return {
|
|
811
814
|
deps: [],
|
|
812
815
|
useIn: [],
|
|
@@ -827,37 +830,67 @@ function formatShare(shareArgs, from, name, shareStrategy) {
|
|
|
827
830
|
? shareArgs.scope
|
|
828
831
|
: [shareArgs.scope ?? 'default'],
|
|
829
832
|
strategy: (shareArgs.strategy ?? shareStrategy) || 'version-first',
|
|
833
|
+
treeShaking: shareArgs.treeShaking
|
|
834
|
+
? {
|
|
835
|
+
...shareArgs.treeShaking,
|
|
836
|
+
mode: shareArgs.treeShaking.mode ?? 'server-calc',
|
|
837
|
+
status: shareArgs.treeShaking.status ?? 1 /* TreeShakingStatus.UNKNOWN */,
|
|
838
|
+
useIn: [],
|
|
839
|
+
}
|
|
840
|
+
: undefined,
|
|
830
841
|
};
|
|
831
842
|
}
|
|
832
|
-
function formatShareConfigs(
|
|
833
|
-
const shareArgs =
|
|
834
|
-
const from =
|
|
835
|
-
const
|
|
843
|
+
function formatShareConfigs(prevOptions, newOptions) {
|
|
844
|
+
const shareArgs = newOptions.shared || {};
|
|
845
|
+
const from = newOptions.name;
|
|
846
|
+
const newShareInfos = Object.keys(shareArgs).reduce((res, pkgName) => {
|
|
836
847
|
const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
|
|
837
848
|
res[pkgName] = res[pkgName] || [];
|
|
838
849
|
arrayShareArgs.forEach((shareConfig) => {
|
|
839
|
-
res[pkgName].push(formatShare(shareConfig, from, pkgName,
|
|
850
|
+
res[pkgName].push(formatShare(shareConfig, from, pkgName, newOptions.shareStrategy));
|
|
840
851
|
});
|
|
841
852
|
return res;
|
|
842
853
|
}, {});
|
|
843
|
-
const
|
|
844
|
-
...
|
|
854
|
+
const allShareInfos = {
|
|
855
|
+
...prevOptions.shared,
|
|
845
856
|
};
|
|
846
|
-
Object.keys(
|
|
847
|
-
if (!
|
|
848
|
-
|
|
857
|
+
Object.keys(newShareInfos).forEach((shareKey) => {
|
|
858
|
+
if (!allShareInfos[shareKey]) {
|
|
859
|
+
allShareInfos[shareKey] = newShareInfos[shareKey];
|
|
849
860
|
}
|
|
850
861
|
else {
|
|
851
|
-
|
|
852
|
-
const isSameVersion =
|
|
862
|
+
newShareInfos[shareKey].forEach((newUserSharedOptions) => {
|
|
863
|
+
const isSameVersion = allShareInfos[shareKey].find((sharedVal) => sharedVal.version === newUserSharedOptions.version);
|
|
853
864
|
if (!isSameVersion) {
|
|
854
|
-
|
|
865
|
+
allShareInfos[shareKey].push(newUserSharedOptions);
|
|
855
866
|
}
|
|
856
867
|
});
|
|
857
868
|
}
|
|
858
869
|
});
|
|
859
|
-
return {
|
|
870
|
+
return { allShareInfos, newShareInfos };
|
|
871
|
+
}
|
|
872
|
+
function shouldUseTreeShaking(treeShaking, usedExports) {
|
|
873
|
+
if (!treeShaking) {
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
const { status, mode } = treeShaking;
|
|
877
|
+
if (status === 0 /* TreeShakingStatus.NO_USE */) {
|
|
878
|
+
return false;
|
|
879
|
+
}
|
|
880
|
+
if (status === 2 /* TreeShakingStatus.CALCULATED */) {
|
|
881
|
+
return true;
|
|
882
|
+
}
|
|
883
|
+
if (mode === 'runtime-infer') {
|
|
884
|
+
if (!usedExports) {
|
|
885
|
+
return true;
|
|
886
|
+
}
|
|
887
|
+
return isMatchUsedExports(treeShaking, usedExports);
|
|
888
|
+
}
|
|
889
|
+
return false;
|
|
860
890
|
}
|
|
891
|
+
/**
|
|
892
|
+
* compare version a and b, return true if a is less than b
|
|
893
|
+
*/
|
|
861
894
|
function versionLt(a, b) {
|
|
862
895
|
const transformInvalidVersion = (version) => {
|
|
863
896
|
const isNumberVersion = !Number.isNaN(Number(version));
|
|
@@ -903,19 +936,79 @@ const isLoaded = (shared) => {
|
|
|
903
936
|
const isLoading = (shared) => {
|
|
904
937
|
return Boolean(shared.loading);
|
|
905
938
|
};
|
|
906
|
-
|
|
939
|
+
const isMatchUsedExports = (treeShaking, usedExports) => {
|
|
940
|
+
if (!treeShaking || !usedExports) {
|
|
941
|
+
return false;
|
|
942
|
+
}
|
|
943
|
+
const { usedExports: treeShakingUsedExports } = treeShaking;
|
|
944
|
+
if (!treeShakingUsedExports) {
|
|
945
|
+
return false;
|
|
946
|
+
}
|
|
947
|
+
if (usedExports.every((e) => treeShakingUsedExports.includes(e))) {
|
|
948
|
+
return true;
|
|
949
|
+
}
|
|
950
|
+
return false;
|
|
951
|
+
};
|
|
952
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName, treeShaking) {
|
|
907
953
|
const versions = shareScopeMap[scope][pkgName];
|
|
954
|
+
let version = '';
|
|
955
|
+
let useTreesShaking = shouldUseTreeShaking(treeShaking);
|
|
956
|
+
// return false means use prev version
|
|
908
957
|
const callback = function (prev, cur) {
|
|
958
|
+
if (useTreesShaking) {
|
|
959
|
+
if (!versions[prev].treeShaking) {
|
|
960
|
+
return true;
|
|
961
|
+
}
|
|
962
|
+
if (!versions[cur].treeShaking) {
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
return !isLoaded(versions[prev].treeShaking) && versionLt(prev, cur);
|
|
966
|
+
}
|
|
909
967
|
return !isLoaded(versions[prev]) && versionLt(prev, cur);
|
|
910
968
|
};
|
|
911
|
-
|
|
969
|
+
if (useTreesShaking) {
|
|
970
|
+
version = findVersion(shareScopeMap[scope][pkgName], callback);
|
|
971
|
+
if (version) {
|
|
972
|
+
return {
|
|
973
|
+
version,
|
|
974
|
+
useTreesShaking,
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
useTreesShaking = false;
|
|
978
|
+
}
|
|
979
|
+
return {
|
|
980
|
+
version: findVersion(shareScopeMap[scope][pkgName], callback),
|
|
981
|
+
useTreesShaking,
|
|
982
|
+
};
|
|
912
983
|
}
|
|
913
|
-
|
|
984
|
+
const isLoadingOrLoaded = (shared) => {
|
|
985
|
+
return isLoaded(shared) || isLoading(shared);
|
|
986
|
+
};
|
|
987
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName, treeShaking) {
|
|
914
988
|
const versions = shareScopeMap[scope][pkgName];
|
|
989
|
+
let version = '';
|
|
990
|
+
let useTreesShaking = shouldUseTreeShaking(treeShaking);
|
|
991
|
+
// return false means use prev version
|
|
915
992
|
const callback = function (prev, cur) {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
993
|
+
if (useTreesShaking) {
|
|
994
|
+
if (!versions[prev].treeShaking) {
|
|
995
|
+
return true;
|
|
996
|
+
}
|
|
997
|
+
if (!versions[cur].treeShaking) {
|
|
998
|
+
return false;
|
|
999
|
+
}
|
|
1000
|
+
if (isLoadingOrLoaded(versions[cur].treeShaking)) {
|
|
1001
|
+
if (isLoadingOrLoaded(versions[prev].treeShaking)) {
|
|
1002
|
+
return Boolean(versionLt(prev, cur));
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
return true;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (isLoadingOrLoaded(versions[prev].treeShaking)) {
|
|
1009
|
+
return false;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
919
1012
|
if (isLoadingOrLoaded(versions[cur])) {
|
|
920
1013
|
if (isLoadingOrLoaded(versions[prev])) {
|
|
921
1014
|
return Boolean(versionLt(prev, cur));
|
|
@@ -929,7 +1022,20 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
|
929
1022
|
}
|
|
930
1023
|
return versionLt(prev, cur);
|
|
931
1024
|
};
|
|
932
|
-
|
|
1025
|
+
if (useTreesShaking) {
|
|
1026
|
+
version = findVersion(shareScopeMap[scope][pkgName], callback);
|
|
1027
|
+
if (version) {
|
|
1028
|
+
return {
|
|
1029
|
+
version,
|
|
1030
|
+
useTreesShaking,
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
useTreesShaking = false;
|
|
1034
|
+
}
|
|
1035
|
+
return {
|
|
1036
|
+
version: findVersion(shareScopeMap[scope][pkgName], callback),
|
|
1037
|
+
useTreesShaking,
|
|
1038
|
+
};
|
|
933
1039
|
}
|
|
934
1040
|
function getFindShareFunction(strategy) {
|
|
935
1041
|
if (strategy === 'loaded-first') {
|
|
@@ -941,7 +1047,7 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
941
1047
|
if (!localShareScopeMap) {
|
|
942
1048
|
return;
|
|
943
1049
|
}
|
|
944
|
-
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
1050
|
+
const { shareConfig, scope = DEFAULT_SCOPE, strategy, treeShaking, } = shareInfo;
|
|
945
1051
|
const scopes = Array.isArray(scope) ? scope : [scope];
|
|
946
1052
|
for (const sc of scopes) {
|
|
947
1053
|
if (shareConfig &&
|
|
@@ -949,14 +1055,13 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
949
1055
|
localShareScopeMap[sc][pkgName]) {
|
|
950
1056
|
const { requiredVersion } = shareConfig;
|
|
951
1057
|
const findShareFunction = getFindShareFunction(strategy);
|
|
952
|
-
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
953
|
-
//@ts-ignore
|
|
1058
|
+
const { version: maxOrSingletonVersion, useTreesShaking } = findShareFunction(localShareScopeMap, sc, pkgName, treeShaking);
|
|
954
1059
|
const defaultResolver = () => {
|
|
1060
|
+
const shared = localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
955
1061
|
if (shareConfig.singleton) {
|
|
956
1062
|
if (typeof requiredVersion === 'string' &&
|
|
957
1063
|
!satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
958
|
-
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion &&
|
|
959
|
-
localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
|
|
1064
|
+
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && shared.from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
|
|
960
1065
|
if (shareConfig.strictVersion) {
|
|
961
1066
|
error(msg);
|
|
962
1067
|
}
|
|
@@ -964,21 +1069,48 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
964
1069
|
warn(msg);
|
|
965
1070
|
}
|
|
966
1071
|
}
|
|
967
|
-
return
|
|
1072
|
+
return {
|
|
1073
|
+
shared,
|
|
1074
|
+
useTreesShaking,
|
|
1075
|
+
};
|
|
968
1076
|
}
|
|
969
1077
|
else {
|
|
970
1078
|
if (requiredVersion === false || requiredVersion === '*') {
|
|
971
|
-
return
|
|
1079
|
+
return {
|
|
1080
|
+
shared,
|
|
1081
|
+
useTreesShaking,
|
|
1082
|
+
};
|
|
972
1083
|
}
|
|
973
1084
|
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
974
|
-
return
|
|
1085
|
+
return {
|
|
1086
|
+
shared,
|
|
1087
|
+
useTreesShaking,
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
const _usedTreeShaking = shouldUseTreeShaking(treeShaking);
|
|
1091
|
+
if (_usedTreeShaking) {
|
|
1092
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])) {
|
|
1093
|
+
if (!shouldUseTreeShaking(versionValue.treeShaking, treeShaking?.usedExports)) {
|
|
1094
|
+
continue;
|
|
1095
|
+
}
|
|
1096
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
1097
|
+
return {
|
|
1098
|
+
shared: versionValue,
|
|
1099
|
+
useTreesShaking: _usedTreeShaking,
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
975
1103
|
}
|
|
976
1104
|
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])) {
|
|
977
1105
|
if (satisfy(versionKey, requiredVersion)) {
|
|
978
|
-
return
|
|
1106
|
+
return {
|
|
1107
|
+
shared: versionValue,
|
|
1108
|
+
useTreesShaking: false,
|
|
1109
|
+
};
|
|
979
1110
|
}
|
|
980
1111
|
}
|
|
981
1112
|
}
|
|
1113
|
+
return;
|
|
982
1114
|
};
|
|
983
1115
|
const params = {
|
|
984
1116
|
shareScopeMap: localShareScopeMap,
|
|
@@ -986,6 +1118,7 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
986
1118
|
pkgName,
|
|
987
1119
|
version: maxOrSingletonVersion,
|
|
988
1120
|
GlobalFederation: Global.__FEDERATION__,
|
|
1121
|
+
shareInfo,
|
|
989
1122
|
resolver: defaultResolver,
|
|
990
1123
|
};
|
|
991
1124
|
const resolveShared = resolveShare.emit(params) || params;
|
|
@@ -1007,13 +1140,47 @@ function getTargetSharedOptions(options) {
|
|
|
1007
1140
|
shareVersionMap[shared.version] = shared;
|
|
1008
1141
|
});
|
|
1009
1142
|
const callback = function (prev, cur) {
|
|
1010
|
-
return
|
|
1143
|
+
return (
|
|
1144
|
+
// TODO: consider multiple treeShaking shared scenes
|
|
1145
|
+
!isLoaded(shareVersionMap[prev]) && versionLt(prev, cur));
|
|
1011
1146
|
};
|
|
1012
1147
|
const maxVersion = findVersion(shareVersionMap, callback);
|
|
1013
1148
|
return shareVersionMap[maxVersion];
|
|
1014
1149
|
};
|
|
1015
1150
|
const resolver = extraOptions?.resolver ?? defaultResolver;
|
|
1016
|
-
|
|
1151
|
+
const isPlainObject = (val) => {
|
|
1152
|
+
return val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
1153
|
+
};
|
|
1154
|
+
const merge = (...sources) => {
|
|
1155
|
+
const out = {};
|
|
1156
|
+
for (const src of sources) {
|
|
1157
|
+
if (!src)
|
|
1158
|
+
continue;
|
|
1159
|
+
for (const [key, value] of Object.entries(src)) {
|
|
1160
|
+
const prev = out[key];
|
|
1161
|
+
if (isPlainObject(prev) && isPlainObject(value)) {
|
|
1162
|
+
out[key] = merge(prev, value);
|
|
1163
|
+
}
|
|
1164
|
+
else if (value !== undefined) {
|
|
1165
|
+
out[key] = value;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return out;
|
|
1170
|
+
};
|
|
1171
|
+
return merge(resolver(shareInfos[pkgName]), extraOptions?.customShareInfo);
|
|
1172
|
+
}
|
|
1173
|
+
const addUseIn = (shared, from) => {
|
|
1174
|
+
if (!shared.useIn) {
|
|
1175
|
+
shared.useIn = [];
|
|
1176
|
+
}
|
|
1177
|
+
addUniqueItem(shared.useIn, from);
|
|
1178
|
+
};
|
|
1179
|
+
function directShare(shared, useTreesShaking) {
|
|
1180
|
+
if (useTreesShaking && shared.treeShaking) {
|
|
1181
|
+
return shared.treeShaking;
|
|
1182
|
+
}
|
|
1183
|
+
return shared;
|
|
1017
1184
|
}
|
|
1018
1185
|
|
|
1019
1186
|
function getBuilderId() {
|
|
@@ -1525,6 +1692,40 @@ var helpers = {
|
|
|
1525
1692
|
},
|
|
1526
1693
|
};
|
|
1527
1694
|
|
|
1695
|
+
function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap) {
|
|
1696
|
+
const localShareScopeMap = hostShareScopeMap;
|
|
1697
|
+
const shareScopeKeys = Array.isArray(remoteInfo.shareScope)
|
|
1698
|
+
? remoteInfo.shareScope
|
|
1699
|
+
: [remoteInfo.shareScope];
|
|
1700
|
+
if (!shareScopeKeys.length) {
|
|
1701
|
+
shareScopeKeys.push('default');
|
|
1702
|
+
}
|
|
1703
|
+
shareScopeKeys.forEach((shareScopeKey) => {
|
|
1704
|
+
if (!localShareScopeMap[shareScopeKey]) {
|
|
1705
|
+
localShareScopeMap[shareScopeKey] = {};
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
const remoteEntryInitOptions = {
|
|
1709
|
+
version: remoteInfo.version || '',
|
|
1710
|
+
shareScopeKeys: Array.isArray(remoteInfo.shareScope)
|
|
1711
|
+
? shareScopeKeys
|
|
1712
|
+
: remoteInfo.shareScope || 'default',
|
|
1713
|
+
};
|
|
1714
|
+
// Help to find host instance
|
|
1715
|
+
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
1716
|
+
value: localShareScopeMap,
|
|
1717
|
+
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
1718
|
+
enumerable: false,
|
|
1719
|
+
});
|
|
1720
|
+
// TODO: compate legacy init params, should use shareScopeMap if exist
|
|
1721
|
+
const shareScope = localShareScopeMap[shareScopeKeys[0]];
|
|
1722
|
+
const initScope = [];
|
|
1723
|
+
return {
|
|
1724
|
+
remoteEntryInitOptions,
|
|
1725
|
+
shareScope,
|
|
1726
|
+
initScope,
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1528
1729
|
class Module {
|
|
1529
1730
|
constructor({ remoteInfo, host, }) {
|
|
1530
1731
|
this.inited = false;
|
|
@@ -1536,8 +1737,7 @@ class Module {
|
|
|
1536
1737
|
if (this.remoteEntryExports) {
|
|
1537
1738
|
return this.remoteEntryExports;
|
|
1538
1739
|
}
|
|
1539
|
-
|
|
1540
|
-
remoteEntryExports = await getRemoteEntry({
|
|
1740
|
+
const remoteEntryExports = await getRemoteEntry({
|
|
1541
1741
|
origin: this.host,
|
|
1542
1742
|
remoteInfo: this.remoteInfo,
|
|
1543
1743
|
remoteEntryExports: this.remoteEntryExports,
|
|
@@ -1547,38 +1747,11 @@ class Module {
|
|
|
1547
1747
|
return this.remoteEntryExports;
|
|
1548
1748
|
}
|
|
1549
1749
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1550
|
-
async
|
|
1551
|
-
const { loadFactory = true } = options || { loadFactory: true };
|
|
1750
|
+
async init(id, remoteSnapshot) {
|
|
1552
1751
|
// Get remoteEntry.js
|
|
1553
1752
|
const remoteEntryExports = await this.getEntry();
|
|
1554
1753
|
if (!this.inited) {
|
|
1555
|
-
const
|
|
1556
|
-
const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope)
|
|
1557
|
-
? this.remoteInfo.shareScope
|
|
1558
|
-
: [this.remoteInfo.shareScope];
|
|
1559
|
-
if (!shareScopeKeys.length) {
|
|
1560
|
-
shareScopeKeys.push('default');
|
|
1561
|
-
}
|
|
1562
|
-
shareScopeKeys.forEach((shareScopeKey) => {
|
|
1563
|
-
if (!localShareScopeMap[shareScopeKey]) {
|
|
1564
|
-
localShareScopeMap[shareScopeKey] = {};
|
|
1565
|
-
}
|
|
1566
|
-
});
|
|
1567
|
-
// TODO: compate legacy init params, should use shareScopeMap if exist
|
|
1568
|
-
const shareScope = localShareScopeMap[shareScopeKeys[0]];
|
|
1569
|
-
const initScope = [];
|
|
1570
|
-
const remoteEntryInitOptions = {
|
|
1571
|
-
version: this.remoteInfo.version || '',
|
|
1572
|
-
shareScopeKeys: Array.isArray(this.remoteInfo.shareScope)
|
|
1573
|
-
? shareScopeKeys
|
|
1574
|
-
: this.remoteInfo.shareScope || 'default',
|
|
1575
|
-
};
|
|
1576
|
-
// Help to find host instance
|
|
1577
|
-
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
1578
|
-
value: localShareScopeMap,
|
|
1579
|
-
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
1580
|
-
enumerable: false,
|
|
1581
|
-
});
|
|
1754
|
+
const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap);
|
|
1582
1755
|
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
1583
1756
|
shareScope,
|
|
1584
1757
|
// @ts-ignore shareScopeMap will be set by Object.defineProperty
|
|
@@ -1602,9 +1775,15 @@ class Module {
|
|
|
1602
1775
|
remoteSnapshot,
|
|
1603
1776
|
remoteEntryExports,
|
|
1604
1777
|
});
|
|
1778
|
+
this.inited = true;
|
|
1605
1779
|
}
|
|
1780
|
+
return remoteEntryExports;
|
|
1781
|
+
}
|
|
1782
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1783
|
+
async get(id, expose, options, remoteSnapshot) {
|
|
1784
|
+
const { loadFactory = true } = options || { loadFactory: true };
|
|
1785
|
+
const remoteEntryExports = await this.init(id, remoteSnapshot);
|
|
1606
1786
|
this.lib = remoteEntryExports;
|
|
1607
|
-
this.inited = true;
|
|
1608
1787
|
let moduleFactory;
|
|
1609
1788
|
moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
|
|
1610
1789
|
remoteEntryExports,
|
|
@@ -2058,7 +2237,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
2058
2237
|
}, true, memo, remoteSnapshot);
|
|
2059
2238
|
if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
|
|
2060
2239
|
const collectSharedAssets = (shareInfo, snapshotShared) => {
|
|
2061
|
-
const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
|
|
2240
|
+
const { shared: registeredShared } = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare) || {};
|
|
2062
2241
|
// If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
|
|
2063
2242
|
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
2064
2243
|
snapshotShared.assets.js.sync.forEach((asset) => {
|
|
@@ -2349,6 +2528,7 @@ class SnapshotHandler {
|
|
|
2349
2528
|
class SharedHandler {
|
|
2350
2529
|
constructor(host) {
|
|
2351
2530
|
this.hooks = new PluginSystem({
|
|
2531
|
+
beforeRegisterShare: new SyncWaterfallHook('beforeRegisterShare'),
|
|
2352
2532
|
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
2353
2533
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
2354
2534
|
// not used yet
|
|
@@ -2364,12 +2544,17 @@ class SharedHandler {
|
|
|
2364
2544
|
}
|
|
2365
2545
|
// register shared in shareScopeMap
|
|
2366
2546
|
registerShared(globalOptions, userOptions) {
|
|
2367
|
-
const {
|
|
2368
|
-
const sharedKeys = Object.keys(
|
|
2547
|
+
const { newShareInfos, allShareInfos } = formatShareConfigs(globalOptions, userOptions);
|
|
2548
|
+
const sharedKeys = Object.keys(newShareInfos);
|
|
2369
2549
|
sharedKeys.forEach((sharedKey) => {
|
|
2370
|
-
const sharedVals =
|
|
2550
|
+
const sharedVals = newShareInfos[sharedKey];
|
|
2371
2551
|
sharedVals.forEach((sharedVal) => {
|
|
2372
2552
|
sharedVal.scope.forEach((sc) => {
|
|
2553
|
+
this.hooks.lifecycle.beforeRegisterShare.emit({
|
|
2554
|
+
origin: this.host,
|
|
2555
|
+
pkgName: sharedKey,
|
|
2556
|
+
shared: sharedVal,
|
|
2557
|
+
});
|
|
2373
2558
|
const registeredShared = this.shareScopeMap[sc]?.[sharedKey];
|
|
2374
2559
|
if (!registeredShared) {
|
|
2375
2560
|
this.setShared({
|
|
@@ -2385,8 +2570,8 @@ class SharedHandler {
|
|
|
2385
2570
|
});
|
|
2386
2571
|
});
|
|
2387
2572
|
return {
|
|
2388
|
-
|
|
2389
|
-
|
|
2573
|
+
newShareInfos,
|
|
2574
|
+
allShareInfos,
|
|
2390
2575
|
};
|
|
2391
2576
|
}
|
|
2392
2577
|
async loadShare(pkgName, extraOptions) {
|
|
@@ -2417,61 +2602,61 @@ class SharedHandler {
|
|
|
2417
2602
|
const { shareInfo: shareOptionsRes } = loadShareRes;
|
|
2418
2603
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
2419
2604
|
assert(shareOptionsRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
if (
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
!registeredShared.loaded) {
|
|
2435
|
-
const factory = await registeredShared.loading;
|
|
2436
|
-
registeredShared.loaded = true;
|
|
2437
|
-
if (!registeredShared.lib) {
|
|
2438
|
-
registeredShared.lib = factory;
|
|
2439
|
-
}
|
|
2440
|
-
addUseIn(registeredShared);
|
|
2441
|
-
return factory;
|
|
2442
|
-
}
|
|
2443
|
-
else if (registeredShared) {
|
|
2444
|
-
const asyncLoadProcess = async () => {
|
|
2445
|
-
const factory = await registeredShared.get();
|
|
2446
|
-
addUseIn(registeredShared);
|
|
2447
|
-
registeredShared.loaded = true;
|
|
2448
|
-
registeredShared.lib = factory;
|
|
2605
|
+
const { shared: registeredShared, useTreesShaking } = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare) || {};
|
|
2606
|
+
if (registeredShared) {
|
|
2607
|
+
const targetShared = directShare(registeredShared, useTreesShaking);
|
|
2608
|
+
if (targetShared.lib) {
|
|
2609
|
+
addUseIn(targetShared, host.options.name);
|
|
2610
|
+
return targetShared.lib;
|
|
2611
|
+
}
|
|
2612
|
+
else if (targetShared.loading && !targetShared.loaded) {
|
|
2613
|
+
const factory = await targetShared.loading;
|
|
2614
|
+
targetShared.loaded = true;
|
|
2615
|
+
if (!targetShared.lib) {
|
|
2616
|
+
targetShared.lib = factory;
|
|
2617
|
+
}
|
|
2618
|
+
addUseIn(targetShared, host.options.name);
|
|
2449
2619
|
return factory;
|
|
2450
|
-
}
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2620
|
+
}
|
|
2621
|
+
else {
|
|
2622
|
+
const asyncLoadProcess = async () => {
|
|
2623
|
+
const factory = await targetShared.get();
|
|
2624
|
+
addUseIn(targetShared, host.options.name);
|
|
2625
|
+
targetShared.loaded = true;
|
|
2626
|
+
targetShared.lib = factory;
|
|
2627
|
+
return factory;
|
|
2628
|
+
};
|
|
2629
|
+
const loading = asyncLoadProcess();
|
|
2630
|
+
this.setShared({
|
|
2631
|
+
pkgName,
|
|
2632
|
+
loaded: false,
|
|
2633
|
+
shared: registeredShared,
|
|
2634
|
+
from: host.options.name,
|
|
2635
|
+
lib: null,
|
|
2636
|
+
loading,
|
|
2637
|
+
treeShaking: useTreesShaking
|
|
2638
|
+
? targetShared
|
|
2639
|
+
: undefined,
|
|
2640
|
+
});
|
|
2641
|
+
return loading;
|
|
2642
|
+
}
|
|
2461
2643
|
}
|
|
2462
2644
|
else {
|
|
2463
2645
|
if (extraOptions?.customShareInfo) {
|
|
2464
2646
|
return false;
|
|
2465
2647
|
}
|
|
2648
|
+
const _useTreeShaking = shouldUseTreeShaking(shareOptionsRes.treeShaking);
|
|
2649
|
+
const targetShared = directShare(shareOptionsRes, _useTreeShaking);
|
|
2466
2650
|
const asyncLoadProcess = async () => {
|
|
2467
|
-
const factory = await
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
addUseIn(
|
|
2471
|
-
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
|
|
2651
|
+
const factory = await targetShared.get();
|
|
2652
|
+
targetShared.lib = factory;
|
|
2653
|
+
targetShared.loaded = true;
|
|
2654
|
+
addUseIn(targetShared, host.options.name);
|
|
2655
|
+
const { shared: gShared, useTreesShaking: gUseTreeShaking } = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare) || {};
|
|
2472
2656
|
if (gShared) {
|
|
2473
|
-
|
|
2474
|
-
|
|
2657
|
+
const targetGShared = directShare(gShared, gUseTreeShaking);
|
|
2658
|
+
targetGShared.lib = factory;
|
|
2659
|
+
targetGShared.loaded = true;
|
|
2475
2660
|
gShared.from = shareOptionsRes.from;
|
|
2476
2661
|
}
|
|
2477
2662
|
return factory;
|
|
@@ -2484,6 +2669,9 @@ class SharedHandler {
|
|
|
2484
2669
|
from: host.options.name,
|
|
2485
2670
|
lib: null,
|
|
2486
2671
|
loading,
|
|
2672
|
+
treeShaking: _useTreeShaking
|
|
2673
|
+
? targetShared
|
|
2674
|
+
: undefined,
|
|
2487
2675
|
});
|
|
2488
2676
|
return loading;
|
|
2489
2677
|
}
|
|
@@ -2523,41 +2711,42 @@ class SharedHandler {
|
|
|
2523
2711
|
const { version, eager } = shared;
|
|
2524
2712
|
scope[name] = scope[name] || {};
|
|
2525
2713
|
const versions = scope[name];
|
|
2526
|
-
const activeVersion = versions[version];
|
|
2714
|
+
const activeVersion = versions[version] && directShare(versions[version]);
|
|
2527
2715
|
const activeVersionEager = Boolean(activeVersion &&
|
|
2528
|
-
(
|
|
2716
|
+
(('eager' in activeVersion && activeVersion.eager) ||
|
|
2717
|
+
('shareConfig' in activeVersion &&
|
|
2718
|
+
activeVersion.shareConfig?.eager)));
|
|
2529
2719
|
if (!activeVersion ||
|
|
2530
2720
|
(activeVersion.strategy !== 'loaded-first' &&
|
|
2531
2721
|
!activeVersion.loaded &&
|
|
2532
2722
|
(Boolean(!eager) !== !activeVersionEager
|
|
2533
2723
|
? eager
|
|
2534
|
-
: hostName >
|
|
2724
|
+
: hostName > versions[version].from))) {
|
|
2535
2725
|
versions[version] = shared;
|
|
2536
2726
|
}
|
|
2537
2727
|
};
|
|
2538
|
-
const initFn = (mod) => mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
|
|
2539
2728
|
const initRemoteModule = async (key) => {
|
|
2540
2729
|
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
2541
2730
|
id: key,
|
|
2542
2731
|
});
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
if (
|
|
2559
|
-
|
|
2560
|
-
module.
|
|
2732
|
+
let remoteEntryExports = undefined;
|
|
2733
|
+
try {
|
|
2734
|
+
remoteEntryExports = await module.getEntry();
|
|
2735
|
+
}
|
|
2736
|
+
catch (error) {
|
|
2737
|
+
remoteEntryExports =
|
|
2738
|
+
(await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
2739
|
+
id: key,
|
|
2740
|
+
error,
|
|
2741
|
+
from: 'runtime',
|
|
2742
|
+
lifecycle: 'beforeLoadShare',
|
|
2743
|
+
origin: host,
|
|
2744
|
+
}));
|
|
2745
|
+
}
|
|
2746
|
+
finally {
|
|
2747
|
+
if (remoteEntryExports?.init) {
|
|
2748
|
+
module.remoteEntryExports = remoteEntryExports;
|
|
2749
|
+
await module.init();
|
|
2561
2750
|
}
|
|
2562
2751
|
}
|
|
2563
2752
|
};
|
|
@@ -2596,16 +2785,10 @@ class SharedHandler {
|
|
|
2596
2785
|
this.initializeSharing(shareScope, { strategy: shareOptions.strategy });
|
|
2597
2786
|
});
|
|
2598
2787
|
}
|
|
2599
|
-
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare);
|
|
2600
|
-
const addUseIn = (shared) => {
|
|
2601
|
-
if (!shared.useIn) {
|
|
2602
|
-
shared.useIn = [];
|
|
2603
|
-
}
|
|
2604
|
-
addUniqueItem(shared.useIn, host.options.name);
|
|
2605
|
-
};
|
|
2788
|
+
const { shared: registeredShared, useTreesShaking } = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare) || {};
|
|
2606
2789
|
if (registeredShared) {
|
|
2607
2790
|
if (typeof registeredShared.lib === 'function') {
|
|
2608
|
-
addUseIn(registeredShared);
|
|
2791
|
+
addUseIn(registeredShared, host.options.name);
|
|
2609
2792
|
if (!registeredShared.loaded) {
|
|
2610
2793
|
registeredShared.loaded = true;
|
|
2611
2794
|
if (registeredShared.from === host.options.name) {
|
|
@@ -2617,7 +2800,7 @@ class SharedHandler {
|
|
|
2617
2800
|
if (typeof registeredShared.get === 'function') {
|
|
2618
2801
|
const module = registeredShared.get();
|
|
2619
2802
|
if (!(module instanceof Promise)) {
|
|
2620
|
-
addUseIn(registeredShared);
|
|
2803
|
+
addUseIn(registeredShared, host.options.name);
|
|
2621
2804
|
this.setShared({
|
|
2622
2805
|
pkgName,
|
|
2623
2806
|
loaded: true,
|
|
@@ -2670,9 +2853,20 @@ class SharedHandler {
|
|
|
2670
2853
|
hostShareScopeMap: extraOptions.hostShareScopeMap,
|
|
2671
2854
|
});
|
|
2672
2855
|
}
|
|
2673
|
-
setShared({ pkgName, shared, from, lib, loading, loaded, get, }) {
|
|
2856
|
+
setShared({ pkgName, shared, from, lib, loading, loaded, get, treeShaking, }) {
|
|
2674
2857
|
const { version, scope = 'default', ...shareInfo } = shared;
|
|
2675
2858
|
const scopes = Array.isArray(scope) ? scope : [scope];
|
|
2859
|
+
const mergeAttrs = (shared) => {
|
|
2860
|
+
const merge = (s, key, val) => {
|
|
2861
|
+
if (val && !s[key]) {
|
|
2862
|
+
s[key] = val;
|
|
2863
|
+
}
|
|
2864
|
+
};
|
|
2865
|
+
const targetShared = (treeShaking ? shared.treeShaking : shared);
|
|
2866
|
+
merge(targetShared, 'loaded', loaded);
|
|
2867
|
+
merge(targetShared, 'loading', loading);
|
|
2868
|
+
merge(targetShared, 'get', get);
|
|
2869
|
+
};
|
|
2676
2870
|
scopes.forEach((sc) => {
|
|
2677
2871
|
if (!this.shareScopeMap[sc]) {
|
|
2678
2872
|
this.shareScopeMap[sc] = {};
|
|
@@ -2686,21 +2880,10 @@ class SharedHandler {
|
|
|
2686
2880
|
scope: [sc],
|
|
2687
2881
|
...shareInfo,
|
|
2688
2882
|
lib,
|
|
2689
|
-
loaded,
|
|
2690
|
-
loading,
|
|
2691
2883
|
};
|
|
2692
|
-
if (get) {
|
|
2693
|
-
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
2694
|
-
}
|
|
2695
|
-
return;
|
|
2696
2884
|
}
|
|
2697
2885
|
const registeredShared = this.shareScopeMap[sc][pkgName][version];
|
|
2698
|
-
|
|
2699
|
-
registeredShared.loading = loading;
|
|
2700
|
-
}
|
|
2701
|
-
if (loaded && !registeredShared.loaded) {
|
|
2702
|
-
registeredShared.loaded = loaded;
|
|
2703
|
-
}
|
|
2886
|
+
mergeAttrs(registeredShared);
|
|
2704
2887
|
if (from && registeredShared.from !== from) {
|
|
2705
2888
|
registeredShared.from = from;
|
|
2706
2889
|
}
|
|
@@ -2728,6 +2911,7 @@ class RemoteHandler {
|
|
|
2728
2911
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
2729
2912
|
// not used yet
|
|
2730
2913
|
afterPreloadRemote: new AsyncHook(),
|
|
2914
|
+
// TODO: Move to loaderHook
|
|
2731
2915
|
loadEntry: new AsyncHook(),
|
|
2732
2916
|
});
|
|
2733
2917
|
this.host = host;
|
|
@@ -3076,7 +3260,7 @@ class ModuleFederation {
|
|
|
3076
3260
|
// maybe will change, temporarily for internal use only
|
|
3077
3261
|
initContainer: new AsyncWaterfallHook('initContainer'),
|
|
3078
3262
|
});
|
|
3079
|
-
this.version = "0.0.0-fix-
|
|
3263
|
+
this.version = "0.0.0-fix-webpack-manfest-version-20260202074337";
|
|
3080
3264
|
this.moduleCache = new Map();
|
|
3081
3265
|
this.loaderHook = new PluginSystem({
|
|
3082
3266
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -3157,7 +3341,7 @@ class ModuleFederation {
|
|
|
3157
3341
|
this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
|
|
3158
3342
|
}
|
|
3159
3343
|
formatOptions(globalOptions, userOptions) {
|
|
3160
|
-
const { shared
|
|
3344
|
+
const { allShareInfos: shared} = formatShareConfigs(globalOptions, userOptions);
|
|
3161
3345
|
const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
|
|
3162
3346
|
origin: this,
|
|
3163
3347
|
userOptions,
|
|
@@ -3165,7 +3349,7 @@ class ModuleFederation {
|
|
|
3165
3349
|
shareInfo: shared,
|
|
3166
3350
|
});
|
|
3167
3351
|
const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
|
|
3168
|
-
const {
|
|
3352
|
+
const { allShareInfos } = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes);
|
|
3169
3353
|
const plugins = [...globalOptionsRes.plugins];
|
|
3170
3354
|
if (userOptionsRes.plugins) {
|
|
3171
3355
|
userOptionsRes.plugins.forEach((plugin) => {
|
|
@@ -3179,7 +3363,7 @@ class ModuleFederation {
|
|
|
3179
3363
|
...userOptions,
|
|
3180
3364
|
plugins,
|
|
3181
3365
|
remotes,
|
|
3182
|
-
shared:
|
|
3366
|
+
shared: allShareInfos,
|
|
3183
3367
|
};
|
|
3184
3368
|
this.hooks.lifecycle.init.emit({
|
|
3185
3369
|
origin: this,
|