@module-federation/runtime-core 0.0.0-feat-shared-treeshake-poc-20260119091950 → 0.0.0-feat-node-manifest-20260122114009
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 +145 -345
- package/dist/index.cjs.cjs.map +1 -1
- package/dist/index.esm.js +145 -345
- package/dist/index.esm.js.map +1 -1
- package/dist/src/core.d.ts +1 -5
- package/dist/src/module/index.d.ts +1 -2
- package/dist/src/shared/index.d.ts +3 -12
- package/dist/src/type/config.d.ts +1 -14
- package/dist/src/utils/share.d.ts +9 -27
- package/package.json +3 -3
package/dist/index.cjs.cjs
CHANGED
|
@@ -94,7 +94,7 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
|
94
94
|
type: 'global',
|
|
95
95
|
globalName: '',
|
|
96
96
|
};
|
|
97
|
-
if (sdk.isBrowserEnv() || sdk.isReactNativeEnv()) {
|
|
97
|
+
if (sdk.isBrowserEnv() || sdk.isReactNativeEnv() || !('ssrRemoteEntry' in snapshot)) {
|
|
98
98
|
return 'remoteEntry' in snapshot
|
|
99
99
|
? {
|
|
100
100
|
url: snapshot.remoteEntry,
|
|
@@ -201,7 +201,7 @@ function getGlobalFederationConstructor() {
|
|
|
201
201
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
|
|
202
202
|
if (isDebug) {
|
|
203
203
|
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
204
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-feat-
|
|
204
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-feat-node-manifest-20260122114009";
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -808,9 +808,6 @@ function formatShare(shareArgs, from, name, shareStrategy) {
|
|
|
808
808
|
throw new Error(`Can not get shared '${name}'!`);
|
|
809
809
|
});
|
|
810
810
|
}
|
|
811
|
-
if (shareArgs.shareConfig?.eager && shareArgs.treeShaking) {
|
|
812
|
-
throw new Error('Can not set "eager:true" and "treeShaking" at the same time!');
|
|
813
|
-
}
|
|
814
811
|
return {
|
|
815
812
|
deps: [],
|
|
816
813
|
useIn: [],
|
|
@@ -831,67 +828,37 @@ function formatShare(shareArgs, from, name, shareStrategy) {
|
|
|
831
828
|
? shareArgs.scope
|
|
832
829
|
: [shareArgs.scope ?? 'default'],
|
|
833
830
|
strategy: (shareArgs.strategy ?? shareStrategy) || 'version-first',
|
|
834
|
-
treeShaking: shareArgs.treeShaking
|
|
835
|
-
? {
|
|
836
|
-
...shareArgs.treeShaking,
|
|
837
|
-
mode: shareArgs.treeShaking.mode ?? 'server-calc',
|
|
838
|
-
status: shareArgs.treeShaking.status ?? 1 /* TreeShakingStatus.UNKNOWN */,
|
|
839
|
-
useIn: [],
|
|
840
|
-
}
|
|
841
|
-
: undefined,
|
|
842
831
|
};
|
|
843
832
|
}
|
|
844
|
-
function formatShareConfigs(
|
|
845
|
-
const shareArgs =
|
|
846
|
-
const from =
|
|
847
|
-
const
|
|
833
|
+
function formatShareConfigs(globalOptions, userOptions) {
|
|
834
|
+
const shareArgs = userOptions.shared || {};
|
|
835
|
+
const from = userOptions.name;
|
|
836
|
+
const shareInfos = Object.keys(shareArgs).reduce((res, pkgName) => {
|
|
848
837
|
const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
|
|
849
838
|
res[pkgName] = res[pkgName] || [];
|
|
850
839
|
arrayShareArgs.forEach((shareConfig) => {
|
|
851
|
-
res[pkgName].push(formatShare(shareConfig, from, pkgName,
|
|
840
|
+
res[pkgName].push(formatShare(shareConfig, from, pkgName, userOptions.shareStrategy));
|
|
852
841
|
});
|
|
853
842
|
return res;
|
|
854
843
|
}, {});
|
|
855
|
-
const
|
|
856
|
-
...
|
|
844
|
+
const shared = {
|
|
845
|
+
...globalOptions.shared,
|
|
857
846
|
};
|
|
858
|
-
Object.keys(
|
|
859
|
-
if (!
|
|
860
|
-
|
|
847
|
+
Object.keys(shareInfos).forEach((shareKey) => {
|
|
848
|
+
if (!shared[shareKey]) {
|
|
849
|
+
shared[shareKey] = shareInfos[shareKey];
|
|
861
850
|
}
|
|
862
851
|
else {
|
|
863
|
-
|
|
864
|
-
const isSameVersion =
|
|
852
|
+
shareInfos[shareKey].forEach((newUserSharedOptions) => {
|
|
853
|
+
const isSameVersion = shared[shareKey].find((sharedVal) => sharedVal.version === newUserSharedOptions.version);
|
|
865
854
|
if (!isSameVersion) {
|
|
866
|
-
|
|
855
|
+
shared[shareKey].push(newUserSharedOptions);
|
|
867
856
|
}
|
|
868
857
|
});
|
|
869
858
|
}
|
|
870
859
|
});
|
|
871
|
-
return {
|
|
860
|
+
return { shared, shareInfos };
|
|
872
861
|
}
|
|
873
|
-
function shouldUseTreeShaking(treeShaking, usedExports) {
|
|
874
|
-
if (!treeShaking) {
|
|
875
|
-
return false;
|
|
876
|
-
}
|
|
877
|
-
const { status, mode } = treeShaking;
|
|
878
|
-
if (status === 0 /* TreeShakingStatus.NO_USE */) {
|
|
879
|
-
return false;
|
|
880
|
-
}
|
|
881
|
-
if (status === 2 /* TreeShakingStatus.CALCULATED */) {
|
|
882
|
-
return true;
|
|
883
|
-
}
|
|
884
|
-
if (mode === 'runtime-infer') {
|
|
885
|
-
if (!usedExports) {
|
|
886
|
-
return true;
|
|
887
|
-
}
|
|
888
|
-
return isMatchUsedExports(treeShaking, usedExports);
|
|
889
|
-
}
|
|
890
|
-
return false;
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* compare version a and b, return true if a is less than b
|
|
894
|
-
*/
|
|
895
862
|
function versionLt(a, b) {
|
|
896
863
|
const transformInvalidVersion = (version) => {
|
|
897
864
|
const isNumberVersion = !Number.isNaN(Number(version));
|
|
@@ -937,79 +904,19 @@ const isLoaded = (shared) => {
|
|
|
937
904
|
const isLoading = (shared) => {
|
|
938
905
|
return Boolean(shared.loading);
|
|
939
906
|
};
|
|
940
|
-
|
|
941
|
-
if (!treeShaking || !usedExports) {
|
|
942
|
-
return false;
|
|
943
|
-
}
|
|
944
|
-
const { usedExports: treeShakingUsedExports } = treeShaking;
|
|
945
|
-
if (!treeShakingUsedExports) {
|
|
946
|
-
return false;
|
|
947
|
-
}
|
|
948
|
-
if (usedExports.every((e) => treeShakingUsedExports.includes(e))) {
|
|
949
|
-
return true;
|
|
950
|
-
}
|
|
951
|
-
return false;
|
|
952
|
-
};
|
|
953
|
-
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName, treeShaking) {
|
|
907
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
954
908
|
const versions = shareScopeMap[scope][pkgName];
|
|
955
|
-
let version = '';
|
|
956
|
-
let useTreesShaking = shouldUseTreeShaking(treeShaking);
|
|
957
|
-
// return false means use prev version
|
|
958
909
|
const callback = function (prev, cur) {
|
|
959
|
-
if (useTreesShaking) {
|
|
960
|
-
if (!versions[prev].treeShaking) {
|
|
961
|
-
return true;
|
|
962
|
-
}
|
|
963
|
-
if (!versions[cur].treeShaking) {
|
|
964
|
-
return false;
|
|
965
|
-
}
|
|
966
|
-
return !isLoaded(versions[prev].treeShaking) && versionLt(prev, cur);
|
|
967
|
-
}
|
|
968
910
|
return !isLoaded(versions[prev]) && versionLt(prev, cur);
|
|
969
911
|
};
|
|
970
|
-
|
|
971
|
-
version = findVersion(shareScopeMap[scope][pkgName], callback);
|
|
972
|
-
if (version) {
|
|
973
|
-
return {
|
|
974
|
-
version,
|
|
975
|
-
useTreesShaking,
|
|
976
|
-
};
|
|
977
|
-
}
|
|
978
|
-
useTreesShaking = false;
|
|
979
|
-
}
|
|
980
|
-
return {
|
|
981
|
-
version: findVersion(shareScopeMap[scope][pkgName], callback),
|
|
982
|
-
useTreesShaking,
|
|
983
|
-
};
|
|
912
|
+
return findVersion(shareScopeMap[scope][pkgName], callback);
|
|
984
913
|
}
|
|
985
|
-
|
|
986
|
-
return isLoaded(shared) || isLoading(shared);
|
|
987
|
-
};
|
|
988
|
-
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName, treeShaking) {
|
|
914
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
989
915
|
const versions = shareScopeMap[scope][pkgName];
|
|
990
|
-
let version = '';
|
|
991
|
-
let useTreesShaking = shouldUseTreeShaking(treeShaking);
|
|
992
|
-
// return false means use prev version
|
|
993
916
|
const callback = function (prev, cur) {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
if (!versions[cur].treeShaking) {
|
|
999
|
-
return false;
|
|
1000
|
-
}
|
|
1001
|
-
if (isLoadingOrLoaded(versions[cur].treeShaking)) {
|
|
1002
|
-
if (isLoadingOrLoaded(versions[prev].treeShaking)) {
|
|
1003
|
-
return Boolean(versionLt(prev, cur));
|
|
1004
|
-
}
|
|
1005
|
-
else {
|
|
1006
|
-
return true;
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
if (isLoadingOrLoaded(versions[prev].treeShaking)) {
|
|
1010
|
-
return false;
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
917
|
+
const isLoadingOrLoaded = (shared) => {
|
|
918
|
+
return isLoaded(shared) || isLoading(shared);
|
|
919
|
+
};
|
|
1013
920
|
if (isLoadingOrLoaded(versions[cur])) {
|
|
1014
921
|
if (isLoadingOrLoaded(versions[prev])) {
|
|
1015
922
|
return Boolean(versionLt(prev, cur));
|
|
@@ -1023,20 +930,7 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName, treeSh
|
|
|
1023
930
|
}
|
|
1024
931
|
return versionLt(prev, cur);
|
|
1025
932
|
};
|
|
1026
|
-
|
|
1027
|
-
version = findVersion(shareScopeMap[scope][pkgName], callback);
|
|
1028
|
-
if (version) {
|
|
1029
|
-
return {
|
|
1030
|
-
version,
|
|
1031
|
-
useTreesShaking,
|
|
1032
|
-
};
|
|
1033
|
-
}
|
|
1034
|
-
useTreesShaking = false;
|
|
1035
|
-
}
|
|
1036
|
-
return {
|
|
1037
|
-
version: findVersion(shareScopeMap[scope][pkgName], callback),
|
|
1038
|
-
useTreesShaking,
|
|
1039
|
-
};
|
|
933
|
+
return findVersion(shareScopeMap[scope][pkgName], callback);
|
|
1040
934
|
}
|
|
1041
935
|
function getFindShareFunction(strategy) {
|
|
1042
936
|
if (strategy === 'loaded-first') {
|
|
@@ -1048,7 +942,7 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
1048
942
|
if (!localShareScopeMap) {
|
|
1049
943
|
return;
|
|
1050
944
|
}
|
|
1051
|
-
const { shareConfig, scope = DEFAULT_SCOPE, strategy
|
|
945
|
+
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
1052
946
|
const scopes = Array.isArray(scope) ? scope : [scope];
|
|
1053
947
|
for (const sc of scopes) {
|
|
1054
948
|
if (shareConfig &&
|
|
@@ -1056,13 +950,14 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
1056
950
|
localShareScopeMap[sc][pkgName]) {
|
|
1057
951
|
const { requiredVersion } = shareConfig;
|
|
1058
952
|
const findShareFunction = getFindShareFunction(strategy);
|
|
1059
|
-
const
|
|
953
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
954
|
+
//@ts-ignore
|
|
1060
955
|
const defaultResolver = () => {
|
|
1061
|
-
const shared = localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
1062
956
|
if (shareConfig.singleton) {
|
|
1063
957
|
if (typeof requiredVersion === 'string' &&
|
|
1064
958
|
!satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
1065
|
-
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion &&
|
|
959
|
+
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion &&
|
|
960
|
+
localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
|
|
1066
961
|
if (shareConfig.strictVersion) {
|
|
1067
962
|
error(msg);
|
|
1068
963
|
}
|
|
@@ -1070,48 +965,21 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
1070
965
|
warn(msg);
|
|
1071
966
|
}
|
|
1072
967
|
}
|
|
1073
|
-
return
|
|
1074
|
-
shared,
|
|
1075
|
-
useTreesShaking,
|
|
1076
|
-
};
|
|
968
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
1077
969
|
}
|
|
1078
970
|
else {
|
|
1079
971
|
if (requiredVersion === false || requiredVersion === '*') {
|
|
1080
|
-
return
|
|
1081
|
-
shared,
|
|
1082
|
-
useTreesShaking,
|
|
1083
|
-
};
|
|
972
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
1084
973
|
}
|
|
1085
974
|
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
1086
|
-
return
|
|
1087
|
-
shared,
|
|
1088
|
-
useTreesShaking,
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
const _usedTreeShaking = shouldUseTreeShaking(treeShaking);
|
|
1092
|
-
if (_usedTreeShaking) {
|
|
1093
|
-
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])) {
|
|
1094
|
-
if (!shouldUseTreeShaking(versionValue.treeShaking, treeShaking?.usedExports)) {
|
|
1095
|
-
continue;
|
|
1096
|
-
}
|
|
1097
|
-
if (satisfy(versionKey, requiredVersion)) {
|
|
1098
|
-
return {
|
|
1099
|
-
shared: versionValue,
|
|
1100
|
-
useTreesShaking: _usedTreeShaking,
|
|
1101
|
-
};
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
975
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
1104
976
|
}
|
|
1105
977
|
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])) {
|
|
1106
978
|
if (satisfy(versionKey, requiredVersion)) {
|
|
1107
|
-
return
|
|
1108
|
-
shared: versionValue,
|
|
1109
|
-
useTreesShaking: false,
|
|
1110
|
-
};
|
|
979
|
+
return versionValue;
|
|
1111
980
|
}
|
|
1112
981
|
}
|
|
1113
982
|
}
|
|
1114
|
-
return;
|
|
1115
983
|
};
|
|
1116
984
|
const params = {
|
|
1117
985
|
shareScopeMap: localShareScopeMap,
|
|
@@ -1119,7 +987,6 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
1119
987
|
pkgName,
|
|
1120
988
|
version: maxOrSingletonVersion,
|
|
1121
989
|
GlobalFederation: Global.__FEDERATION__,
|
|
1122
|
-
shareInfo,
|
|
1123
990
|
resolver: defaultResolver,
|
|
1124
991
|
};
|
|
1125
992
|
const resolveShared = resolveShare.emit(params) || params;
|
|
@@ -1141,47 +1008,13 @@ function getTargetSharedOptions(options) {
|
|
|
1141
1008
|
shareVersionMap[shared.version] = shared;
|
|
1142
1009
|
});
|
|
1143
1010
|
const callback = function (prev, cur) {
|
|
1144
|
-
return (
|
|
1145
|
-
// TODO: consider multiple treeShaking shared scenes
|
|
1146
|
-
!isLoaded(shareVersionMap[prev]) && versionLt(prev, cur));
|
|
1011
|
+
return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
|
|
1147
1012
|
};
|
|
1148
1013
|
const maxVersion = findVersion(shareVersionMap, callback);
|
|
1149
1014
|
return shareVersionMap[maxVersion];
|
|
1150
1015
|
};
|
|
1151
1016
|
const resolver = extraOptions?.resolver ?? defaultResolver;
|
|
1152
|
-
|
|
1153
|
-
return val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
1154
|
-
};
|
|
1155
|
-
const merge = (...sources) => {
|
|
1156
|
-
const out = {};
|
|
1157
|
-
for (const src of sources) {
|
|
1158
|
-
if (!src)
|
|
1159
|
-
continue;
|
|
1160
|
-
for (const [key, value] of Object.entries(src)) {
|
|
1161
|
-
const prev = out[key];
|
|
1162
|
-
if (isPlainObject(prev) && isPlainObject(value)) {
|
|
1163
|
-
out[key] = merge(prev, value);
|
|
1164
|
-
}
|
|
1165
|
-
else if (value !== undefined) {
|
|
1166
|
-
out[key] = value;
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
return out;
|
|
1171
|
-
};
|
|
1172
|
-
return merge(resolver(shareInfos[pkgName]), extraOptions?.customShareInfo);
|
|
1173
|
-
}
|
|
1174
|
-
const addUseIn = (shared, from) => {
|
|
1175
|
-
if (!shared.useIn) {
|
|
1176
|
-
shared.useIn = [];
|
|
1177
|
-
}
|
|
1178
|
-
addUniqueItem(shared.useIn, from);
|
|
1179
|
-
};
|
|
1180
|
-
function directShare(shared, useTreesShaking) {
|
|
1181
|
-
if (useTreesShaking && shared.treeShaking) {
|
|
1182
|
-
return shared.treeShaking;
|
|
1183
|
-
}
|
|
1184
|
-
return shared;
|
|
1017
|
+
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions?.customShareInfo);
|
|
1185
1018
|
}
|
|
1186
1019
|
|
|
1187
1020
|
function getBuilderId() {
|
|
@@ -1693,40 +1526,6 @@ var helpers = {
|
|
|
1693
1526
|
},
|
|
1694
1527
|
};
|
|
1695
1528
|
|
|
1696
|
-
function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap) {
|
|
1697
|
-
const localShareScopeMap = hostShareScopeMap;
|
|
1698
|
-
const shareScopeKeys = Array.isArray(remoteInfo.shareScope)
|
|
1699
|
-
? remoteInfo.shareScope
|
|
1700
|
-
: [remoteInfo.shareScope];
|
|
1701
|
-
if (!shareScopeKeys.length) {
|
|
1702
|
-
shareScopeKeys.push('default');
|
|
1703
|
-
}
|
|
1704
|
-
shareScopeKeys.forEach((shareScopeKey) => {
|
|
1705
|
-
if (!localShareScopeMap[shareScopeKey]) {
|
|
1706
|
-
localShareScopeMap[shareScopeKey] = {};
|
|
1707
|
-
}
|
|
1708
|
-
});
|
|
1709
|
-
const remoteEntryInitOptions = {
|
|
1710
|
-
version: remoteInfo.version || '',
|
|
1711
|
-
shareScopeKeys: Array.isArray(remoteInfo.shareScope)
|
|
1712
|
-
? shareScopeKeys
|
|
1713
|
-
: remoteInfo.shareScope || 'default',
|
|
1714
|
-
};
|
|
1715
|
-
// Help to find host instance
|
|
1716
|
-
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
1717
|
-
value: localShareScopeMap,
|
|
1718
|
-
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
1719
|
-
enumerable: false,
|
|
1720
|
-
});
|
|
1721
|
-
// TODO: compate legacy init params, should use shareScopeMap if exist
|
|
1722
|
-
const shareScope = localShareScopeMap[shareScopeKeys[0]];
|
|
1723
|
-
const initScope = [];
|
|
1724
|
-
return {
|
|
1725
|
-
remoteEntryInitOptions,
|
|
1726
|
-
shareScope,
|
|
1727
|
-
initScope,
|
|
1728
|
-
};
|
|
1729
|
-
}
|
|
1730
1529
|
class Module {
|
|
1731
1530
|
constructor({ remoteInfo, host, }) {
|
|
1732
1531
|
this.inited = false;
|
|
@@ -1752,7 +1551,33 @@ class Module {
|
|
|
1752
1551
|
// Get remoteEntry.js
|
|
1753
1552
|
const remoteEntryExports = await this.getEntry();
|
|
1754
1553
|
if (!this.inited) {
|
|
1755
|
-
const
|
|
1554
|
+
const localShareScopeMap = this.host.shareScopeMap;
|
|
1555
|
+
const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope)
|
|
1556
|
+
? this.remoteInfo.shareScope
|
|
1557
|
+
: [this.remoteInfo.shareScope];
|
|
1558
|
+
if (!shareScopeKeys.length) {
|
|
1559
|
+
shareScopeKeys.push('default');
|
|
1560
|
+
}
|
|
1561
|
+
shareScopeKeys.forEach((shareScopeKey) => {
|
|
1562
|
+
if (!localShareScopeMap[shareScopeKey]) {
|
|
1563
|
+
localShareScopeMap[shareScopeKey] = {};
|
|
1564
|
+
}
|
|
1565
|
+
});
|
|
1566
|
+
// TODO: compate legacy init params, should use shareScopeMap if exist
|
|
1567
|
+
const shareScope = localShareScopeMap[shareScopeKeys[0]];
|
|
1568
|
+
const initScope = [];
|
|
1569
|
+
const remoteEntryInitOptions = {
|
|
1570
|
+
version: this.remoteInfo.version || '',
|
|
1571
|
+
shareScopeKeys: Array.isArray(this.remoteInfo.shareScope)
|
|
1572
|
+
? shareScopeKeys
|
|
1573
|
+
: this.remoteInfo.shareScope || 'default',
|
|
1574
|
+
};
|
|
1575
|
+
// Help to find host instance
|
|
1576
|
+
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
1577
|
+
value: localShareScopeMap,
|
|
1578
|
+
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
1579
|
+
enumerable: false,
|
|
1580
|
+
});
|
|
1756
1581
|
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
1757
1582
|
shareScope,
|
|
1758
1583
|
// @ts-ignore shareScopeMap will be set by Object.defineProperty
|
|
@@ -1776,7 +1601,6 @@ class Module {
|
|
|
1776
1601
|
remoteSnapshot,
|
|
1777
1602
|
remoteEntryExports,
|
|
1778
1603
|
});
|
|
1779
|
-
this.inited = true;
|
|
1780
1604
|
}
|
|
1781
1605
|
return remoteEntryExports;
|
|
1782
1606
|
}
|
|
@@ -1785,6 +1609,7 @@ class Module {
|
|
|
1785
1609
|
const { loadFactory = true } = options || { loadFactory: true };
|
|
1786
1610
|
const remoteEntryExports = await this.init(id, remoteSnapshot);
|
|
1787
1611
|
this.lib = remoteEntryExports;
|
|
1612
|
+
this.inited = true;
|
|
1788
1613
|
let moduleFactory;
|
|
1789
1614
|
moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
|
|
1790
1615
|
remoteEntryExports,
|
|
@@ -2238,7 +2063,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
2238
2063
|
}, true, memo, remoteSnapshot);
|
|
2239
2064
|
if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
|
|
2240
2065
|
const collectSharedAssets = (shareInfo, snapshotShared) => {
|
|
2241
|
-
const
|
|
2066
|
+
const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
|
|
2242
2067
|
// 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.
|
|
2243
2068
|
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
2244
2069
|
snapshotShared.assets.js.sync.forEach((asset) => {
|
|
@@ -2529,7 +2354,6 @@ class SnapshotHandler {
|
|
|
2529
2354
|
class SharedHandler {
|
|
2530
2355
|
constructor(host) {
|
|
2531
2356
|
this.hooks = new PluginSystem({
|
|
2532
|
-
beforeRegisterShare: new SyncWaterfallHook('beforeRegisterShare'),
|
|
2533
2357
|
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
2534
2358
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
2535
2359
|
// not used yet
|
|
@@ -2545,17 +2369,12 @@ class SharedHandler {
|
|
|
2545
2369
|
}
|
|
2546
2370
|
// register shared in shareScopeMap
|
|
2547
2371
|
registerShared(globalOptions, userOptions) {
|
|
2548
|
-
const {
|
|
2549
|
-
const sharedKeys = Object.keys(
|
|
2372
|
+
const { shareInfos, shared } = formatShareConfigs(globalOptions, userOptions);
|
|
2373
|
+
const sharedKeys = Object.keys(shareInfos);
|
|
2550
2374
|
sharedKeys.forEach((sharedKey) => {
|
|
2551
|
-
const sharedVals =
|
|
2375
|
+
const sharedVals = shareInfos[sharedKey];
|
|
2552
2376
|
sharedVals.forEach((sharedVal) => {
|
|
2553
2377
|
sharedVal.scope.forEach((sc) => {
|
|
2554
|
-
this.hooks.lifecycle.beforeRegisterShare.emit({
|
|
2555
|
-
origin: this.host,
|
|
2556
|
-
pkgName: sharedKey,
|
|
2557
|
-
shared: sharedVal,
|
|
2558
|
-
});
|
|
2559
2378
|
const registeredShared = this.shareScopeMap[sc]?.[sharedKey];
|
|
2560
2379
|
if (!registeredShared) {
|
|
2561
2380
|
this.setShared({
|
|
@@ -2571,8 +2390,8 @@ class SharedHandler {
|
|
|
2571
2390
|
});
|
|
2572
2391
|
});
|
|
2573
2392
|
return {
|
|
2574
|
-
|
|
2575
|
-
|
|
2393
|
+
shareInfos,
|
|
2394
|
+
shared,
|
|
2576
2395
|
};
|
|
2577
2396
|
}
|
|
2578
2397
|
async loadShare(pkgName, extraOptions) {
|
|
@@ -2603,61 +2422,61 @@ class SharedHandler {
|
|
|
2603
2422
|
const { shareInfo: shareOptionsRes } = loadShareRes;
|
|
2604
2423
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
2605
2424
|
assert(shareOptionsRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
if (
|
|
2610
|
-
|
|
2611
|
-
return targetShared.lib;
|
|
2612
|
-
}
|
|
2613
|
-
else if (targetShared.loading && !targetShared.loaded) {
|
|
2614
|
-
const factory = await targetShared.loading;
|
|
2615
|
-
targetShared.loaded = true;
|
|
2616
|
-
if (!targetShared.lib) {
|
|
2617
|
-
targetShared.lib = factory;
|
|
2618
|
-
}
|
|
2619
|
-
addUseIn(targetShared, host.options.name);
|
|
2620
|
-
return factory;
|
|
2621
|
-
}
|
|
2622
|
-
else {
|
|
2623
|
-
const asyncLoadProcess = async () => {
|
|
2624
|
-
const factory = await targetShared.get();
|
|
2625
|
-
addUseIn(targetShared, host.options.name);
|
|
2626
|
-
targetShared.loaded = true;
|
|
2627
|
-
targetShared.lib = factory;
|
|
2628
|
-
return factory;
|
|
2629
|
-
};
|
|
2630
|
-
const loading = asyncLoadProcess();
|
|
2631
|
-
this.setShared({
|
|
2632
|
-
pkgName,
|
|
2633
|
-
loaded: false,
|
|
2634
|
-
shared: registeredShared,
|
|
2635
|
-
from: host.options.name,
|
|
2636
|
-
lib: null,
|
|
2637
|
-
loading,
|
|
2638
|
-
treeShaking: useTreesShaking
|
|
2639
|
-
? targetShared
|
|
2640
|
-
: undefined,
|
|
2641
|
-
});
|
|
2642
|
-
return loading;
|
|
2425
|
+
// Retrieve from cache
|
|
2426
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
|
|
2427
|
+
const addUseIn = (shared) => {
|
|
2428
|
+
if (!shared.useIn) {
|
|
2429
|
+
shared.useIn = [];
|
|
2643
2430
|
}
|
|
2431
|
+
addUniqueItem(shared.useIn, host.options.name);
|
|
2432
|
+
};
|
|
2433
|
+
if (registeredShared && registeredShared.lib) {
|
|
2434
|
+
addUseIn(registeredShared);
|
|
2435
|
+
return registeredShared.lib;
|
|
2436
|
+
}
|
|
2437
|
+
else if (registeredShared &&
|
|
2438
|
+
registeredShared.loading &&
|
|
2439
|
+
!registeredShared.loaded) {
|
|
2440
|
+
const factory = await registeredShared.loading;
|
|
2441
|
+
registeredShared.loaded = true;
|
|
2442
|
+
if (!registeredShared.lib) {
|
|
2443
|
+
registeredShared.lib = factory;
|
|
2444
|
+
}
|
|
2445
|
+
addUseIn(registeredShared);
|
|
2446
|
+
return factory;
|
|
2447
|
+
}
|
|
2448
|
+
else if (registeredShared) {
|
|
2449
|
+
const asyncLoadProcess = async () => {
|
|
2450
|
+
const factory = await registeredShared.get();
|
|
2451
|
+
addUseIn(registeredShared);
|
|
2452
|
+
registeredShared.loaded = true;
|
|
2453
|
+
registeredShared.lib = factory;
|
|
2454
|
+
return factory;
|
|
2455
|
+
};
|
|
2456
|
+
const loading = asyncLoadProcess();
|
|
2457
|
+
this.setShared({
|
|
2458
|
+
pkgName,
|
|
2459
|
+
loaded: false,
|
|
2460
|
+
shared: registeredShared,
|
|
2461
|
+
from: host.options.name,
|
|
2462
|
+
lib: null,
|
|
2463
|
+
loading,
|
|
2464
|
+
});
|
|
2465
|
+
return loading;
|
|
2644
2466
|
}
|
|
2645
2467
|
else {
|
|
2646
2468
|
if (extraOptions?.customShareInfo) {
|
|
2647
2469
|
return false;
|
|
2648
2470
|
}
|
|
2649
|
-
const _useTreeShaking = shouldUseTreeShaking(shareOptionsRes.treeShaking);
|
|
2650
|
-
const targetShared = directShare(shareOptionsRes, _useTreeShaking);
|
|
2651
2471
|
const asyncLoadProcess = async () => {
|
|
2652
|
-
const factory = await
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
addUseIn(
|
|
2656
|
-
const
|
|
2472
|
+
const factory = await shareOptionsRes.get();
|
|
2473
|
+
shareOptionsRes.lib = factory;
|
|
2474
|
+
shareOptionsRes.loaded = true;
|
|
2475
|
+
addUseIn(shareOptionsRes);
|
|
2476
|
+
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
|
|
2657
2477
|
if (gShared) {
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
targetGShared.loaded = true;
|
|
2478
|
+
gShared.lib = factory;
|
|
2479
|
+
gShared.loaded = true;
|
|
2661
2480
|
gShared.from = shareOptionsRes.from;
|
|
2662
2481
|
}
|
|
2663
2482
|
return factory;
|
|
@@ -2670,9 +2489,6 @@ class SharedHandler {
|
|
|
2670
2489
|
from: host.options.name,
|
|
2671
2490
|
lib: null,
|
|
2672
2491
|
loading,
|
|
2673
|
-
treeShaking: _useTreeShaking
|
|
2674
|
-
? targetShared
|
|
2675
|
-
: undefined,
|
|
2676
2492
|
});
|
|
2677
2493
|
return loading;
|
|
2678
2494
|
}
|
|
@@ -2712,17 +2528,15 @@ class SharedHandler {
|
|
|
2712
2528
|
const { version, eager } = shared;
|
|
2713
2529
|
scope[name] = scope[name] || {};
|
|
2714
2530
|
const versions = scope[name];
|
|
2715
|
-
const activeVersion = versions[version]
|
|
2531
|
+
const activeVersion = versions[version];
|
|
2716
2532
|
const activeVersionEager = Boolean(activeVersion &&
|
|
2717
|
-
(
|
|
2718
|
-
('shareConfig' in activeVersion &&
|
|
2719
|
-
activeVersion.shareConfig?.eager)));
|
|
2533
|
+
(activeVersion.eager || activeVersion.shareConfig?.eager));
|
|
2720
2534
|
if (!activeVersion ||
|
|
2721
2535
|
(activeVersion.strategy !== 'loaded-first' &&
|
|
2722
2536
|
!activeVersion.loaded &&
|
|
2723
2537
|
(Boolean(!eager) !== !activeVersionEager
|
|
2724
2538
|
? eager
|
|
2725
|
-
: hostName >
|
|
2539
|
+
: hostName > activeVersion.from))) {
|
|
2726
2540
|
versions[version] = shared;
|
|
2727
2541
|
}
|
|
2728
2542
|
};
|
|
@@ -2730,26 +2544,7 @@ class SharedHandler {
|
|
|
2730
2544
|
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
2731
2545
|
id: key,
|
|
2732
2546
|
});
|
|
2733
|
-
|
|
2734
|
-
try {
|
|
2735
|
-
remoteEntryExports = await module.getEntry();
|
|
2736
|
-
}
|
|
2737
|
-
catch (error) {
|
|
2738
|
-
remoteEntryExports =
|
|
2739
|
-
(await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
2740
|
-
id: key,
|
|
2741
|
-
error,
|
|
2742
|
-
from: 'runtime',
|
|
2743
|
-
lifecycle: 'beforeLoadShare',
|
|
2744
|
-
origin: host,
|
|
2745
|
-
}));
|
|
2746
|
-
}
|
|
2747
|
-
finally {
|
|
2748
|
-
if (remoteEntryExports?.init) {
|
|
2749
|
-
module.remoteEntryExports = remoteEntryExports;
|
|
2750
|
-
await module.init();
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2547
|
+
await module.init();
|
|
2753
2548
|
};
|
|
2754
2549
|
Object.keys(host.options.shared).forEach((shareName) => {
|
|
2755
2550
|
const sharedArr = host.options.shared[shareName];
|
|
@@ -2786,10 +2581,16 @@ class SharedHandler {
|
|
|
2786
2581
|
this.initializeSharing(shareScope, { strategy: shareOptions.strategy });
|
|
2787
2582
|
});
|
|
2788
2583
|
}
|
|
2789
|
-
const
|
|
2584
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare);
|
|
2585
|
+
const addUseIn = (shared) => {
|
|
2586
|
+
if (!shared.useIn) {
|
|
2587
|
+
shared.useIn = [];
|
|
2588
|
+
}
|
|
2589
|
+
addUniqueItem(shared.useIn, host.options.name);
|
|
2590
|
+
};
|
|
2790
2591
|
if (registeredShared) {
|
|
2791
2592
|
if (typeof registeredShared.lib === 'function') {
|
|
2792
|
-
addUseIn(registeredShared
|
|
2593
|
+
addUseIn(registeredShared);
|
|
2793
2594
|
if (!registeredShared.loaded) {
|
|
2794
2595
|
registeredShared.loaded = true;
|
|
2795
2596
|
if (registeredShared.from === host.options.name) {
|
|
@@ -2801,7 +2602,7 @@ class SharedHandler {
|
|
|
2801
2602
|
if (typeof registeredShared.get === 'function') {
|
|
2802
2603
|
const module = registeredShared.get();
|
|
2803
2604
|
if (!(module instanceof Promise)) {
|
|
2804
|
-
addUseIn(registeredShared
|
|
2605
|
+
addUseIn(registeredShared);
|
|
2805
2606
|
this.setShared({
|
|
2806
2607
|
pkgName,
|
|
2807
2608
|
loaded: true,
|
|
@@ -2854,20 +2655,9 @@ class SharedHandler {
|
|
|
2854
2655
|
hostShareScopeMap: extraOptions.hostShareScopeMap,
|
|
2855
2656
|
});
|
|
2856
2657
|
}
|
|
2857
|
-
setShared({ pkgName, shared, from, lib, loading, loaded, get,
|
|
2658
|
+
setShared({ pkgName, shared, from, lib, loading, loaded, get, }) {
|
|
2858
2659
|
const { version, scope = 'default', ...shareInfo } = shared;
|
|
2859
2660
|
const scopes = Array.isArray(scope) ? scope : [scope];
|
|
2860
|
-
const mergeAttrs = (shared) => {
|
|
2861
|
-
const merge = (s, key, val) => {
|
|
2862
|
-
if (val && !s[key]) {
|
|
2863
|
-
s[key] = val;
|
|
2864
|
-
}
|
|
2865
|
-
};
|
|
2866
|
-
const targetShared = (treeShaking ? shared.treeShaking : shared);
|
|
2867
|
-
merge(targetShared, 'loaded', loaded);
|
|
2868
|
-
merge(targetShared, 'loading', loading);
|
|
2869
|
-
merge(targetShared, 'get', get);
|
|
2870
|
-
};
|
|
2871
2661
|
scopes.forEach((sc) => {
|
|
2872
2662
|
if (!this.shareScopeMap[sc]) {
|
|
2873
2663
|
this.shareScopeMap[sc] = {};
|
|
@@ -2881,10 +2671,21 @@ class SharedHandler {
|
|
|
2881
2671
|
scope: [sc],
|
|
2882
2672
|
...shareInfo,
|
|
2883
2673
|
lib,
|
|
2674
|
+
loaded,
|
|
2675
|
+
loading,
|
|
2884
2676
|
};
|
|
2677
|
+
if (get) {
|
|
2678
|
+
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
2679
|
+
}
|
|
2680
|
+
return;
|
|
2885
2681
|
}
|
|
2886
2682
|
const registeredShared = this.shareScopeMap[sc][pkgName][version];
|
|
2887
|
-
|
|
2683
|
+
if (loading && !registeredShared.loading) {
|
|
2684
|
+
registeredShared.loading = loading;
|
|
2685
|
+
}
|
|
2686
|
+
if (loaded && !registeredShared.loaded) {
|
|
2687
|
+
registeredShared.loaded = loaded;
|
|
2688
|
+
}
|
|
2888
2689
|
if (from && registeredShared.from !== from) {
|
|
2889
2690
|
registeredShared.from = from;
|
|
2890
2691
|
}
|
|
@@ -2912,7 +2713,6 @@ class RemoteHandler {
|
|
|
2912
2713
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
2913
2714
|
// not used yet
|
|
2914
2715
|
afterPreloadRemote: new AsyncHook(),
|
|
2915
|
-
// TODO: Move to loaderHook
|
|
2916
2716
|
loadEntry: new AsyncHook(),
|
|
2917
2717
|
});
|
|
2918
2718
|
this.host = host;
|
|
@@ -3261,7 +3061,7 @@ class ModuleFederation {
|
|
|
3261
3061
|
// maybe will change, temporarily for internal use only
|
|
3262
3062
|
initContainer: new AsyncWaterfallHook('initContainer'),
|
|
3263
3063
|
});
|
|
3264
|
-
this.version = "0.0.0-feat-
|
|
3064
|
+
this.version = "0.0.0-feat-node-manifest-20260122114009";
|
|
3265
3065
|
this.moduleCache = new Map();
|
|
3266
3066
|
this.loaderHook = new PluginSystem({
|
|
3267
3067
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -3342,7 +3142,7 @@ class ModuleFederation {
|
|
|
3342
3142
|
this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
|
|
3343
3143
|
}
|
|
3344
3144
|
formatOptions(globalOptions, userOptions) {
|
|
3345
|
-
const {
|
|
3145
|
+
const { shared } = formatShareConfigs(globalOptions, userOptions);
|
|
3346
3146
|
const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
|
|
3347
3147
|
origin: this,
|
|
3348
3148
|
userOptions,
|
|
@@ -3350,7 +3150,7 @@ class ModuleFederation {
|
|
|
3350
3150
|
shareInfo: shared,
|
|
3351
3151
|
});
|
|
3352
3152
|
const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
|
|
3353
|
-
const {
|
|
3153
|
+
const { shared: handledShared } = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes);
|
|
3354
3154
|
const plugins = [...globalOptionsRes.plugins];
|
|
3355
3155
|
if (userOptionsRes.plugins) {
|
|
3356
3156
|
userOptionsRes.plugins.forEach((plugin) => {
|
|
@@ -3364,7 +3164,7 @@ class ModuleFederation {
|
|
|
3364
3164
|
...userOptions,
|
|
3365
3165
|
plugins,
|
|
3366
3166
|
remotes,
|
|
3367
|
-
shared:
|
|
3167
|
+
shared: handledShared,
|
|
3368
3168
|
};
|
|
3369
3169
|
this.hooks.lifecycle.init.emit({
|
|
3370
3170
|
origin: this,
|