@module-federation/vite 1.18.0 → 1.18.2
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/README.md +1 -0
- package/lib/index.js +578 -340
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -490,6 +490,7 @@ function normalizeManifest(manifest) {
|
|
|
490
490
|
}
|
|
491
491
|
let config;
|
|
492
492
|
let explicitSharedKeys = /* @__PURE__ */ new Set();
|
|
493
|
+
const explicitSharedKeysByOptions = /* @__PURE__ */ new WeakMap();
|
|
493
494
|
function resolveRuntimeImplementation() {
|
|
494
495
|
const fallback = resolveImportPath("@module-federation/runtime");
|
|
495
496
|
try {
|
|
@@ -505,17 +506,16 @@ function resolveRuntimeImplementation() {
|
|
|
505
506
|
function getNormalizeModuleFederationOptions() {
|
|
506
507
|
return config;
|
|
507
508
|
}
|
|
508
|
-
function isExplicitSharedKey(key) {
|
|
509
|
-
return explicitSharedKeys
|
|
509
|
+
function isExplicitSharedKey(key, options) {
|
|
510
|
+
return (options ? explicitSharedKeysByOptions.get(options) : explicitSharedKeys)?.has(key) ?? false;
|
|
510
511
|
}
|
|
511
|
-
function getNormalizeShareItem(key) {
|
|
512
|
-
const options = getNormalizeModuleFederationOptions();
|
|
512
|
+
function getNormalizeShareItem(key, options = getNormalizeModuleFederationOptions()) {
|
|
513
513
|
return options.shared[key] || options.shared[getPackageName(key)] || options.shared[getPackageName(key) + "/"];
|
|
514
514
|
}
|
|
515
515
|
function normalizeModuleFederationOptions(options) {
|
|
516
516
|
warnOnReservedInternalNamePrefix(options.name, "containerName");
|
|
517
517
|
if (options.virtualModuleDir && options.virtualModuleDir.includes("/")) throw createModuleFederationError(`Invalid virtualModuleDir: "${options.virtualModuleDir}". The virtualModuleDir option cannot contain slashes (/). Please use a single directory name like '__mf__virtual__your_app_name'.`);
|
|
518
|
-
|
|
518
|
+
const normalized = {
|
|
519
519
|
exposes: normalizeExposes(options.exposes),
|
|
520
520
|
filename: options.filename || "remoteEntry-[hash]",
|
|
521
521
|
internalName: toInternalModuleFederationName(options.name),
|
|
@@ -546,6 +546,8 @@ function normalizeModuleFederationOptions(options) {
|
|
|
546
546
|
varFilename: options.varFilename,
|
|
547
547
|
target: options.target
|
|
548
548
|
};
|
|
549
|
+
explicitSharedKeysByOptions.set(normalized, new Set(explicitSharedKeys));
|
|
550
|
+
return config = normalized;
|
|
549
551
|
}
|
|
550
552
|
//#endregion
|
|
551
553
|
//#region src/utils/VirtualModule.ts
|
|
@@ -575,7 +577,7 @@ function decodeViteId(id) {
|
|
|
575
577
|
return viteId.startsWith("__x00__") ? `\0${viteId.slice(7)}` : viteId;
|
|
576
578
|
}
|
|
577
579
|
function assertModuleFound(tag, str = "") {
|
|
578
|
-
const module = VirtualModule.findModule(tag, str);
|
|
580
|
+
const module = VirtualModule.findById(str) ?? VirtualModule.findModule(tag, str);
|
|
579
581
|
if (!module) throw createModuleFederationError(`Module Federation shared module '${str}' not found. Please ensure it's installed as a dependency in your package.json.`);
|
|
580
582
|
return module;
|
|
581
583
|
}
|
|
@@ -594,6 +596,7 @@ var VirtualModule = class VirtualModule {
|
|
|
594
596
|
code;
|
|
595
597
|
importId;
|
|
596
598
|
importIdKey;
|
|
599
|
+
scopeName;
|
|
597
600
|
static findName(tag, str = "") {
|
|
598
601
|
if (!patternMap[tag]) patternMap[tag] = new RegExp(`(.*${packageNameEncode(tag)}(.+?)${packageNameEncode(tag)}.*)`);
|
|
599
602
|
const moduleName = (normalizeVirtualModuleId(str).match(patternMap[tag]) || [])[2];
|
|
@@ -607,16 +610,16 @@ var VirtualModule = class VirtualModule {
|
|
|
607
610
|
const normalized = normalizeVirtualModuleId(id);
|
|
608
611
|
return normalized.startsWith("virtual:mf:") ? idCacheMap[normalized] : void 0;
|
|
609
612
|
}
|
|
610
|
-
constructor(name, tag = "__mf_v__", suffix = "") {
|
|
613
|
+
constructor(name, tag = "__mf_v__", suffix = "", scopeName) {
|
|
611
614
|
this.name = name;
|
|
612
615
|
this.tag = tag;
|
|
613
616
|
this.suffix = suffix || getSuffix(name);
|
|
617
|
+
this.scopeName = scopeName;
|
|
614
618
|
if (!cacheMap[this.tag]) cacheMap[this.tag] = {};
|
|
615
619
|
cacheMap[this.tag][this.name] = this;
|
|
616
620
|
}
|
|
617
621
|
getImportId() {
|
|
618
|
-
const
|
|
619
|
-
const importIdKey = `${mfName}${this.tag}${this.name}${this.tag}`;
|
|
622
|
+
const importIdKey = `${this.scopeName ?? getNormalizeModuleFederationOptions().internalName}${this.tag}${this.name}${this.tag}`;
|
|
620
623
|
if (this.importId && this.importIdKey === importIdKey) return this.importId;
|
|
621
624
|
if (this.importId) delete idCacheMap[this.importId];
|
|
622
625
|
this.importIdKey = importIdKey;
|
|
@@ -774,7 +777,7 @@ function generateExposes(options, remoteDependencyMap = {}, command = "build") {
|
|
|
774
777
|
export default {
|
|
775
778
|
${Object.keys(options.exposes).map((key) => {
|
|
776
779
|
const remoteDependencyPreloads = (remoteDependencyMap[key] ?? []).map((remoteId) => {
|
|
777
|
-
const virtualRemote = getRemoteVirtualModule(remoteId, command);
|
|
780
|
+
const virtualRemote = getRemoteVirtualModule(remoteId, command, false, "unified", options);
|
|
778
781
|
return `import(${JSON.stringify(virtualRemote.getImportId())})
|
|
779
782
|
.then((mod) => mod.__mf_remote_pending)`;
|
|
780
783
|
}).join(",");
|
|
@@ -805,9 +808,40 @@ function generateExposes(options, remoteDependencyMap = {}, command = "build") {
|
|
|
805
808
|
//#endregion
|
|
806
809
|
//#region src/virtualModules/virtualRuntimeInitStatus.ts
|
|
807
810
|
const virtualRuntimeInitStatus = new VirtualModule("runtimeInit");
|
|
811
|
+
const runtimeInitModules = /* @__PURE__ */ new WeakMap();
|
|
812
|
+
const runtimeInitOwnerIds = /* @__PURE__ */ new WeakMap();
|
|
813
|
+
let nextRuntimeInitOwnerId = 1;
|
|
808
814
|
const MODULE_CACHE_GLOBAL_KEY = "__mf_module_cache__";
|
|
809
|
-
function
|
|
810
|
-
|
|
815
|
+
function getRuntimeInitOwnerId(options) {
|
|
816
|
+
let ownerId = runtimeInitOwnerIds.get(options);
|
|
817
|
+
if (!ownerId) {
|
|
818
|
+
ownerId = nextRuntimeInitOwnerId++;
|
|
819
|
+
runtimeInitOwnerIds.set(options, ownerId);
|
|
820
|
+
}
|
|
821
|
+
return ownerId;
|
|
822
|
+
}
|
|
823
|
+
function getRuntimeInitModule(options) {
|
|
824
|
+
if (!options) return virtualRuntimeInitStatus;
|
|
825
|
+
let runtimeInitModule = runtimeInitModules.get(options);
|
|
826
|
+
if (!runtimeInitModule) {
|
|
827
|
+
const ownerId = getRuntimeInitOwnerId(options);
|
|
828
|
+
runtimeInitModule = new VirtualModule("runtimeInit", "__mf_v__", "", `${options.internalName}__mf_owner__${ownerId}`);
|
|
829
|
+
runtimeInitModules.set(options, runtimeInitModule);
|
|
830
|
+
}
|
|
831
|
+
return runtimeInitModule;
|
|
832
|
+
}
|
|
833
|
+
function getRuntimeInitStatusImportId(options) {
|
|
834
|
+
return getRuntimeInitModule(options).getImportId();
|
|
835
|
+
}
|
|
836
|
+
function getRuntimeRemoteCachePrefix(options) {
|
|
837
|
+
return options ? `${getRuntimeInitStatusImportId(options)}::` : "";
|
|
838
|
+
}
|
|
839
|
+
function getRuntimeRemoteAlias(alias, options) {
|
|
840
|
+
if (!options) return alias;
|
|
841
|
+
return `${options.internalName}__mf_owner__${getRuntimeInitOwnerId(options)}__${alias}`;
|
|
842
|
+
}
|
|
843
|
+
function getRuntimeInitGlobalKey(ownerImportId) {
|
|
844
|
+
return `__mf_init__${ownerImportId ?? virtualRuntimeInitStatus.getImportId()}__`;
|
|
811
845
|
}
|
|
812
846
|
function getDeferredInitPromiseCode() {
|
|
813
847
|
return `let initResolve, initReject;
|
|
@@ -817,10 +851,7 @@ function getDeferredInitPromiseCode() {
|
|
|
817
851
|
});`;
|
|
818
852
|
}
|
|
819
853
|
let _ssrRemotes = [];
|
|
820
|
-
function
|
|
821
|
-
_ssrRemotes = remotes;
|
|
822
|
-
}
|
|
823
|
-
function getSsrNoopResolveCode(enableSsrInit, hostInitImportId, initResolveExpression = "initResolve") {
|
|
854
|
+
function getSsrNoopResolveCode(enableSsrInit, hostInitImportId, initResolveExpression = "initResolve", ssrRemotes = _ssrRemotes) {
|
|
824
855
|
if (!enableSsrInit) return "";
|
|
825
856
|
return `if (${SERVER_ENV_GUARD}) {
|
|
826
857
|
var _noop = { loadRemote: function() { return Promise.resolve(undefined); }, loadShare: function() { return Promise.resolve(undefined); } };
|
|
@@ -840,7 +871,7 @@ function getSsrNoopResolveCode(enableSsrInit, hostInitImportId, initResolveExpre
|
|
|
840
871
|
function() { return [runtimeMod, []]; }
|
|
841
872
|
);
|
|
842
873
|
}).then(function(pair) {
|
|
843
|
-
var runtime = pair[0].init({ name: '__mf_ssr_host__', remotes: ${JSON.stringify(
|
|
874
|
+
var runtime = pair[0].init({ name: '__mf_ssr_host__', remotes: ${JSON.stringify(ssrRemotes)}, shared: {}, plugins: pair[1] });
|
|
844
875
|
${initResolveExpression}(runtime);
|
|
845
876
|
}, function() {
|
|
846
877
|
${initResolveExpression}(_noop);
|
|
@@ -850,7 +881,7 @@ function getSsrNoopResolveCode(enableSsrInit, hostInitImportId, initResolveExpre
|
|
|
850
881
|
}
|
|
851
882
|
function getRuntimeInitStateBootstrapCode(options) {
|
|
852
883
|
return `
|
|
853
|
-
const ${options.globalKeyVar} = ${JSON.stringify(getRuntimeInitGlobalKey())};
|
|
884
|
+
const ${options.globalKeyVar} = ${JSON.stringify(getRuntimeInitGlobalKey(options.ownerImportId))};
|
|
854
885
|
let ${options.stateVar} = globalThis[${options.globalKeyVar}];
|
|
855
886
|
if (!${options.stateVar}) {
|
|
856
887
|
${getDeferredInitPromiseCode()}
|
|
@@ -859,14 +890,14 @@ if (!${options.stateVar}) {
|
|
|
859
890
|
initResolve,
|
|
860
891
|
initReject,
|
|
861
892
|
};
|
|
862
|
-
${getSsrNoopResolveCode(options.enableSsrInit)}
|
|
893
|
+
${getSsrNoopResolveCode(options.enableSsrInit, options.hostInitImportId, "initResolve", options.ssrRemotes)}
|
|
863
894
|
}
|
|
864
895
|
const ${options.exposedConst} = ${options.stateVar}.${options.exposedProperty};
|
|
865
896
|
`;
|
|
866
897
|
}
|
|
867
|
-
function getRuntimeInitBootstrapCode(enableSsrInit = false, hostInitImportId) {
|
|
898
|
+
function getRuntimeInitBootstrapCode(enableSsrInit = false, ownerImportId, ssrRemotes, hostInitImportId = ownerImportId) {
|
|
868
899
|
return `
|
|
869
|
-
const globalKey = ${JSON.stringify(getRuntimeInitGlobalKey())};
|
|
900
|
+
const globalKey = ${JSON.stringify(getRuntimeInitGlobalKey(ownerImportId))};
|
|
870
901
|
const moduleCacheGlobalKey = ${JSON.stringify(MODULE_CACHE_GLOBAL_KEY)};
|
|
871
902
|
globalThis[moduleCacheGlobalKey] ||= { share: {}, remote: {} };
|
|
872
903
|
globalThis[moduleCacheGlobalKey].share ||= {};
|
|
@@ -883,7 +914,7 @@ globalThis[globalKey] = {
|
|
|
883
914
|
${enableSsrInit ? `
|
|
884
915
|
if (${SERVER_ENV_GUARD} && !globalThis[globalKey].ssrInitStarted) {
|
|
885
916
|
globalThis[globalKey].ssrInitStarted = true;
|
|
886
|
-
${getSsrNoopResolveCode(enableSsrInit, hostInitImportId, "globalThis[globalKey].initResolve")}
|
|
917
|
+
${getSsrNoopResolveCode(enableSsrInit, hostInitImportId, "globalThis[globalKey].initResolve", ssrRemotes)}
|
|
887
918
|
}` : ""}
|
|
888
919
|
globalThis[globalKey].moduleCache ||= globalThis[moduleCacheGlobalKey];
|
|
889
920
|
globalThis[globalKey].moduleCache.share ||= {};
|
|
@@ -912,29 +943,36 @@ for (const __mfShareKey of Object.keys(__mfModuleCache.share)) {
|
|
|
912
943
|
}
|
|
913
944
|
`;
|
|
914
945
|
}
|
|
915
|
-
function getRuntimeInitPromiseBootstrapCode(enableSsrInit = false) {
|
|
946
|
+
function getRuntimeInitPromiseBootstrapCode(enableSsrInit = false, ownerImportId, ssrRemotes, hostInitImportId = ownerImportId) {
|
|
916
947
|
return getRuntimeInitStateBootstrapCode({
|
|
917
948
|
globalKeyVar: "__mfPromiseGlobalKey",
|
|
918
949
|
stateVar: "__mfPromiseState",
|
|
919
950
|
exposedConst: "initPromise",
|
|
920
951
|
exposedProperty: "initPromise",
|
|
921
|
-
enableSsrInit
|
|
952
|
+
enableSsrInit,
|
|
953
|
+
ownerImportId,
|
|
954
|
+
hostInitImportId,
|
|
955
|
+
ssrRemotes
|
|
922
956
|
});
|
|
923
957
|
}
|
|
924
|
-
function getRuntimeInitResolveBootstrapCode(enableSsrInit = false) {
|
|
958
|
+
function getRuntimeInitResolveBootstrapCode(enableSsrInit = false, ownerImportId, ssrRemotes, hostInitImportId = ownerImportId) {
|
|
925
959
|
return getRuntimeInitStateBootstrapCode({
|
|
926
960
|
globalKeyVar: "__mfResolveGlobalKey",
|
|
927
961
|
stateVar: "__mfResolveState",
|
|
928
962
|
exposedConst: "initResolve",
|
|
929
963
|
exposedProperty: "initResolve",
|
|
930
|
-
enableSsrInit
|
|
964
|
+
enableSsrInit,
|
|
965
|
+
ownerImportId,
|
|
966
|
+
hostInitImportId,
|
|
967
|
+
ssrRemotes
|
|
931
968
|
});
|
|
932
969
|
}
|
|
933
|
-
function writeRuntimeInitStatus(command, enableSsrInit = false, hostInitImportId) {
|
|
970
|
+
function writeRuntimeInitStatus(command, enableSsrInit = false, hostInitImportId, options, ssrRemotes = _ssrRemotes) {
|
|
934
971
|
const exportStatement = command === "build" ? `const { initPromise, initResolve, initReject, moduleCache } = globalThis[globalKey];
|
|
935
972
|
export { initPromise, initResolve, initReject, moduleCache };` : `module.exports = globalThis[globalKey];`;
|
|
936
|
-
|
|
937
|
-
|
|
973
|
+
const ownerImportId = options ? getRuntimeInitStatusImportId(options) : hostInitImportId;
|
|
974
|
+
getRuntimeInitModule(options).writeSync(`
|
|
975
|
+
${getRuntimeInitBootstrapCode(enableSsrInit, ownerImportId, ssrRemotes, hostInitImportId)}
|
|
938
976
|
${exportStatement}
|
|
939
977
|
`);
|
|
940
978
|
}
|
|
@@ -1079,25 +1117,35 @@ function createCodePositionMap(code) {
|
|
|
1079
1117
|
}
|
|
1080
1118
|
//#endregion
|
|
1081
1119
|
//#region src/utils/treeShaking.ts
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
let
|
|
1090
|
-
|
|
1091
|
-
|
|
1120
|
+
const legacyTreeShakingState = {
|
|
1121
|
+
inferredUsage: /* @__PURE__ */ new Map(),
|
|
1122
|
+
buildMode: false
|
|
1123
|
+
};
|
|
1124
|
+
const treeShakingStates = /* @__PURE__ */ new WeakMap();
|
|
1125
|
+
function getTreeShakingState(options) {
|
|
1126
|
+
if (!options) return legacyTreeShakingState;
|
|
1127
|
+
let state = treeShakingStates.get(options);
|
|
1128
|
+
if (!state) {
|
|
1129
|
+
state = {
|
|
1130
|
+
inferredUsage: /* @__PURE__ */ new Map(),
|
|
1131
|
+
buildMode: false
|
|
1132
|
+
};
|
|
1133
|
+
treeShakingStates.set(options, state);
|
|
1134
|
+
}
|
|
1135
|
+
return state;
|
|
1136
|
+
}
|
|
1137
|
+
function setTreeShakingBuildMode(enabled, options) {
|
|
1138
|
+
getTreeShakingState(options).buildMode = enabled;
|
|
1092
1139
|
}
|
|
1093
|
-
function resetTreeShakingExports() {
|
|
1094
|
-
|
|
1140
|
+
function resetTreeShakingExports(options) {
|
|
1141
|
+
getTreeShakingState(options).inferredUsage.clear();
|
|
1095
1142
|
}
|
|
1096
|
-
function getOrCreateExportRecord(sharedKey, request) {
|
|
1097
|
-
|
|
1143
|
+
function getOrCreateExportRecord(sharedKey, request, options) {
|
|
1144
|
+
const inferredUsage = getTreeShakingState(options).inferredUsage;
|
|
1145
|
+
let byRequest = inferredUsage.get(sharedKey);
|
|
1098
1146
|
if (!byRequest) {
|
|
1099
1147
|
byRequest = /* @__PURE__ */ new Map();
|
|
1100
|
-
|
|
1148
|
+
inferredUsage.set(sharedKey, byRequest);
|
|
1101
1149
|
}
|
|
1102
1150
|
let record = byRequest.get(request);
|
|
1103
1151
|
if (!record) {
|
|
@@ -1109,22 +1157,23 @@ function getOrCreateExportRecord(sharedKey, request) {
|
|
|
1109
1157
|
}
|
|
1110
1158
|
return record;
|
|
1111
1159
|
}
|
|
1112
|
-
function recordTreeShakingExports(sharedKey, exports, request = sharedKey) {
|
|
1113
|
-
const record = getOrCreateExportRecord(sharedKey, request);
|
|
1160
|
+
function recordTreeShakingExports(sharedKey, exports, request = sharedKey, options) {
|
|
1161
|
+
const record = getOrCreateExportRecord(sharedKey, request, options);
|
|
1114
1162
|
exports.forEach((name) => record.usedExports.add(name));
|
|
1115
1163
|
}
|
|
1116
|
-
function markTreeShakingPackageUnsafe(sharedKey, request = sharedKey) {
|
|
1117
|
-
getOrCreateExportRecord(sharedKey, request).requiresFullBundle = true;
|
|
1164
|
+
function markTreeShakingPackageUnsafe(sharedKey, request = sharedKey, options) {
|
|
1165
|
+
getOrCreateExportRecord(sharedKey, request, options).requiresFullBundle = true;
|
|
1118
1166
|
}
|
|
1119
|
-
function getExportRecords(sharedKey, request) {
|
|
1167
|
+
function getExportRecords(sharedKey, request, options) {
|
|
1168
|
+
const inferredUsage = getTreeShakingState(options).inferredUsage;
|
|
1120
1169
|
if (sharedKey) {
|
|
1121
|
-
const records =
|
|
1170
|
+
const records = inferredUsage.get(sharedKey);
|
|
1122
1171
|
const wildcard = records?.get("*");
|
|
1123
1172
|
const exact = records?.get(request);
|
|
1124
1173
|
return [wildcard, exact === wildcard ? void 0 : exact].filter((record) => !!record);
|
|
1125
1174
|
}
|
|
1126
1175
|
const records = [];
|
|
1127
|
-
|
|
1176
|
+
inferredUsage.forEach((byRequest, configuredKey) => {
|
|
1128
1177
|
const wildcard = byRequest.get("*");
|
|
1129
1178
|
const exact = byRequest.get(request);
|
|
1130
1179
|
const keyBase = configuredKey.endsWith("/") ? configuredKey.slice(0, -1) : configuredKey;
|
|
@@ -1141,10 +1190,10 @@ function getExportRecords(sharedKey, request) {
|
|
|
1141
1190
|
* fallback lookup across keys keeps aliases/backwards-compatible callers
|
|
1142
1191
|
* working, while still keeping each concrete request's exports isolated.
|
|
1143
1192
|
*/
|
|
1144
|
-
function getTreeShakingExportUsage(request, shareItem, sharedKey) {
|
|
1193
|
+
function getTreeShakingExportUsage(request, shareItem, sharedKey, options) {
|
|
1145
1194
|
const treeShaking = shareItem?.shareConfig.treeShaking;
|
|
1146
|
-
if (!treeShaking || !
|
|
1147
|
-
const records = getExportRecords(sharedKey, request);
|
|
1195
|
+
if (!treeShaking || !getTreeShakingState(options).buildMode) return void 0;
|
|
1196
|
+
const records = getExportRecords(sharedKey, request, options);
|
|
1148
1197
|
if (records.some((record) => record.requiresFullBundle)) return { kind: "full" };
|
|
1149
1198
|
const configured = treeShaking.usedExports ?? [];
|
|
1150
1199
|
const result = new Set(configured);
|
|
@@ -1661,7 +1710,7 @@ function getNamedExportsViaRegex(source, filePath, visited, scanState = { comple
|
|
|
1661
1710
|
}
|
|
1662
1711
|
const name = asMatch[1];
|
|
1663
1712
|
if (isValidEsmExportName(name)) names.add(name);
|
|
1664
|
-
else scanState.complete = false;
|
|
1713
|
+
else if (name === "default" || name === "__esModule") {} else scanState.complete = false;
|
|
1665
1714
|
}
|
|
1666
1715
|
}
|
|
1667
1716
|
const namespaceReExportRegex = new RegExp(`export\\s+\\*\\s+as\\s+(${JS_IDENTIFIER_PATTERN})\\s+from\\s+['"][^'"]+['"]`, "gu");
|
|
@@ -1852,8 +1901,8 @@ function getDependencyNames(packageJson) {
|
|
|
1852
1901
|
}
|
|
1853
1902
|
return Array.from(names);
|
|
1854
1903
|
}
|
|
1855
|
-
function isSharedSingletonConsumedByPeer(pkg) {
|
|
1856
|
-
const shared =
|
|
1904
|
+
function isSharedSingletonConsumedByPeer(pkg, options = getNormalizeModuleFederationOptions()) {
|
|
1905
|
+
const shared = options?.shared || {};
|
|
1857
1906
|
if (Object.entries(shared).some(([key, item]) => key !== pkg && key.startsWith(`${pkg}/`) && item.shareConfig.singleton === true)) return true;
|
|
1858
1907
|
const sharedKeyByPackageName = /* @__PURE__ */ new Map();
|
|
1859
1908
|
Object.entries(shared).filter(([, item]) => item.shareConfig.singleton === true).forEach(([key]) => {
|
|
@@ -1874,8 +1923,7 @@ function isSharedSingletonConsumedByPeer(pkg) {
|
|
|
1874
1923
|
};
|
|
1875
1924
|
return Array.from(sharedKeyByPackageName.values()).some((sharedPkg) => sharedPkg !== pkg && reachesPkg(sharedPkg, new Set([sharedPkg])));
|
|
1876
1925
|
}
|
|
1877
|
-
function isRemoteOnlyContainer() {
|
|
1878
|
-
const options = getNormalizeModuleFederationOptions();
|
|
1926
|
+
function isRemoteOnlyContainer(options = getNormalizeModuleFederationOptions()) {
|
|
1879
1927
|
return Object.keys(options.exposes || {}).length > 0 && Object.keys(options.remotes || {}).length === 0;
|
|
1880
1928
|
}
|
|
1881
1929
|
function tryResolveImportFromPackageRoot(pkg, root) {
|
|
@@ -1898,13 +1946,42 @@ function getConcreteSharedImportSource(pkg, shareItem) {
|
|
|
1898
1946
|
}
|
|
1899
1947
|
return tryResolveImportFromPackageRoot(pkg, currentDir);
|
|
1900
1948
|
}
|
|
1901
|
-
const preBuildCacheMap = {};
|
|
1902
|
-
const preBuildShareItemMap = {};
|
|
1903
1949
|
const PREBUILD_TAG = "__prebuild__";
|
|
1904
|
-
const treeShakingProviderCacheMap = {};
|
|
1905
|
-
const materializedTreeShakingProviders = /* @__PURE__ */ new Set();
|
|
1906
1950
|
const TREE_SHAKING_PROVIDER_TAG = "__treeShakingProvider__";
|
|
1907
1951
|
const TREE_SHAKING_GRAPH_QUERY = "__mf_tree_shaking_graph__";
|
|
1952
|
+
const legacySharedVirtualModuleState = {
|
|
1953
|
+
preBuildCacheMap: {},
|
|
1954
|
+
preBuildShareItemMap: {},
|
|
1955
|
+
treeShakingProviderCacheMap: {},
|
|
1956
|
+
materializedTreeShakingProviders: /* @__PURE__ */ new Set(),
|
|
1957
|
+
loadShareCacheMap: {}
|
|
1958
|
+
};
|
|
1959
|
+
const sharedVirtualModuleStates = /* @__PURE__ */ new WeakMap();
|
|
1960
|
+
let nextSharedVirtualModuleOwnerId = 1;
|
|
1961
|
+
function getSharedVirtualModuleState(options) {
|
|
1962
|
+
if (!options) try {
|
|
1963
|
+
const currentOptions = getNormalizeModuleFederationOptions();
|
|
1964
|
+
return sharedVirtualModuleStates.get(currentOptions) ?? legacySharedVirtualModuleState;
|
|
1965
|
+
} catch {
|
|
1966
|
+
return legacySharedVirtualModuleState;
|
|
1967
|
+
}
|
|
1968
|
+
let state = sharedVirtualModuleStates.get(options);
|
|
1969
|
+
if (!state) {
|
|
1970
|
+
state = {
|
|
1971
|
+
preBuildCacheMap: {},
|
|
1972
|
+
preBuildShareItemMap: {},
|
|
1973
|
+
treeShakingProviderCacheMap: {},
|
|
1974
|
+
materializedTreeShakingProviders: /* @__PURE__ */ new Set(),
|
|
1975
|
+
loadShareCacheMap: {},
|
|
1976
|
+
ownerKey: `${options.internalName}__mf_owner__${nextSharedVirtualModuleOwnerId++}`
|
|
1977
|
+
};
|
|
1978
|
+
sharedVirtualModuleStates.set(options, state);
|
|
1979
|
+
}
|
|
1980
|
+
return state;
|
|
1981
|
+
}
|
|
1982
|
+
function createScopedSharedVirtualModule(pkg, tag, options) {
|
|
1983
|
+
return new VirtualModule(pkg, tag, ".js", getSharedVirtualModuleState(options).ownerKey);
|
|
1984
|
+
}
|
|
1908
1985
|
function getTreeShakingGraphToken(id) {
|
|
1909
1986
|
if (!id) return void 0;
|
|
1910
1987
|
const queryStart = id.indexOf("?");
|
|
@@ -1935,19 +2012,21 @@ function addTreeShakingGraphQuery(id, token) {
|
|
|
1935
2012
|
const hash = hashStart === -1 ? "" : cleanId.slice(hashStart);
|
|
1936
2013
|
return `${base}${base.includes("?") ? "&" : "?"}${TREE_SHAKING_GRAPH_QUERY}=${encodeURIComponent(token)}${hash}`;
|
|
1937
2014
|
}
|
|
1938
|
-
function getConcreteTreeShakingExportUsage(pkg, shareItem) {
|
|
1939
|
-
return getTreeShakingExportUsage(pkg, shareItem, shareItem?.name);
|
|
2015
|
+
function getConcreteTreeShakingExportUsage(pkg, shareItem, options) {
|
|
2016
|
+
return getTreeShakingExportUsage(pkg, shareItem, shareItem?.name, options);
|
|
1940
2017
|
}
|
|
1941
|
-
function getTreeShakingSharedProviderName(pkg) {
|
|
1942
|
-
const
|
|
1943
|
-
return `${internalName
|
|
2018
|
+
function getTreeShakingSharedProviderName(pkg, options) {
|
|
2019
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
2020
|
+
return `${getSharedVirtualModuleState(options).ownerKey ?? resolvedOptions.internalName ?? resolvedOptions.name}__tree_shaking__${packageNameEncode(pkg)}`;
|
|
1944
2021
|
}
|
|
1945
|
-
function getTreeShakingSharedProviderImportId(pkg) {
|
|
1946
|
-
|
|
2022
|
+
function getTreeShakingSharedProviderImportId(pkg, options) {
|
|
2023
|
+
const { treeShakingProviderCacheMap } = getSharedVirtualModuleState(options);
|
|
2024
|
+
if (!treeShakingProviderCacheMap[pkg]) treeShakingProviderCacheMap[pkg] = createScopedSharedVirtualModule(pkg, TREE_SHAKING_PROVIDER_TAG, options);
|
|
1947
2025
|
return treeShakingProviderCacheMap[pkg].getImportId();
|
|
1948
2026
|
}
|
|
1949
|
-
function hasTreeShakingSharedProvider(pkg, shareItem) {
|
|
1950
|
-
const
|
|
2027
|
+
function hasTreeShakingSharedProvider(pkg, shareItem, options) {
|
|
2028
|
+
const { materializedTreeShakingProviders } = getSharedVirtualModuleState(options);
|
|
2029
|
+
const usage = getConcreteTreeShakingExportUsage(pkg, shareItem, options);
|
|
1951
2030
|
return materializedTreeShakingProviders.has(pkg) && usage?.kind === "exports";
|
|
1952
2031
|
}
|
|
1953
2032
|
/**
|
|
@@ -1959,8 +2038,9 @@ function hasTreeShakingSharedProvider(pkg, shareItem) {
|
|
|
1959
2038
|
* perform its normal usedExports compatibility check and safely choose the full
|
|
1960
2039
|
* provider when the optimized one is insufficient.
|
|
1961
2040
|
*/
|
|
1962
|
-
function writeTreeShakingSharedProvider(pkg, shareItem) {
|
|
1963
|
-
const
|
|
2041
|
+
function writeTreeShakingSharedProvider(pkg, shareItem, options) {
|
|
2042
|
+
const { materializedTreeShakingProviders, treeShakingProviderCacheMap } = getSharedVirtualModuleState(options);
|
|
2043
|
+
const usage = getConcreteTreeShakingExportUsage(pkg, shareItem, options);
|
|
1964
2044
|
if (usage?.kind !== "exports" || !usage.usedExports.length || shareItem?.shareConfig.import === false) {
|
|
1965
2045
|
materializedTreeShakingProviders.delete(pkg);
|
|
1966
2046
|
return;
|
|
@@ -1972,7 +2052,7 @@ function writeTreeShakingSharedProvider(pkg, shareItem) {
|
|
|
1972
2052
|
mfWarn(`Tree-shaking shared dependency "${pkg}" was disabled because export "${unsupportedExport}" cannot be represented by the generated ESM provider.`);
|
|
1973
2053
|
return;
|
|
1974
2054
|
}
|
|
1975
|
-
const provider = treeShakingProviderCacheMap[pkg] || (treeShakingProviderCacheMap[pkg] =
|
|
2055
|
+
const provider = treeShakingProviderCacheMap[pkg] || (treeShakingProviderCacheMap[pkg] = createScopedSharedVirtualModule(pkg, "__treeShakingProvider__", options));
|
|
1976
2056
|
const optimizedImportSource = addTreeShakingGraphQuery(getConcreteSharedImportSource(pkg, shareItem) || pkg, pkg);
|
|
1977
2057
|
const namedExports = usedExports.filter((name) => name !== "default");
|
|
1978
2058
|
const namedImports = namedExports.map((name, index) => `${name} as __mfTreeShaken_${index}`).join(", ");
|
|
@@ -1994,11 +2074,12 @@ export default { get, init };
|
|
|
1994
2074
|
`, true);
|
|
1995
2075
|
materializedTreeShakingProviders.add(pkg);
|
|
1996
2076
|
}
|
|
1997
|
-
function writePreBuildLibPath(pkg, shareItem) {
|
|
1998
|
-
|
|
2077
|
+
function writePreBuildLibPath(pkg, shareItem, options) {
|
|
2078
|
+
const { preBuildCacheMap, preBuildShareItemMap } = getSharedVirtualModuleState(options);
|
|
2079
|
+
if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = createScopedSharedVirtualModule(pkg, PREBUILD_TAG, options);
|
|
1999
2080
|
preBuildShareItemMap[pkg] = shareItem;
|
|
2000
2081
|
const importSource = getConcreteSharedImportSource(pkg, shareItem) || pkg;
|
|
2001
|
-
writeTreeShakingSharedProvider(pkg, shareItem);
|
|
2082
|
+
writeTreeShakingSharedProvider(pkg, shareItem, options);
|
|
2002
2083
|
if (pkg === "react/compiler-runtime") {
|
|
2003
2084
|
const reactCacheDescriptor = getSharedCacheDescriptorLiteral("react", shareItem ?? {
|
|
2004
2085
|
name: "react",
|
|
@@ -2067,36 +2148,36 @@ function writePreBuildLibPath(pkg, shareItem) {
|
|
|
2067
2148
|
`, true);
|
|
2068
2149
|
}
|
|
2069
2150
|
/** Re-render already materialized wrappers after import analysis discovers exports. */
|
|
2070
|
-
function refreshTreeShakingModules() {
|
|
2151
|
+
function refreshTreeShakingModules(options) {
|
|
2152
|
+
const { preBuildShareItemMap } = getSharedVirtualModuleState(options);
|
|
2071
2153
|
for (const [pkg, shareItem] of Object.entries(preBuildShareItemMap)) {
|
|
2072
2154
|
if (!shareItem?.shareConfig.treeShaking) continue;
|
|
2073
|
-
writePreBuildLibPath(pkg, shareItem);
|
|
2074
|
-
writeLoadShareModule(pkg, shareItem, "build", false);
|
|
2155
|
+
writePreBuildLibPath(pkg, shareItem, options);
|
|
2156
|
+
writeLoadShareModule(pkg, shareItem, "build", false, options);
|
|
2075
2157
|
}
|
|
2076
2158
|
}
|
|
2077
|
-
function getPreBuildLibImportId(pkg) {
|
|
2078
|
-
|
|
2159
|
+
function getPreBuildLibImportId(pkg, options) {
|
|
2160
|
+
const { preBuildCacheMap } = getSharedVirtualModuleState(options);
|
|
2161
|
+
if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = createScopedSharedVirtualModule(pkg, PREBUILD_TAG, options);
|
|
2079
2162
|
return preBuildCacheMap[pkg].getImportId();
|
|
2080
2163
|
}
|
|
2081
|
-
function getPreBuildShareItem(pkg) {
|
|
2082
|
-
return preBuildShareItemMap[pkg];
|
|
2164
|
+
function getPreBuildShareItem(pkg, options) {
|
|
2165
|
+
return getSharedVirtualModuleState(options).preBuildShareItemMap[pkg];
|
|
2083
2166
|
}
|
|
2084
|
-
function getSharedImportSource(pkg, shareItem) {
|
|
2085
|
-
return getConcreteSharedImportSource(pkg, shareItem) || getPreBuildLibImportId(pkg);
|
|
2167
|
+
function getSharedImportSource(pkg, shareItem, options) {
|
|
2168
|
+
return getConcreteSharedImportSource(pkg, shareItem) || getPreBuildLibImportId(pkg, options);
|
|
2086
2169
|
}
|
|
2087
2170
|
const LOAD_SHARE_TAG = "__loadShare__";
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] =
|
|
2171
|
+
function getLoadShareImportId(pkg, _isRolldown, options) {
|
|
2172
|
+
const { loadShareCacheMap } = getSharedVirtualModuleState(options);
|
|
2173
|
+
if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] = createScopedSharedVirtualModule(pkg, LOAD_SHARE_TAG, options);
|
|
2091
2174
|
return loadShareCacheMap[pkg].getImportId();
|
|
2092
2175
|
}
|
|
2093
|
-
function getLoadShareModulePath(pkg, isRolldown) {
|
|
2094
|
-
|
|
2176
|
+
function getLoadShareModulePath(pkg, isRolldown, options) {
|
|
2177
|
+
const { loadShareCacheMap } = getSharedVirtualModuleState(options);
|
|
2178
|
+
if (!loadShareCacheMap[pkg]) getLoadShareImportId(pkg, isRolldown, options);
|
|
2095
2179
|
return loadShareCacheMap[pkg].getImportId();
|
|
2096
2180
|
}
|
|
2097
|
-
function toViteOptimizedDepVirtualId(id) {
|
|
2098
|
-
return toViteEncodedId(id);
|
|
2099
|
-
}
|
|
2100
2181
|
function getCachedLoadSharePkg(id) {
|
|
2101
2182
|
if (!id.includes("__loadShare__")) return;
|
|
2102
2183
|
const normalized = normalizeVirtualModuleId(id);
|
|
@@ -2114,8 +2195,8 @@ function materializeCachedLoadShareModule(options) {
|
|
|
2114
2195
|
const key = options.findSharedKey(pkg, options.shared);
|
|
2115
2196
|
if (!key) return;
|
|
2116
2197
|
const shareItem = options.shared[key];
|
|
2117
|
-
writeLoadShareModule(pkg, shareItem, options.command, options.isRolldown);
|
|
2118
|
-
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(pkg, shareItem);
|
|
2198
|
+
writeLoadShareModule(pkg, shareItem, options.command, options.isRolldown, options.federationOptions);
|
|
2199
|
+
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(pkg, shareItem, options.federationOptions);
|
|
2119
2200
|
options.addUsedShares(pkg);
|
|
2120
2201
|
options.writeLocalSharedImportMap();
|
|
2121
2202
|
}
|
|
@@ -2184,7 +2265,14 @@ const WORKSPACE_SINGLETON_SSR_LOCAL_SHARE = "__mfNormalizeShareModule(__mfLocalS
|
|
|
2184
2265
|
function prependWorkspaceSingletonSsrImport(code) {
|
|
2185
2266
|
if (!code.includes("if (import.meta.env.SSR)")) return code;
|
|
2186
2267
|
if (!code.includes(WORKSPACE_SINGLETON_SSR_LOCAL_SHARE)) return code;
|
|
2187
|
-
|
|
2268
|
+
const localShareImport = /^[ \t]*import\s+\*\s+as\s+__mfLocalShare\s+from\s+(['"])(.+?)\1\s*;?[ \t]*\r?\n?/gm;
|
|
2269
|
+
let hasLocalShareImport = false;
|
|
2270
|
+
code = code.replace(localShareImport, (statement) => {
|
|
2271
|
+
if (hasLocalShareImport) return "";
|
|
2272
|
+
hasLocalShareImport = true;
|
|
2273
|
+
return statement;
|
|
2274
|
+
});
|
|
2275
|
+
if (hasLocalShareImport) return code;
|
|
2188
2276
|
const importMatch = code.match(/initPromise\.then\(\(\)\s*=>\s*\{[\s\S]*?\breturn import\((["'])(.+?)\1\)\.then\(\(mod\)\s*=>\s*\{[\s\S]*?__mfApplyLazyShareExports/) ?? code.match(/initPromise\.then\(\(\)\s*=>\s*\n\s*import\((["'])(.+?)\1\)\.then\(\(mod\)\s*=>\s*\{[\s\S]*?__mfApplyLazyShareExports/) ?? code.match(/import\((["'])(.+?)\1\)/);
|
|
2189
2277
|
if (!importMatch) return code;
|
|
2190
2278
|
const quote = importMatch[1];
|
|
@@ -2235,12 +2323,15 @@ const normalizeLocalShareModuleCode = `const __mfNormalizeShareModule = (mod) =>
|
|
|
2235
2323
|
? Object.assign({}, normalized)
|
|
2236
2324
|
: normalized;
|
|
2237
2325
|
};`;
|
|
2238
|
-
function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
|
|
2239
|
-
|
|
2326
|
+
function writeLoadShareModule(pkg, shareItem, command, _isRolldown, options) {
|
|
2327
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
2328
|
+
const { loadShareCacheMap } = getSharedVirtualModuleState(options);
|
|
2329
|
+
if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] = createScopedSharedVirtualModule(pkg, LOAD_SHARE_TAG, options);
|
|
2240
2330
|
let importLine = getRuntimeModuleCacheBootstrapCode();
|
|
2241
2331
|
const cacheDescriptor = getSharedCacheDescriptorLiteral(pkg, shareItem);
|
|
2242
|
-
const cacheOwner = JSON.stringify(
|
|
2243
|
-
const
|
|
2332
|
+
const cacheOwner = JSON.stringify(resolvedOptions.name);
|
|
2333
|
+
const runtimeInitOwnerImportId = options ? getRuntimeInitStatusImportId(options) : void 0;
|
|
2334
|
+
const treeShakingConsumer = command === "build" && shareItem.shareConfig.treeShaking ? resolvedOptions.name : void 0;
|
|
2244
2335
|
if (shareItem.shareConfig.import === false) {
|
|
2245
2336
|
const detectedNamedExports = getPackageNamedExports(pkg);
|
|
2246
2337
|
const namedExports = detectedNamedExports ?? [];
|
|
@@ -2251,7 +2342,7 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
|
|
|
2251
2342
|
exportLine = generateDeferredHostProvidedExports([], pkg, cacheDescriptor, treeShakingConsumer);
|
|
2252
2343
|
}
|
|
2253
2344
|
loadShareCacheMap[pkg].writeSync(`
|
|
2254
|
-
${getRuntimeInitPromiseBootstrapCode()}
|
|
2345
|
+
${getRuntimeInitPromiseBootstrapCode(false, runtimeInitOwnerImportId)}
|
|
2255
2346
|
${importLine}
|
|
2256
2347
|
${sharedCacheHelperCode}
|
|
2257
2348
|
${exportLine}
|
|
@@ -2259,7 +2350,7 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
|
|
|
2259
2350
|
return;
|
|
2260
2351
|
}
|
|
2261
2352
|
const concreteSharedImportSource = getConcreteSharedImportSource(pkg, shareItem);
|
|
2262
|
-
const sharedImportSource = concreteSharedImportSource || getPreBuildLibImportId(pkg);
|
|
2353
|
+
const sharedImportSource = concreteSharedImportSource || getPreBuildLibImportId(pkg, options);
|
|
2263
2354
|
const devImportSource = concreteSharedImportSource || pkg;
|
|
2264
2355
|
const localProviderPath = getLocalProviderImportPath(pkg);
|
|
2265
2356
|
const coherentLocalSource = concreteSharedImportSource || localProviderPath || devImportSource;
|
|
@@ -2271,20 +2362,20 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
|
|
|
2271
2362
|
const hasCompleteExportCoverage = detectedNamedExports !== void 0;
|
|
2272
2363
|
const isWorkspaceSingleton = isWorkspacePackage && shareItem.shareConfig.singleton === true;
|
|
2273
2364
|
const isDefaultShareScope = shareItem.scope === void 0 || shareItem.scope === "default" || Array.isArray(shareItem.scope) && shareItem.scope[0] === "default";
|
|
2274
|
-
const usesDeferredSingletonFallback = hasCompleteExportCoverage && (isWorkspaceSingleton || command !== "build" && isRemoteOnlyContainer() && shareItem.shareConfig.singleton === true || command === "build" && isRemoteOnlyContainer() && shareItem.shareConfig.singleton === true && !isDefaultShareScope);
|
|
2275
|
-
const servesRemoteSingletonFallback = command !== "build" && isRemoteOnlyContainer() && shareItem.shareConfig.singleton === true;
|
|
2276
|
-
const isConsumedByPeerSingleton = isSharedSingletonConsumedByPeer(pkg);
|
|
2277
|
-
const usesEntryInjectedRemoteFallback = hasCompleteExportCoverage && command !== "build" && !isWorkspaceSingleton && isRemoteOnlyContainer() && shareItem.shareConfig.singleton === true &&
|
|
2365
|
+
const usesDeferredSingletonFallback = hasCompleteExportCoverage && (isWorkspaceSingleton || command !== "build" && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true || command === "build" && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true && !isDefaultShareScope);
|
|
2366
|
+
const servesRemoteSingletonFallback = command !== "build" && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true;
|
|
2367
|
+
const isConsumedByPeerSingleton = isSharedSingletonConsumedByPeer(pkg, resolvedOptions);
|
|
2368
|
+
const usesEntryInjectedRemoteFallback = hasCompleteExportCoverage && command !== "build" && !isWorkspaceSingleton && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true && resolvedOptions.hostInitInjectLocation === "entry" && isConsumedByPeerSingleton;
|
|
2278
2369
|
const usesEagerWorkspaceFallback = hasCompleteExportCoverage && isWorkspaceSingleton && isConsumedByPeerSingleton;
|
|
2279
2370
|
const usesDeferredTreeShakingFallback = hasCompleteExportCoverage && Boolean(treeShakingConsumer);
|
|
2280
2371
|
let exportLine;
|
|
2281
2372
|
let initBlock = "";
|
|
2282
2373
|
if (usesDeferredTreeShakingFallback) {
|
|
2283
|
-
importLine = `${getRuntimeInitPromiseBootstrapCode()}\n ${importLine}`;
|
|
2374
|
+
importLine = `${getRuntimeInitPromiseBootstrapCode(false, runtimeInitOwnerImportId)}\n ${importLine}`;
|
|
2284
2375
|
exportLine = generateLazyWorkspaceSingletonExports(namedExports, lazyLocalFallbackSource, cacheDescriptor, cacheOwner, treeShakingConsumer, command !== "build" && (isWorkspaceSingleton || isWorkspacePackage || servesRemoteSingletonFallback));
|
|
2285
2376
|
} else if (usesEagerWorkspaceFallback || usesEntryInjectedRemoteFallback) exportLine = generateEagerWorkspaceSingletonExports(namedExports, lazyLocalFallbackSource, cacheDescriptor, cacheOwner, treeShakingConsumer);
|
|
2286
2377
|
else if (usesDeferredSingletonFallback) {
|
|
2287
|
-
importLine = `${getRuntimeInitPromiseBootstrapCode()}\n ${importLine}`;
|
|
2378
|
+
importLine = `${getRuntimeInitPromiseBootstrapCode(false, runtimeInitOwnerImportId)}\n ${importLine}`;
|
|
2288
2379
|
exportLine = generateLazyWorkspaceSingletonExports(namedExports, lazyLocalFallbackSource, cacheDescriptor, cacheOwner, treeShakingConsumer, command !== "build" && (isWorkspaceSingleton || isWorkspacePackage || servesRemoteSingletonFallback));
|
|
2289
2380
|
} else if (detectedNamedExports === void 0) {
|
|
2290
2381
|
exportLine = `const __mfDefaultExport = (() => {
|
|
@@ -2347,7 +2438,7 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
|
|
|
2347
2438
|
initBlock = `exportModule = __mfNormalizeShareModule(__mfLocalShare);
|
|
2348
2439
|
__mfWriteSharedCache(__mfModuleCache.share, ${cacheDescriptor}, exportModule, ${cacheOwner});`;
|
|
2349
2440
|
}
|
|
2350
|
-
const prebuildImportLine = usesDeferredSingletonFallback || usesDeferredTreeShakingFallback ? servesRemoteSingletonFallback || usesDeferredSingletonFallback && command !== "build" && (isWorkspaceSingleton || isWorkspacePackage) ? `import * as __mfLocalShare from ${escapeGeneratedStringLiteral(lazyLocalFallbackSource)};` : "" : `import * as __mfLocalShare from ${escapeGeneratedStringLiteral(detectedNamedExports === void 0 ? coherentLocalSource : skipServePrebuildWarmup ? devImportSource : sharedImportSource)};`;
|
|
2441
|
+
const prebuildImportLine = usesEagerWorkspaceFallback || usesEntryInjectedRemoteFallback ? "" : usesDeferredSingletonFallback || usesDeferredTreeShakingFallback ? servesRemoteSingletonFallback || usesDeferredSingletonFallback && command !== "build" && (isWorkspaceSingleton || isWorkspacePackage) ? `import * as __mfLocalShare from ${escapeGeneratedStringLiteral(lazyLocalFallbackSource)};` : "" : `import * as __mfLocalShare from ${escapeGeneratedStringLiteral(detectedNamedExports === void 0 ? coherentLocalSource : skipServePrebuildWarmup ? devImportSource : sharedImportSource)};`;
|
|
2351
2442
|
const devDynamicImportLine = isWorkspacePackage ? "" : usesDeferredSingletonFallback || usesDeferredTreeShakingFallback ? "" : command !== "build" && !skipServePrebuildWarmup ? `;() => import(${escapeGeneratedStringLiteral(devImportSource)}).catch(() => {});` : "";
|
|
2352
2443
|
const moduleBody = usesDeferredSingletonFallback || usesDeferredTreeShakingFallback ? `
|
|
2353
2444
|
${prebuildImportLine}
|
|
@@ -2373,74 +2464,98 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
|
|
|
2373
2464
|
//#endregion
|
|
2374
2465
|
//#region src/virtualModules/virtualRemoteEntry.ts
|
|
2375
2466
|
let usedShares = /* @__PURE__ */ new Set();
|
|
2376
|
-
|
|
2467
|
+
const usedSharesByOptions = /* @__PURE__ */ new WeakMap();
|
|
2468
|
+
function getScopedUsedShares(options) {
|
|
2469
|
+
let scoped = usedSharesByOptions.get(options);
|
|
2470
|
+
if (!scoped) {
|
|
2471
|
+
scoped = /* @__PURE__ */ new Set();
|
|
2472
|
+
usedSharesByOptions.set(options, scoped);
|
|
2473
|
+
}
|
|
2474
|
+
return scoped;
|
|
2475
|
+
}
|
|
2476
|
+
function getUsedShares(options) {
|
|
2477
|
+
if (options) return getScopedUsedShares(options);
|
|
2377
2478
|
return usedShares;
|
|
2378
2479
|
}
|
|
2379
|
-
function addUsedShares(pkg) {
|
|
2480
|
+
function addUsedShares(pkg, options) {
|
|
2380
2481
|
usedShares.add(pkg);
|
|
2482
|
+
if (options) getScopedUsedShares(options).add(pkg);
|
|
2381
2483
|
}
|
|
2382
2484
|
const LOCAL_SHARED_IMPORT_MAP_ID = "virtual:mf-localSharedImportMap";
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2485
|
+
const localOwnerIds = /* @__PURE__ */ new WeakMap();
|
|
2486
|
+
let nextLocalOwnerId = 1;
|
|
2487
|
+
function getLocalOwnerKey(options) {
|
|
2488
|
+
let ownerId = localOwnerIds.get(options);
|
|
2489
|
+
if (!ownerId) {
|
|
2490
|
+
ownerId = nextLocalOwnerId++;
|
|
2491
|
+
localOwnerIds.set(options, ownerId);
|
|
2492
|
+
}
|
|
2493
|
+
return `${options.internalName}__mf_owner__${ownerId}`;
|
|
2494
|
+
}
|
|
2495
|
+
function getLocalSharedImportMapPath(options) {
|
|
2496
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
2497
|
+
return `${LOCAL_SHARED_IMPORT_MAP_ID}:${packageNameEncode(options ? getLocalOwnerKey(resolvedOptions) : resolvedOptions.internalName || resolvedOptions.name)}`;
|
|
2386
2498
|
}
|
|
2387
|
-
function getResolvedLocalSharedImportMapId() {
|
|
2388
|
-
return `\0${getLocalSharedImportMapPath()}`;
|
|
2499
|
+
function getResolvedLocalSharedImportMapId(options) {
|
|
2500
|
+
return `\0${getLocalSharedImportMapPath(options)}`;
|
|
2389
2501
|
}
|
|
2390
2502
|
let invalidateLocalSharedImportMap;
|
|
2391
|
-
|
|
2392
|
-
|
|
2503
|
+
const localSharedImportMapInvalidators = /* @__PURE__ */ new WeakMap();
|
|
2504
|
+
function setLocalSharedImportMapInvalidator(invalidator, options) {
|
|
2505
|
+
if (!options) invalidateLocalSharedImportMap = invalidator;
|
|
2506
|
+
else if (invalidator) localSharedImportMapInvalidators.set(options, invalidator);
|
|
2507
|
+
else localSharedImportMapInvalidators.delete(options);
|
|
2393
2508
|
}
|
|
2394
|
-
function writeLocalSharedImportMap() {
|
|
2395
|
-
invalidateLocalSharedImportMap?.();
|
|
2509
|
+
function writeLocalSharedImportMap(options) {
|
|
2510
|
+
(options ? localSharedImportMapInvalidators.get(options) : invalidateLocalSharedImportMap)?.();
|
|
2396
2511
|
}
|
|
2397
2512
|
function shouldUseDirectReactImport() {
|
|
2398
2513
|
const isVinext = hasPackageDependency("vinext");
|
|
2399
2514
|
const isAstro = hasPackageDependency("astro");
|
|
2400
2515
|
return isVinext || isAstro;
|
|
2401
2516
|
}
|
|
2402
|
-
function getLocalSharedPackagePath(pkg, shareItem) {
|
|
2517
|
+
function getLocalSharedPackagePath(pkg, shareItem, options) {
|
|
2403
2518
|
if (shouldUseDirectReactImport() && pkg === "react") return "react";
|
|
2404
|
-
return getConcreteSharedImportSource(pkg, shareItem) || getLocalProviderImportPath(pkg) || getSharedImportSource(pkg, shareItem);
|
|
2519
|
+
return getConcreteSharedImportSource(pkg, shareItem) || getLocalProviderImportPath(pkg) || getSharedImportSource(pkg, shareItem, options);
|
|
2405
2520
|
}
|
|
2406
2521
|
function getDirectSharedCacheSeedImportPath(pkg, shareItem) {
|
|
2407
2522
|
return getConcreteSharedImportSource(pkg, shareItem) || getProjectResolvedImportPath(pkg) || getLocalProviderImportPath(pkg) || pkg;
|
|
2408
2523
|
}
|
|
2409
|
-
function generateLocalSharedImportMap() {
|
|
2524
|
+
function generateLocalSharedImportMap(options) {
|
|
2525
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
2410
2526
|
const useDirectReactImport = shouldUseDirectReactImport();
|
|
2411
|
-
const
|
|
2412
|
-
const orderedShares = getOrderedUsedShares();
|
|
2527
|
+
const orderedShares = getOrderedUsedShares(options);
|
|
2413
2528
|
return `
|
|
2414
2529
|
import {loadShare} from "@module-federation/runtime";
|
|
2415
2530
|
${orderedShares.map((pkg, index) => {
|
|
2416
|
-
const shareItem = getNormalizeShareItem(pkg);
|
|
2531
|
+
const shareItem = getNormalizeShareItem(pkg, resolvedOptions);
|
|
2417
2532
|
if (!shareItem?.shareConfig.eager || shareItem.shareConfig.import === false) return "";
|
|
2418
|
-
return `import * as __mfEagerShare_${index} from ${JSON.stringify(getLocalSharedPackagePath(pkg, shareItem))};`;
|
|
2533
|
+
return `import * as __mfEagerShare_${index} from ${JSON.stringify(getLocalSharedPackagePath(pkg, shareItem, options))};`;
|
|
2419
2534
|
}).filter(Boolean).join("\n")}
|
|
2420
2535
|
const importMap = {
|
|
2421
2536
|
${orderedShares.map((pkg, index) => {
|
|
2422
|
-
const shareItem = getNormalizeShareItem(pkg);
|
|
2537
|
+
const shareItem = getNormalizeShareItem(pkg, resolvedOptions);
|
|
2423
2538
|
return `
|
|
2424
2539
|
${JSON.stringify(pkg)}: async () => {
|
|
2425
2540
|
${shareItem?.shareConfig.import === false ? `throw new Error(\`[Module Federation] Shared module '\${${JSON.stringify(pkg)}}' must be provided by host\`);` : shareItem?.shareConfig.eager ? `let pkg = __mfEagerShare_${index};
|
|
2426
|
-
return pkg;` : `let pkg = await import(${JSON.stringify(getLocalSharedPackagePath(pkg, shareItem))});
|
|
2541
|
+
return pkg;` : `let pkg = await import(${JSON.stringify(getLocalSharedPackagePath(pkg, shareItem, options))});
|
|
2427
2542
|
return pkg;`}
|
|
2428
2543
|
}
|
|
2429
2544
|
`;
|
|
2430
2545
|
}).join(",")}
|
|
2431
2546
|
}
|
|
2432
2547
|
const usedShared = {
|
|
2433
|
-
${getOrderedUsedShares().map((key) => {
|
|
2434
|
-
const shareItem = getNormalizeShareItem(key);
|
|
2548
|
+
${getOrderedUsedShares(options).map((key) => {
|
|
2549
|
+
const shareItem = getNormalizeShareItem(key, resolvedOptions);
|
|
2435
2550
|
if (!shareItem) return null;
|
|
2436
2551
|
const detectedNamedExports = getSharedNamedExports(key, shareItem);
|
|
2437
2552
|
const canLiveRebind = shareItem.shareConfig.import === false || detectedNamedExports !== void 0;
|
|
2438
2553
|
const treeShakingConfig = canLiveRebind ? shareItem.shareConfig.treeShaking : void 0;
|
|
2439
|
-
const treeShakingUsage = treeShakingConfig ? getTreeShakingExportUsage(key, shareItem, shareItem.name) : void 0;
|
|
2554
|
+
const treeShakingUsage = treeShakingConfig ? getTreeShakingExportUsage(key, shareItem, shareItem.name, options) : void 0;
|
|
2440
2555
|
const treeShakingProviderExports = treeShakingUsage?.kind === "exports" ? treeShakingUsage.usedExports : [];
|
|
2441
|
-
const treeShakingUsedExports =
|
|
2442
|
-
const disableRuntimeInference = treeShakingConfig?.mode === "runtime-infer" &&
|
|
2443
|
-
const treeShakingProviderImportId = treeShakingConfig && !disableRuntimeInference && hasTreeShakingSharedProvider(key, shareItem) ? getTreeShakingSharedProviderImportId(key) : void 0;
|
|
2556
|
+
const treeShakingUsedExports = resolvedOptions.injectTreeShakingUsedExports === false ? treeShakingConfig?.usedExports || [] : treeShakingProviderExports;
|
|
2557
|
+
const disableRuntimeInference = treeShakingConfig?.mode === "runtime-infer" && resolvedOptions.injectTreeShakingUsedExports === false;
|
|
2558
|
+
const treeShakingProviderImportId = treeShakingConfig && !disableRuntimeInference && hasTreeShakingSharedProvider(key, shareItem, options) ? getTreeShakingSharedProviderImportId(key, options) : void 0;
|
|
2444
2559
|
const treeShakingStatus = treeShakingUsage?.kind === "full" || disableRuntimeInference || treeShakingConfig?.mode === "runtime-infer" && !treeShakingProviderImportId && shareItem.shareConfig.import !== false ? 0 : 1;
|
|
2445
2560
|
return `
|
|
2446
2561
|
${JSON.stringify(key)}: {
|
|
@@ -2449,7 +2564,7 @@ function generateLocalSharedImportMap() {
|
|
|
2449
2564
|
scope: [${JSON.stringify(shareItem.scope)}],
|
|
2450
2565
|
loaded: false,
|
|
2451
2566
|
eager: ${Boolean(shareItem.shareConfig.eager)},
|
|
2452
|
-
from: ${JSON.stringify(
|
|
2567
|
+
from: ${JSON.stringify(resolvedOptions.name)},
|
|
2453
2568
|
canLiveRebind: ${canLiveRebind},
|
|
2454
2569
|
async get () {
|
|
2455
2570
|
if (${shareItem.shareConfig.import === false}) {
|
|
@@ -2494,14 +2609,14 @@ function generateLocalSharedImportMap() {
|
|
|
2494
2609
|
`;
|
|
2495
2610
|
}).filter((x) => x !== null).join(",")}
|
|
2496
2611
|
}
|
|
2497
|
-
const usedRemotes = [${Object.keys(getUsedRemotesMap()).map((key) => {
|
|
2498
|
-
const remote =
|
|
2612
|
+
const usedRemotes = [${Object.keys(getUsedRemotesMap(options)).map((key) => {
|
|
2613
|
+
const remote = resolvedOptions.remotes[key];
|
|
2499
2614
|
if (!remote) return null;
|
|
2500
2615
|
return `
|
|
2501
2616
|
{
|
|
2502
|
-
alias: ${JSON.stringify(key)},
|
|
2617
|
+
alias: ${JSON.stringify(getRuntimeRemoteAlias(key, options))},
|
|
2503
2618
|
entryGlobalName: ${JSON.stringify(remote.entryGlobalName)},
|
|
2504
|
-
name: ${JSON.stringify(remote.name)},
|
|
2619
|
+
name: ${JSON.stringify(options ? getRuntimeRemoteAlias(key, options) : remote.name)},
|
|
2505
2620
|
type: ${JSON.stringify(remote.type)},
|
|
2506
2621
|
entry: ${JSON.stringify(remote.entry)},
|
|
2507
2622
|
shareScope: ${JSON.stringify(remote.shareScope ?? "default")},
|
|
@@ -2515,16 +2630,12 @@ function generateLocalSharedImportMap() {
|
|
|
2515
2630
|
}
|
|
2516
2631
|
`;
|
|
2517
2632
|
}
|
|
2518
|
-
function getOrderedUsedShares() {
|
|
2519
|
-
const
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
return;
|
|
2525
|
-
}
|
|
2526
|
-
});
|
|
2527
|
-
} catch {}
|
|
2633
|
+
function getOrderedUsedShares(options) {
|
|
2634
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
2635
|
+
const shares = new Set(getUsedShares(options));
|
|
2636
|
+
Object.keys(resolvedOptions.shared).forEach((pkg) => {
|
|
2637
|
+
if (!pkg.endsWith("/")) shares.add(pkg);
|
|
2638
|
+
});
|
|
2528
2639
|
return orderSharedDependenciesFirst(Array.from(shares).sort((a, b) => {
|
|
2529
2640
|
const priority = (pkg) => pkg === "react" ? 0 : pkg === "react-dom" ? 1 : pkg.startsWith("react/") ? 2 : 3;
|
|
2530
2641
|
return priority(a) - priority(b) || a.localeCompare(b);
|
|
@@ -2578,15 +2689,15 @@ function orderSharedDependenciesFirst(sharedPackages) {
|
|
|
2578
2689
|
sharedPackages.forEach(visit);
|
|
2579
2690
|
return ordered;
|
|
2580
2691
|
}
|
|
2581
|
-
function getShareItemForPreload(pkg) {
|
|
2582
|
-
const shared =
|
|
2692
|
+
function getShareItemForPreload(pkg, options = getNormalizeModuleFederationOptions()) {
|
|
2693
|
+
const shared = options.shared;
|
|
2583
2694
|
const wildcardKey = `${pkg.startsWith("@") ? pkg.split("/").slice(0, 2).join("/") : pkg.split("/")[0]}/`;
|
|
2584
|
-
if (isExplicitSharedKey(pkg)) return shared[pkg];
|
|
2585
|
-
if (isExplicitSharedKey(wildcardKey)) return shared[wildcardKey];
|
|
2695
|
+
if (isExplicitSharedKey(pkg, options)) return shared[pkg];
|
|
2696
|
+
if (isExplicitSharedKey(wildcardKey, options)) return shared[wildcardKey];
|
|
2586
2697
|
}
|
|
2587
|
-
function generateSharedCacheSeedItem(pkg, shareItem, importPath) {
|
|
2698
|
+
function generateSharedCacheSeedItem(pkg, shareItem, importPath, options = getNormalizeModuleFederationOptions()) {
|
|
2588
2699
|
const cacheDescriptor = getSharedCacheDescriptor(pkg, shareItem);
|
|
2589
|
-
const cacheOwner =
|
|
2700
|
+
const cacheOwner = options.name;
|
|
2590
2701
|
return `if (__mfReadSharedCache(__mfModuleCache.share, ${JSON.stringify(cacheDescriptor)}) === undefined) {
|
|
2591
2702
|
const mod = await import(${JSON.stringify(importPath)});
|
|
2592
2703
|
${normalizeRuntimeShareCode}
|
|
@@ -2879,10 +2990,11 @@ function getBrowserImportPath(importPath) {
|
|
|
2879
2990
|
if (/^(?:[a-zA-Z]:[\\/]|\/)/.test(importPath) && !importPath.startsWith("/@")) return `/@fs/${importPath}`;
|
|
2880
2991
|
return importPath;
|
|
2881
2992
|
}
|
|
2882
|
-
function getHostAutoInitSharedSeedItems() {
|
|
2883
|
-
|
|
2993
|
+
function getHostAutoInitSharedSeedItems(options) {
|
|
2994
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
2995
|
+
return getOrderedUsedShares(options).map((pkg) => ({
|
|
2884
2996
|
pkg,
|
|
2885
|
-
shareItem: getShareItemForPreload(pkg)
|
|
2997
|
+
shareItem: getShareItemForPreload(pkg, resolvedOptions)
|
|
2886
2998
|
})).filter(({ shareItem }) => shareItem?.shareConfig?.import === false).sort((a, b) => {
|
|
2887
2999
|
const priority = (pkg) => pkg === "vue" ? 0 : pkg === "pinia" ? 1 : 2;
|
|
2888
3000
|
const aIsLocal = !!getLocalProviderImportPath(a.pkg);
|
|
@@ -2890,11 +3002,12 @@ function getHostAutoInitSharedSeedItems() {
|
|
|
2890
3002
|
return priority(a.pkg) - priority(b.pkg) || Number(aIsLocal) - Number(bIsLocal) || a.pkg.localeCompare(b.pkg);
|
|
2891
3003
|
});
|
|
2892
3004
|
}
|
|
2893
|
-
function generateHostAutoInitSharedCacheSeedCode(command = "build") {
|
|
3005
|
+
function generateHostAutoInitSharedCacheSeedCode(command = "build", options) {
|
|
2894
3006
|
if (command === "build") return "";
|
|
2895
|
-
|
|
3007
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
3008
|
+
return getHostAutoInitSharedSeedItems(options).map(({ pkg, shareItem }) => {
|
|
2896
3009
|
if (!shareItem) return null;
|
|
2897
|
-
return generateSharedCacheSeedItem(pkg, shareItem, getBrowserImportPath(getDirectSharedCacheSeedImportPath(pkg, shareItem)));
|
|
3010
|
+
return generateSharedCacheSeedItem(pkg, shareItem, getBrowserImportPath(getDirectSharedCacheSeedImportPath(pkg, shareItem)), resolvedOptions);
|
|
2898
3011
|
}).filter((item) => item !== null).join("\n");
|
|
2899
3012
|
}
|
|
2900
3013
|
const REMOTE_ENTRY_ID = "virtual:mf-REMOTE_ENTRY_ID";
|
|
@@ -3119,10 +3232,10 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
3119
3232
|
globalThis.__VUE_HMR_RUNTIME__ = { createRecord() {}, rerender() {}, reload() {} };
|
|
3120
3233
|
}
|
|
3121
3234
|
import {${runtimeImports}} from "@module-federation/runtime";
|
|
3122
|
-
${hasEagerShared ? `import * as __mfLocalSharedImportMap from "${getLocalSharedImportMapPath()}";` : ""}
|
|
3235
|
+
${hasEagerShared ? `import * as __mfLocalSharedImportMap from "${getLocalSharedImportMapPath(options)}";` : ""}
|
|
3123
3236
|
${runtimeHelperImports.length ? `import {${runtimeHelperImports.join(", ")}} from "@module-federation/runtime/helpers";` : ""}
|
|
3124
3237
|
${pluginImportNames.filter((item) => !isSsrOnlyPlugin(item[1])).map((item) => item[1]).join("\n")}
|
|
3125
|
-
${command === "build" ? getRuntimeInitResolveBootstrapCode() : getRuntimeInitBootstrapCode() + "\n const { initResolve } = globalThis[globalKey];"}
|
|
3238
|
+
${command === "build" ? getRuntimeInitResolveBootstrapCode(false, options ? getRuntimeInitStatusImportId(options) : void 0) : getRuntimeInitBootstrapCode(false, options ? getRuntimeInitStatusImportId(options) : void 0) + "\n const { initResolve } = globalThis[globalKey];"}
|
|
3126
3239
|
${getRuntimeModuleCacheBootstrapCode()}
|
|
3127
3240
|
const initTokens = {}
|
|
3128
3241
|
const shareScopeNames = Array.isArray(${JSON.stringify(options.shareScope)}) ? ${JSON.stringify(options.shareScope)} : [${JSON.stringify(options.shareScope)}]
|
|
@@ -3156,7 +3269,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
3156
3269
|
async function getLocalSharedImportMap() {
|
|
3157
3270
|
${hasEagerShared ? "return __mfLocalSharedImportMap;" : ""}
|
|
3158
3271
|
${hasEagerShared ? "" : `if (!localSharedImportMapPromise) {
|
|
3159
|
-
localSharedImportMapPromise = retrySharedInit(() => import("${getLocalSharedImportMapPath()}"))
|
|
3272
|
+
localSharedImportMapPromise = retrySharedInit(() => import("${getLocalSharedImportMapPath(options)}"))
|
|
3160
3273
|
.catch((e) => { localSharedImportMapPromise = undefined; throw e; });
|
|
3161
3274
|
}
|
|
3162
3275
|
return localSharedImportMapPromise`}
|
|
@@ -3852,13 +3965,35 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
3852
3965
|
}
|
|
3853
3966
|
`;
|
|
3854
3967
|
}
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3968
|
+
/**
|
|
3969
|
+
* Inject entry file, automatically init when used as host,
|
|
3970
|
+
* and will not inject remoteEntry
|
|
3971
|
+
*/
|
|
3972
|
+
const HOST_AUTO_INIT_TAG = "__H_A_I__";
|
|
3973
|
+
const hostAutoInitStates = /* @__PURE__ */ new WeakMap();
|
|
3974
|
+
const legacyHostAutoInitState = {
|
|
3975
|
+
module: new VirtualModule("hostAutoInit", HOST_AUTO_INIT_TAG),
|
|
3976
|
+
remoteEntryId: REMOTE_ENTRY_ID,
|
|
3977
|
+
command: "build"
|
|
3978
|
+
};
|
|
3979
|
+
function getHostAutoInitState(options) {
|
|
3980
|
+
if (!options) return legacyHostAutoInitState;
|
|
3981
|
+
let state = hostAutoInitStates.get(options);
|
|
3982
|
+
if (!state) {
|
|
3983
|
+
state = {
|
|
3984
|
+
module: new VirtualModule("hostAutoInit", HOST_AUTO_INIT_TAG, "", getLocalOwnerKey(options)),
|
|
3985
|
+
remoteEntryId: REMOTE_ENTRY_ID,
|
|
3986
|
+
command: "build"
|
|
3987
|
+
};
|
|
3988
|
+
hostAutoInitStates.set(options, state);
|
|
3989
|
+
}
|
|
3990
|
+
return state;
|
|
3991
|
+
}
|
|
3992
|
+
function generateHostAutoInitCode(remoteEntryImport, _command = "build", options) {
|
|
3993
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
3994
|
+
const shouldPreloadShares = resolvedOptions.shareStrategy !== "loaded-first";
|
|
3995
|
+
const hostInitShareOrder = JSON.stringify(getOrderedUsedShares(options));
|
|
3996
|
+
const cacheOwner = JSON.stringify(resolvedOptions.name);
|
|
3862
3997
|
return `
|
|
3863
3998
|
${getRuntimeModuleCacheBootstrapCode()}
|
|
3864
3999
|
let hostInitPromise;
|
|
@@ -3866,10 +4001,10 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build") {
|
|
|
3866
4001
|
if (!hostInitPromise) {
|
|
3867
4002
|
hostInitPromise = (async () => {
|
|
3868
4003
|
${sharedCacheHelperCode}
|
|
3869
|
-
${generateHostAutoInitSharedCacheSeedCode(_command)}
|
|
4004
|
+
${generateHostAutoInitSharedCacheSeedCode(_command, options)}
|
|
3870
4005
|
const remoteEntry = await import(${remoteEntryImport});
|
|
3871
4006
|
const runtime = await remoteEntry.init();
|
|
3872
|
-
const {usedShared} = await import("${getLocalSharedImportMapPath()}");
|
|
4007
|
+
const {usedShared} = await import("${getLocalSharedImportMapPath(options)}");
|
|
3873
4008
|
${normalizeRuntimeShareCode}
|
|
3874
4009
|
${shouldPreloadShares ? `
|
|
3875
4010
|
const __mfHostInitShareOrder = ${hostInitShareOrder}
|
|
@@ -3911,46 +4046,82 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build") {
|
|
|
3911
4046
|
export { initHost, hostInitPromise };
|
|
3912
4047
|
`;
|
|
3913
4048
|
}
|
|
3914
|
-
function writeHostAutoInit(remoteEntryId = REMOTE_ENTRY_ID, command = "build") {
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
4049
|
+
function writeHostAutoInit(remoteEntryId = REMOTE_ENTRY_ID, command = "build", options) {
|
|
4050
|
+
const state = getHostAutoInitState(options);
|
|
4051
|
+
state.remoteEntryId = remoteEntryId;
|
|
4052
|
+
state.command = command;
|
|
4053
|
+
state.module.writeSync(generateHostAutoInitCode(JSON.stringify(remoteEntryId), command, options), true);
|
|
3918
4054
|
}
|
|
3919
|
-
function refreshHostAutoInit() {
|
|
4055
|
+
function refreshHostAutoInit(options) {
|
|
3920
4056
|
try {
|
|
3921
|
-
|
|
4057
|
+
const state = getHostAutoInitState(options);
|
|
4058
|
+
writeHostAutoInit(state.remoteEntryId, state.command, options);
|
|
3922
4059
|
} catch {}
|
|
3923
4060
|
}
|
|
3924
|
-
function getHostAutoInitImportId() {
|
|
3925
|
-
return
|
|
4061
|
+
function getHostAutoInitImportId(options) {
|
|
4062
|
+
return getHostAutoInitState(options).module.getImportId();
|
|
3926
4063
|
}
|
|
3927
|
-
function getHostAutoInitPath() {
|
|
3928
|
-
return
|
|
4064
|
+
function getHostAutoInitPath(options) {
|
|
4065
|
+
return getHostAutoInitState(options).module.getImportId();
|
|
3929
4066
|
}
|
|
3930
4067
|
//#endregion
|
|
3931
4068
|
//#region src/virtualModules/virtualRemotes.ts
|
|
3932
|
-
const cacheRemoteMap =
|
|
4069
|
+
const cacheRemoteMap = /* @__PURE__ */ new WeakMap();
|
|
4070
|
+
const remoteOptionsIds = /* @__PURE__ */ new WeakMap();
|
|
4071
|
+
let nextRemoteOptionsId = 1;
|
|
4072
|
+
function getRemoteOptionsId(options) {
|
|
4073
|
+
let id = remoteOptionsIds.get(options);
|
|
4074
|
+
if (id === void 0) {
|
|
4075
|
+
id = nextRemoteOptionsId++;
|
|
4076
|
+
remoteOptionsIds.set(options, id);
|
|
4077
|
+
}
|
|
4078
|
+
return id;
|
|
4079
|
+
}
|
|
3933
4080
|
const LOAD_REMOTE_TAG = "__loadRemote__";
|
|
3934
|
-
function getRemoteVirtualModule(remote, command, enableSsrInit = false, consumer = "unified") {
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
cacheRemoteMap
|
|
3939
|
-
cacheRemoteMap[cacheKey].writeSync(generateRemotes(remote, command, enableSsrInit, consumer));
|
|
4081
|
+
function getRemoteVirtualModule(remote, command, enableSsrInit = false, consumer = "unified", options = getNormalizeModuleFederationOptions()) {
|
|
4082
|
+
let instanceCache = cacheRemoteMap.get(options);
|
|
4083
|
+
if (!instanceCache) {
|
|
4084
|
+
instanceCache = /* @__PURE__ */ new Map();
|
|
4085
|
+
cacheRemoteMap.set(options, instanceCache);
|
|
3940
4086
|
}
|
|
3941
|
-
|
|
4087
|
+
const cacheKey = `${remote}__${command}__${options.shareStrategy}__${consumer}__${enableSsrInit ? "ssr-init" : "no-ssr-init"}`;
|
|
4088
|
+
if (!instanceCache.has(cacheKey)) {
|
|
4089
|
+
const virtual = new VirtualModule(`${consumer === "unified" ? remote : `${remote}__mf_consumer__${consumer}`}__mf_owner__${getRemoteOptionsId(options)}`, LOAD_REMOTE_TAG, ".js", options.internalName);
|
|
4090
|
+
virtual.writeSync(generateRemotes(remote, command, enableSsrInit, consumer, options));
|
|
4091
|
+
instanceCache.set(cacheKey, virtual);
|
|
4092
|
+
}
|
|
4093
|
+
return instanceCache.get(cacheKey);
|
|
3942
4094
|
}
|
|
3943
4095
|
const usedRemotesMap = {};
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
4096
|
+
const usedRemotesByOptions = /* @__PURE__ */ new WeakMap();
|
|
4097
|
+
function getScopedUsedRemotesMap(options) {
|
|
4098
|
+
let scoped = usedRemotesByOptions.get(options);
|
|
4099
|
+
if (!scoped) {
|
|
4100
|
+
scoped = {};
|
|
4101
|
+
usedRemotesByOptions.set(options, scoped);
|
|
4102
|
+
}
|
|
4103
|
+
return scoped;
|
|
4104
|
+
}
|
|
4105
|
+
function recordUsedRemote(map, remoteKey, remoteModule) {
|
|
4106
|
+
if (!map[remoteKey]) map[remoteKey] = /* @__PURE__ */ new Set();
|
|
4107
|
+
map[remoteKey].add(remoteModule);
|
|
4108
|
+
}
|
|
4109
|
+
function addUsedRemote(remoteKey, remoteModule, options) {
|
|
4110
|
+
recordUsedRemote(usedRemotesMap, remoteKey, remoteModule);
|
|
4111
|
+
if (options) recordUsedRemote(getScopedUsedRemotesMap(options), remoteKey, remoteModule);
|
|
3947
4112
|
}
|
|
3948
|
-
function getUsedRemotesMap() {
|
|
4113
|
+
function getUsedRemotesMap(options) {
|
|
4114
|
+
if (options) return getScopedUsedRemotesMap(options);
|
|
3949
4115
|
return usedRemotesMap;
|
|
3950
4116
|
}
|
|
3951
4117
|
function getRemoteAliasFromId(id, remotes) {
|
|
3952
4118
|
return Object.keys(remotes).filter((name) => id === name || id.startsWith(name + "/")).sort((a, b) => b.length - a.length)[0];
|
|
3953
4119
|
}
|
|
4120
|
+
function getRuntimeRemoteId(id, remotes, options) {
|
|
4121
|
+
const alias = getRemoteAliasFromId(id, remotes);
|
|
4122
|
+
if (!alias) return id;
|
|
4123
|
+
return `${getRuntimeRemoteAlias(alias, options)}${id.slice(alias.length)}`;
|
|
4124
|
+
}
|
|
3954
4125
|
function resolveRemoteInitMode(shareStrategy, consumer) {
|
|
3955
4126
|
if (shareStrategy !== "loaded-first") return "eager";
|
|
3956
4127
|
if (consumer === "server") return "loaded-first-ssr";
|
|
@@ -4009,7 +4180,7 @@ function getRemoteModuleRuntimeHelpers() {
|
|
|
4009
4180
|
return exportModule;
|
|
4010
4181
|
}`;
|
|
4011
4182
|
}
|
|
4012
|
-
function getDeferredProxyHelper(
|
|
4183
|
+
function getDeferredProxyHelper(remoteCacheKey) {
|
|
4013
4184
|
return `
|
|
4014
4185
|
function __mfCreateDeferredRemoteProxy() {
|
|
4015
4186
|
let pendingPromise;
|
|
@@ -4017,7 +4188,7 @@ function getDeferredProxyHelper(remoteId) {
|
|
|
4017
4188
|
pendingPromise ||= __mfStartRemoteLoad();
|
|
4018
4189
|
return pendingPromise;
|
|
4019
4190
|
};
|
|
4020
|
-
const getModule = () => __mfModuleCache.remote[${JSON.stringify(
|
|
4191
|
+
const getModule = () => __mfModuleCache.remote[${JSON.stringify(remoteCacheKey)}];
|
|
4021
4192
|
const proxyTarget = function (...args) {
|
|
4022
4193
|
pendingPromise ||= __mfStartRemoteLoad();
|
|
4023
4194
|
const mod = getModule();
|
|
@@ -4115,30 +4286,39 @@ ${deferRemoteLoad ? getLazyRemotePendingExport() : getEagerRemotePendingExport()
|
|
|
4115
4286
|
${command === "serve" && consumer === "server" ? getServerThenExport() : ""}
|
|
4116
4287
|
export { __mfDefaultExport as default };`;
|
|
4117
4288
|
}
|
|
4118
|
-
function generateRemotes(id, command, enableSsrInit = false, consumer = "unified") {
|
|
4119
|
-
const
|
|
4120
|
-
const isLoadedFirst =
|
|
4121
|
-
const initMode = resolveRemoteInitMode(
|
|
4289
|
+
function generateRemotes(id, command, enableSsrInit = false, consumer = "unified", options) {
|
|
4290
|
+
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
4291
|
+
const isLoadedFirst = resolvedOptions.shareStrategy === "loaded-first";
|
|
4292
|
+
const initMode = resolveRemoteInitMode(resolvedOptions.shareStrategy, consumer);
|
|
4122
4293
|
const deferRemoteLoad = shouldDeferRemoteLoad(initMode);
|
|
4123
|
-
const remoteAlias = getRemoteAliasFromId(id,
|
|
4124
|
-
const remote = remoteAlias ?
|
|
4294
|
+
const remoteAlias = getRemoteAliasFromId(id, resolvedOptions.remotes);
|
|
4295
|
+
const remote = remoteAlias ? resolvedOptions.remotes[remoteAlias] : void 0;
|
|
4296
|
+
const runtimeRemoteAlias = remoteAlias ? getRuntimeRemoteAlias(remoteAlias, options) : void 0;
|
|
4297
|
+
const runtimeRemoteId = getRuntimeRemoteId(id, resolvedOptions.remotes, options);
|
|
4125
4298
|
const registerRemoteCode = isLoadedFirst && remote ? `runtime.registerRemotes([${JSON.stringify({
|
|
4126
4299
|
entryGlobalName: remote.entryGlobalName,
|
|
4127
|
-
name: remote.name,
|
|
4128
|
-
alias:
|
|
4300
|
+
name: options ? runtimeRemoteAlias : remote.name,
|
|
4301
|
+
alias: runtimeRemoteAlias,
|
|
4129
4302
|
type: remote.type,
|
|
4130
4303
|
entry: remote.entry,
|
|
4131
4304
|
shareScope: remote.shareScope ?? "default"
|
|
4132
4305
|
})}]);` : "";
|
|
4133
|
-
const
|
|
4306
|
+
const hostAutoInitPath = getHostAutoInitPath(options);
|
|
4307
|
+
const ssrRemotes = Object.entries(resolvedOptions.remotes).map(([name, item]) => ({
|
|
4308
|
+
name: getRuntimeRemoteAlias(name, options),
|
|
4309
|
+
entry: item.entry,
|
|
4310
|
+
type: item.type ?? "module"
|
|
4311
|
+
}));
|
|
4312
|
+
const browserHostInitCode = `import(${JSON.stringify(hostAutoInitPath)})
|
|
4134
4313
|
.then((mod) => mod.hostInitPromise)
|
|
4135
4314
|
.then(initResolve, initReject);`;
|
|
4136
|
-
const devRuntimeBootstrap = `${getRuntimeInitBootstrapCode(enableSsrInit,
|
|
4315
|
+
const devRuntimeBootstrap = `${getRuntimeInitBootstrapCode(enableSsrInit, getRuntimeInitStatusImportId(options), ssrRemotes, hostAutoInitPath)}
|
|
4137
4316
|
const { initPromise, initResolve, initReject, moduleCache: __mfModuleCache } = globalThis[globalKey];`;
|
|
4138
4317
|
const importLine = command === "build" ? `${getRuntimeModuleCacheBootstrapCode()}
|
|
4139
|
-
import { hostInitPromise as __mfHostInitPromise } from ${JSON.stringify(
|
|
4318
|
+
import { hostInitPromise as __mfHostInitPromise } from ${JSON.stringify(hostAutoInitPath)};` : `${devRuntimeBootstrap}
|
|
4140
4319
|
${command === "serve" && consumer !== "server" ? browserHostInitCode : ""}`;
|
|
4141
4320
|
const remoteLoadRuntimePromise = command === "build" ? "__mfHostInitPromise" : "initPromise";
|
|
4321
|
+
const remoteCacheKey = `${getRuntimeRemoteCachePrefix(options)}${id}`;
|
|
4142
4322
|
const remoteLoadFailureHandler = command === "build" ? `.catch((error) => {
|
|
4143
4323
|
delete __mfModuleCache.remote[pendingKey];
|
|
4144
4324
|
throw error;
|
|
@@ -4149,16 +4329,17 @@ function generateRemotes(id, command, enableSsrInit = false, consumer = "unified
|
|
|
4149
4329
|
const remoteLoadCode = `
|
|
4150
4330
|
function __mfStartRemoteLoad() {
|
|
4151
4331
|
${`
|
|
4152
|
-
const
|
|
4332
|
+
const remoteCacheKey = ${JSON.stringify(remoteCacheKey)};
|
|
4333
|
+
const pendingKey = "__mf_pending__" + remoteCacheKey;
|
|
4153
4334
|
if (!__mfModuleCache.remote[pendingKey]) {
|
|
4154
4335
|
__mfModuleCache.remote[pendingKey] = ${remoteLoadRuntimePromise}
|
|
4155
4336
|
.then((runtime) => {
|
|
4156
4337
|
${registerRemoteCode}
|
|
4157
|
-
return runtime.loadRemote(${JSON.stringify(
|
|
4338
|
+
return runtime.loadRemote(${JSON.stringify(runtimeRemoteId)});
|
|
4158
4339
|
})
|
|
4159
4340
|
.then((mod) => Promise.resolve(mod?.__mf_remote_dependency_pending).then(() => mod))
|
|
4160
4341
|
.then((mod) => {
|
|
4161
|
-
__mfModuleCache.remote[
|
|
4342
|
+
__mfModuleCache.remote[remoteCacheKey] = mod;
|
|
4162
4343
|
delete __mfModuleCache.remote[pendingKey];
|
|
4163
4344
|
return mod;
|
|
4164
4345
|
})
|
|
@@ -4178,14 +4359,14 @@ function generateRemotes(id, command, enableSsrInit = false, consumer = "unified
|
|
|
4178
4359
|
}`;
|
|
4179
4360
|
const initExportModule = initMode === "eager" ? environmentSplitInit(eagerClientInit, realRemoteInit) : environmentSplitInit(loadedFirstClientInit, realRemoteInit);
|
|
4180
4361
|
const includeProxyHelper = shouldIncludeDeferredProxy(initMode, consumer, eagerLoadClientRemote, deferRemoteLoad);
|
|
4181
|
-
const deferredProxyCode = getDeferredProxyHelper(
|
|
4362
|
+
const deferredProxyCode = getDeferredProxyHelper(remoteCacheKey);
|
|
4182
4363
|
return `
|
|
4183
4364
|
${importLine}
|
|
4184
4365
|
${remoteLoadCode}
|
|
4185
4366
|
${includeProxyHelper ? deferredProxyCode : ""}
|
|
4186
4367
|
${getRemoteModuleRuntimeHelpers()}
|
|
4187
4368
|
let __mfRemotePending;
|
|
4188
|
-
let exportModule = __mfModuleCache.remote[${JSON.stringify(
|
|
4369
|
+
let exportModule = __mfModuleCache.remote[${JSON.stringify(remoteCacheKey)}]
|
|
4189
4370
|
if (exportModule === undefined) {
|
|
4190
4371
|
${initExportModule}
|
|
4191
4372
|
}
|
|
@@ -4264,7 +4445,7 @@ function patchHashEntryFileNames(config, entryName, fileName) {
|
|
|
4264
4445
|
patchBundlerOutput(config.build.rollupOptions);
|
|
4265
4446
|
patchBundlerOutput(config.build.rolldownOptions);
|
|
4266
4447
|
}
|
|
4267
|
-
const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClientInjected, skipTransformFor = [] }) => {
|
|
4448
|
+
const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClientInjected, skipTransformFor = [], federationOptions }) => {
|
|
4268
4449
|
const DEV_HTML_PROXY_PREFIX = "virtual:mf-html-entry-proxy?";
|
|
4269
4450
|
const ENTRY_BOOTSTRAP_PARAM = "mf-entry-bootstrap";
|
|
4270
4451
|
const ENTRY_BOOTSTRAP_QUERY = `?${ENTRY_BOOTSTRAP_PARAM}`;
|
|
@@ -4348,15 +4529,17 @@ const __mfCurrentScript = document.currentScript;
|
|
|
4348
4529
|
: import(src);
|
|
4349
4530
|
` : "";
|
|
4350
4531
|
const importExpression = (src) => useSystemImportFallback ? `__mfImport(${JSON.stringify(src)})` : `import(${JSON.stringify(src)})`;
|
|
4351
|
-
const remotePreloads = !options?.skipRemotePreload && getNormalizeModuleFederationOptions()?.shareStrategy !== "loaded-first" ? Object.entries(getUsedRemotesMap()).flatMap(([remoteKey, remotes]) => Array.from(remotes).filter((remote) => remote !== remoteKey)).sort().map((remote) => `__mfPreloadRemote(${JSON.stringify(remote)})`).join(",") : "";
|
|
4532
|
+
const remotePreloads = !options?.skipRemotePreload && (federationOptions ?? getNormalizeModuleFederationOptions())?.shareStrategy !== "loaded-first" ? Object.entries(getUsedRemotesMap(federationOptions)).flatMap(([remoteKey, remotes]) => Array.from(remotes).filter((remote) => remote !== remoteKey)).sort().map((remote) => `__mfPreloadRemote(${JSON.stringify(getRuntimeRemoteId(remote, (federationOptions ?? getNormalizeModuleFederationOptions()).remotes, federationOptions))}, ${JSON.stringify(remote)})`).join(",") : "";
|
|
4533
|
+
const remoteCachePrefix = getRuntimeRemoteCachePrefix(federationOptions);
|
|
4352
4534
|
const preloadBlock = remotePreloads ? `
|
|
4353
4535
|
const runtime = await initHost();
|
|
4354
|
-
const __mfPreloadRemote = (remote) => {
|
|
4355
|
-
const
|
|
4536
|
+
const __mfPreloadRemote = (runtimeRemote, remote) => {
|
|
4537
|
+
const remoteCacheKey = ${JSON.stringify(remoteCachePrefix)} + remote;
|
|
4538
|
+
const pendingKey = "__mf_pending__" + remoteCacheKey;
|
|
4356
4539
|
if (!__mfModuleCache.remote[pendingKey]) {
|
|
4357
|
-
__mfModuleCache.remote[pendingKey] = runtime.loadRemote(
|
|
4540
|
+
__mfModuleCache.remote[pendingKey] = runtime.loadRemote(runtimeRemote)
|
|
4358
4541
|
.then((mod) => {
|
|
4359
|
-
__mfModuleCache.remote[
|
|
4542
|
+
__mfModuleCache.remote[remoteCacheKey] = mod;
|
|
4360
4543
|
delete __mfModuleCache.remote[pendingKey];
|
|
4361
4544
|
return mod;
|
|
4362
4545
|
})
|
|
@@ -4603,7 +4786,7 @@ const __mfCurrentScript = document.currentScript;
|
|
|
4603
4786
|
htmlContent = htmlContent.replace("<head>", `<head>${scriptContent}`);
|
|
4604
4787
|
}
|
|
4605
4788
|
}
|
|
4606
|
-
if (waitsForInit) htmlContent = injectHostInitPreloads(htmlContent, bundle, (builtFileName) => resolvePath(builtFileName, fileName));
|
|
4789
|
+
if (waitsForInit && viteConfig.build.modulePreload !== false) htmlContent = injectHostInitPreloads(htmlContent, bundle, (builtFileName) => resolvePath(builtFileName, fileName));
|
|
4607
4790
|
htmlAsset.source = htmlContent;
|
|
4608
4791
|
}
|
|
4609
4792
|
},
|
|
@@ -5179,10 +5362,14 @@ function pluginDevRemoteHmr(options) {
|
|
|
5179
5362
|
}
|
|
5180
5363
|
//#endregion
|
|
5181
5364
|
//#region src/virtualModules/index.ts
|
|
5182
|
-
function initVirtualModules(command, remoteEntryId, enableSsrInit = false) {
|
|
5183
|
-
writeLocalSharedImportMap();
|
|
5184
|
-
writeHostAutoInit(remoteEntryId, command);
|
|
5185
|
-
writeRuntimeInitStatus(command, enableSsrInit, getHostAutoInitPath())
|
|
5365
|
+
function initVirtualModules(command, remoteEntryId, enableSsrInit = false, options) {
|
|
5366
|
+
writeLocalSharedImportMap(options);
|
|
5367
|
+
writeHostAutoInit(remoteEntryId, command, options);
|
|
5368
|
+
writeRuntimeInitStatus(command, enableSsrInit, getHostAutoInitPath(options), options, options ? Object.entries(options.remotes).map(([name, item]) => ({
|
|
5369
|
+
name,
|
|
5370
|
+
entry: item.entry,
|
|
5371
|
+
type: item.type ?? "module"
|
|
5372
|
+
})) : void 0);
|
|
5186
5373
|
}
|
|
5187
5374
|
//#endregion
|
|
5188
5375
|
//#region src/utils/bundleHelpers.ts
|
|
@@ -5517,9 +5704,9 @@ const deduplicateAssets = (filesMap) => {
|
|
|
5517
5704
|
* @param resolveFn - Function to resolve module paths
|
|
5518
5705
|
* @returns Map of file paths to their corresponding share keys
|
|
5519
5706
|
*/
|
|
5520
|
-
const buildFileToShareKeyMap = async (shareKeys, resolveFn) => {
|
|
5707
|
+
const buildFileToShareKeyMap = async (shareKeys, resolveFn, options) => {
|
|
5521
5708
|
const fileToShareKey = /* @__PURE__ */ new Map();
|
|
5522
|
-
const resolutions = await Promise.all(Array.from(shareKeys).map((shareKey) => resolveFn(getPreBuildLibImportId(shareKey)).then((resolution) => ({
|
|
5709
|
+
const resolutions = await Promise.all(Array.from(shareKeys).map((shareKey) => resolveFn(getPreBuildLibImportId(shareKey, options)).then((resolution) => ({
|
|
5523
5710
|
shareKey,
|
|
5524
5711
|
file: resolution?.id?.split("?")[0]
|
|
5525
5712
|
})).catch(() => null)));
|
|
@@ -5725,8 +5912,8 @@ function getRemoteContainerName(remoteKey, remote) {
|
|
|
5725
5912
|
if (entryGlobalName && entryGlobalName !== remoteKey && entryGlobalName !== remote.entry) return entryGlobalName;
|
|
5726
5913
|
return remote.name;
|
|
5727
5914
|
}
|
|
5728
|
-
const Manifest = () => {
|
|
5729
|
-
const mfOptions = getNormalizeModuleFederationOptions();
|
|
5915
|
+
const Manifest = (providedOptions) => {
|
|
5916
|
+
const mfOptions = providedOptions ?? getNormalizeModuleFederationOptions();
|
|
5730
5917
|
const { name, filename, getPublicPath, manifest: manifestOptions, varFilename } = mfOptions;
|
|
5731
5918
|
let mfManifestName = manifestOptions === true ? "mf-manifest.json" : typeof manifestOptions === "object" ? normalizePathForImport(path$1.join(manifestOptions?.filePath || "", manifestOptions?.fileName || "mf-manifest.json")) : void 0;
|
|
5732
5919
|
let mfManifestStatsName = mfManifestName ? getStatsFileName(mfManifestName) : void 0;
|
|
@@ -5853,7 +6040,7 @@ const Manifest = () => {
|
|
|
5853
6040
|
root,
|
|
5854
6041
|
stripKnownJsExtensions: true
|
|
5855
6042
|
});
|
|
5856
|
-
const fileToShareKey = await buildFileToShareKeyMap(getUsedShares(), this.resolve.bind(this));
|
|
6043
|
+
const fileToShareKey = await buildFileToShareKeyMap(getUsedShares(mfOptions), this.resolve.bind(this), mfOptions);
|
|
5857
6044
|
processModuleAssets(Object.fromEntries(Object.entries(bundle).filter(([, file]) => !isTreeShakingProviderChunk(file))), filesMap, (modulePath) => fileToShareKey.get(modulePath));
|
|
5858
6045
|
if (mfOptions.bundleAllCSS) addCssAssetsToAllExports(filesMap, allCssAssets);
|
|
5859
6046
|
filesMap = deduplicateAssets(filesMap);
|
|
@@ -5880,7 +6067,7 @@ const Manifest = () => {
|
|
|
5880
6067
|
* @returns Complete manifest object
|
|
5881
6068
|
*/
|
|
5882
6069
|
function generateMFManifest(preloadMap, disableAssetsAnalyze = false) {
|
|
5883
|
-
const options =
|
|
6070
|
+
const options = mfOptions;
|
|
5884
6071
|
const { name, varFilename } = options;
|
|
5885
6072
|
const resolvedRemoteEntryFile = _command === "serve" ? remoteEntryFile || resolveDevRemoteEntryFileName(filename) : remoteEntryFile;
|
|
5886
6073
|
const remoteEntry = {
|
|
@@ -5898,7 +6085,7 @@ const Manifest = () => {
|
|
|
5898
6085
|
path: "",
|
|
5899
6086
|
type: "var"
|
|
5900
6087
|
} : void 0;
|
|
5901
|
-
const remotes = Array.from(Object.entries(getUsedRemotesMap())).flatMap(([remoteKey, modules]) => {
|
|
6088
|
+
const remotes = Array.from(Object.entries(getUsedRemotesMap(options))).flatMap(([remoteKey, modules]) => {
|
|
5902
6089
|
const remote = options.remotes[remoteKey];
|
|
5903
6090
|
return Array.from(modules).map((moduleKey) => ({
|
|
5904
6091
|
federationContainerName: getRemoteContainerName(remoteKey, remote),
|
|
@@ -5907,11 +6094,11 @@ const Manifest = () => {
|
|
|
5907
6094
|
entry: "*"
|
|
5908
6095
|
}));
|
|
5909
6096
|
});
|
|
5910
|
-
const shared = Array.from(getUsedShares()).flatMap((shareKey) => {
|
|
5911
|
-
const shareItem = getNormalizeShareItem(shareKey);
|
|
6097
|
+
const shared = Array.from(getUsedShares(options)).flatMap((shareKey) => {
|
|
6098
|
+
const shareItem = getNormalizeShareItem(shareKey, options);
|
|
5912
6099
|
if (!shareItem) return [];
|
|
5913
6100
|
const assets = preloadMap[shareKey] || (_command === "serve" && resolvedRemoteEntryFile ? createRemoteEntryAssetMap(resolvedRemoteEntryFile) : createEmptyAssetMap());
|
|
5914
|
-
const treeShakingUsage = getTreeShakingExportUsage(shareKey, shareItem, shareItem.name);
|
|
6101
|
+
const treeShakingUsage = getTreeShakingExportUsage(shareKey, shareItem, shareItem.name, options);
|
|
5915
6102
|
const treeShakingUsedExports = treeShakingUsage?.kind === "exports" ? treeShakingUsage.usedExports : [];
|
|
5916
6103
|
const treeShakingStatus = treeShakingUsage?.kind === "full" ? 0 : 1;
|
|
5917
6104
|
return [{
|
|
@@ -6143,6 +6330,7 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
|
|
|
6143
6330
|
let exposeRemoteDependenciesDirty = true;
|
|
6144
6331
|
let refreshPromise;
|
|
6145
6332
|
let dependencyInvalidationVersion = 0;
|
|
6333
|
+
const isHostAutoInitId = (id) => id.includes(getHostAutoInitPath(options)) || id.includes(getHostAutoInitPath());
|
|
6146
6334
|
function isRemoteImport(source) {
|
|
6147
6335
|
return Object.keys(options.remotes).some((name) => source === name || source.startsWith(name + "/"));
|
|
6148
6336
|
}
|
|
@@ -6232,7 +6420,7 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
|
|
|
6232
6420
|
async resolveId(id, importer) {
|
|
6233
6421
|
if (id === remoteEntryId) return remoteEntryId;
|
|
6234
6422
|
if (id === virtualExposesId) return virtualExposesId;
|
|
6235
|
-
if (_command === "serve" && id
|
|
6423
|
+
if (_command === "serve" && isHostAutoInitId(id)) return id;
|
|
6236
6424
|
if (importer === remoteEntryId && !id.startsWith(".") && !id.startsWith("/") && !id.startsWith("\0") && !id.startsWith("virtual:")) {
|
|
6237
6425
|
const importPath = typeof __filename === "string" ? __filename : fileURLToPath(import.meta.url);
|
|
6238
6426
|
const resolved = await this.resolve(id, importPath, { skipSelf: true });
|
|
@@ -6245,7 +6433,7 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
|
|
|
6245
6433
|
await refreshExposeRemoteDependencies(this);
|
|
6246
6434
|
return generateExposes(options, exposeRemoteDependencies, _command);
|
|
6247
6435
|
}
|
|
6248
|
-
if (_command === "serve" && id
|
|
6436
|
+
if (_command === "serve" && isHostAutoInitId(id)) return id;
|
|
6249
6437
|
},
|
|
6250
6438
|
async transform(code, id) {
|
|
6251
6439
|
return mapCodeToCodeWithSourcemap(await (async () => {
|
|
@@ -6255,7 +6443,7 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
|
|
|
6255
6443
|
await refreshExposeRemoteDependencies(this);
|
|
6256
6444
|
return generateExposes(options, exposeRemoteDependencies, _command);
|
|
6257
6445
|
}
|
|
6258
|
-
if (id
|
|
6446
|
+
if (isHostAutoInitId(id)) {
|
|
6259
6447
|
if (_command === "serve") {
|
|
6260
6448
|
const host = typeof viteConfig.server?.host === "string" && viteConfig.server.host !== "0.0.0.0" ? viteConfig.server.host : "localhost";
|
|
6261
6449
|
const resolvedPublicPath = resolvePublicPath(options, viteConfig.base);
|
|
@@ -6265,7 +6453,7 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
|
|
|
6265
6453
|
return `
|
|
6266
6454
|
const origin = typeof window !== 'undefined' && (${!options.ignoreOrigin}) ? window.origin : ${JSON.stringify(fallbackOrigin)};
|
|
6267
6455
|
const remoteEntryImport = typeof window !== 'undefined' ? origin + ${publicPath} : ${JSON.stringify(ssrRemoteEntry)};
|
|
6268
|
-
${generateHostAutoInitCode("remoteEntryImport", "serve")}
|
|
6456
|
+
${generateHostAutoInitCode("remoteEntryImport", "serve", options)}
|
|
6269
6457
|
`;
|
|
6270
6458
|
}
|
|
6271
6459
|
return code;
|
|
@@ -6360,9 +6548,9 @@ function pluginProxyRemotes_default(options) {
|
|
|
6360
6548
|
if (installedPackageEntry && (importer === void 0 || isNodeModulesImporter(importer))) return installedPackageEntry;
|
|
6361
6549
|
}
|
|
6362
6550
|
const consumer = resolveRemoteConsumer(pluginContext, hasMultiEnvironment);
|
|
6363
|
-
const remoteModule = getRemoteVirtualModule(source, command, enableSsrInit, consumer);
|
|
6364
|
-
addUsedRemote(remoteName, source);
|
|
6365
|
-
refreshHostAutoInit();
|
|
6551
|
+
const remoteModule = getRemoteVirtualModule(source, command, enableSsrInit, consumer, options);
|
|
6552
|
+
addUsedRemote(remoteName, source, options);
|
|
6553
|
+
refreshHostAutoInit(options);
|
|
6366
6554
|
return remoteModule.getImportId();
|
|
6367
6555
|
}
|
|
6368
6556
|
return {
|
|
@@ -6539,7 +6727,7 @@ function excludeSharedSubDependencies(shared) {
|
|
|
6539
6727
|
}
|
|
6540
6728
|
}
|
|
6541
6729
|
function proxySharedModule(options) {
|
|
6542
|
-
const { shared = {} } = options;
|
|
6730
|
+
const { shared = {}, federationOptions } = options;
|
|
6543
6731
|
let _config;
|
|
6544
6732
|
let _command = "serve";
|
|
6545
6733
|
let useDirectReactImport = false;
|
|
@@ -6559,20 +6747,20 @@ function proxySharedModule(options) {
|
|
|
6559
6747
|
};
|
|
6560
6748
|
const getTreeShakingProviderFileName = (pkg, shareItem) => {
|
|
6561
6749
|
if (!shareItem.shareConfig.treeShaking) return void 0;
|
|
6562
|
-
const normalizedOptions = getNormalizeModuleFederationOptions();
|
|
6750
|
+
const normalizedOptions = federationOptions ?? getNormalizeModuleFederationOptions();
|
|
6563
6751
|
const outputDir = normalizedOptions.treeShakingDir ? normalizeTreeShakingOutputPath(normalizedOptions.treeShakingDir) : void 0;
|
|
6564
|
-
const fileName = outputDir ? path$1.posix.join(outputDir, `${getTreeShakingSharedProviderName(pkg)}.js`) : void 0;
|
|
6752
|
+
const fileName = outputDir ? path$1.posix.join(outputDir, `${getTreeShakingSharedProviderName(pkg, federationOptions)}.js`) : void 0;
|
|
6565
6753
|
if (!fileName) return void 0;
|
|
6566
6754
|
return fileName;
|
|
6567
6755
|
};
|
|
6568
6756
|
const emitTreeShakingProvider = (context, pkg, shareItem) => {
|
|
6569
6757
|
if (_command !== "build" || emittedTreeShakingProviders.has(pkg)) return;
|
|
6570
|
-
if (!hasTreeShakingSharedProvider(pkg, shareItem)) return;
|
|
6758
|
+
if (!hasTreeShakingSharedProvider(pkg, shareItem, federationOptions)) return;
|
|
6571
6759
|
const fileName = getTreeShakingProviderFileName(pkg, shareItem);
|
|
6572
6760
|
context.emitFile({
|
|
6573
6761
|
type: "chunk",
|
|
6574
|
-
id: getTreeShakingSharedProviderImportId(pkg),
|
|
6575
|
-
name: getTreeShakingSharedProviderName(pkg),
|
|
6762
|
+
id: getTreeShakingSharedProviderImportId(pkg, federationOptions),
|
|
6763
|
+
name: getTreeShakingSharedProviderName(pkg, federationOptions),
|
|
6576
6764
|
...fileName ? { fileName } : {}
|
|
6577
6765
|
});
|
|
6578
6766
|
emittedTreeShakingProviders.add(pkg);
|
|
@@ -6584,28 +6772,28 @@ function proxySharedModule(options) {
|
|
|
6584
6772
|
configureServer(server) {
|
|
6585
6773
|
devServer = server;
|
|
6586
6774
|
setLocalSharedImportMapInvalidator(() => {
|
|
6587
|
-
const module = server.moduleGraph.getModuleById(getResolvedLocalSharedImportMapId());
|
|
6775
|
+
const module = server.moduleGraph.getModuleById(getResolvedLocalSharedImportMapId(federationOptions));
|
|
6588
6776
|
if (module) server.moduleGraph.invalidateModule(module);
|
|
6589
|
-
});
|
|
6777
|
+
}, federationOptions);
|
|
6590
6778
|
},
|
|
6591
6779
|
resolveId(source) {
|
|
6592
|
-
if (source === getLocalSharedImportMapPath()) return getResolvedLocalSharedImportMapId();
|
|
6780
|
+
if (source === getLocalSharedImportMapPath(federationOptions)) return getResolvedLocalSharedImportMapId(federationOptions);
|
|
6593
6781
|
},
|
|
6594
6782
|
load(id) {
|
|
6595
|
-
if (id === getResolvedLocalSharedImportMapId()) return parsePromise.then((_) => {
|
|
6596
|
-
refreshTreeShakingModules();
|
|
6597
|
-
const providerPackages = new Set([...Object.keys(shared).filter((pkg) => !pkg.endsWith("/")), ...getUsedShares()]);
|
|
6783
|
+
if (id === getResolvedLocalSharedImportMapId(federationOptions)) return parsePromise.then((_) => {
|
|
6784
|
+
refreshTreeShakingModules(federationOptions);
|
|
6785
|
+
const providerPackages = new Set([...Object.keys(shared).filter((pkg) => !pkg.endsWith("/")), ...getUsedShares(federationOptions)]);
|
|
6598
6786
|
for (const pkg of providerPackages) {
|
|
6599
6787
|
const sharedKey = findSharedKeyForSource(pkg, shared);
|
|
6600
6788
|
const shareItem = shared[pkg] || (sharedKey ? shared[sharedKey] : void 0);
|
|
6601
6789
|
if (shareItem) emitTreeShakingProvider(this, pkg, shareItem);
|
|
6602
6790
|
}
|
|
6603
|
-
return generateLocalSharedImportMap();
|
|
6791
|
+
return generateLocalSharedImportMap(federationOptions);
|
|
6604
6792
|
});
|
|
6605
6793
|
},
|
|
6606
6794
|
closeBundle() {
|
|
6607
6795
|
if (devServer) return;
|
|
6608
|
-
setLocalSharedImportMapInvalidator(void 0);
|
|
6796
|
+
setLocalSharedImportMapInvalidator(void 0, federationOptions);
|
|
6609
6797
|
}
|
|
6610
6798
|
},
|
|
6611
6799
|
{
|
|
@@ -6613,8 +6801,8 @@ function proxySharedModule(options) {
|
|
|
6613
6801
|
enforce: "post",
|
|
6614
6802
|
config(config, { command }) {
|
|
6615
6803
|
setPackageDetectionCwd(config.root || process.cwd());
|
|
6616
|
-
setTreeShakingBuildMode(command === "build");
|
|
6617
|
-
resetTreeShakingExports();
|
|
6804
|
+
setTreeShakingBuildMode(command === "build", federationOptions);
|
|
6805
|
+
resetTreeShakingExports(federationOptions);
|
|
6618
6806
|
emittedTreeShakingProviders.clear();
|
|
6619
6807
|
const isVinext = hasPackageDependency("vinext");
|
|
6620
6808
|
const isAstro = hasPackageDependency("astro");
|
|
@@ -6630,29 +6818,29 @@ function proxySharedModule(options) {
|
|
|
6630
6818
|
Object.keys(shared).forEach((key) => {
|
|
6631
6819
|
if (key.endsWith("/")) return;
|
|
6632
6820
|
if (useDirectReactImport && key === "react") {
|
|
6633
|
-
addUsedShares(key);
|
|
6821
|
+
addUsedShares(key, federationOptions);
|
|
6634
6822
|
return;
|
|
6635
6823
|
}
|
|
6636
|
-
writeLoadShareModule(key, shared[key], _command, isRolldown);
|
|
6637
|
-
if (shared[key].shareConfig.import !== false) writePreBuildLibPath(key, shared[key]);
|
|
6638
|
-
addUsedShares(key);
|
|
6824
|
+
writeLoadShareModule(key, shared[key], _command, isRolldown, federationOptions);
|
|
6825
|
+
if (shared[key].shareConfig.import !== false) writePreBuildLibPath(key, shared[key], federationOptions);
|
|
6826
|
+
addUsedShares(key, federationOptions);
|
|
6639
6827
|
});
|
|
6640
|
-
writeLocalSharedImportMap();
|
|
6641
|
-
refreshHostAutoInit();
|
|
6828
|
+
writeLocalSharedImportMap(federationOptions);
|
|
6829
|
+
refreshHostAutoInit(federationOptions);
|
|
6642
6830
|
},
|
|
6643
6831
|
buildStart() {
|
|
6644
6832
|
if (_command !== "build") return;
|
|
6645
|
-
resetTreeShakingExports();
|
|
6833
|
+
resetTreeShakingExports(federationOptions);
|
|
6646
6834
|
emittedTreeShakingProviders.clear();
|
|
6647
|
-
refreshTreeShakingModules();
|
|
6835
|
+
refreshTreeShakingModules(federationOptions);
|
|
6648
6836
|
},
|
|
6649
6837
|
shouldTransformCachedModule() {
|
|
6650
6838
|
return _command === "build" && Object.values(shared).some((share) => !!share.shareConfig.treeShaking);
|
|
6651
6839
|
},
|
|
6652
6840
|
transform(code, id) {
|
|
6653
6841
|
if (_command !== "build" || !Object.keys(shared).some((key) => shared[key].shareConfig.treeShaking)) return;
|
|
6654
|
-
collectTreeShakingImports(code, id, shared, findSharedKeyForSource, recordTreeShakingExports, markTreeShakingPackageUnsafe);
|
|
6655
|
-
refreshTreeShakingModules();
|
|
6842
|
+
collectTreeShakingImports(code, id, shared, findSharedKeyForSource, (sharedKey, exports, request) => recordTreeShakingExports(sharedKey, exports, request, federationOptions), (sharedKey, request) => markTreeShakingPackageUnsafe(sharedKey, request, federationOptions));
|
|
6843
|
+
refreshTreeShakingModules(federationOptions);
|
|
6656
6844
|
}
|
|
6657
6845
|
},
|
|
6658
6846
|
{
|
|
@@ -6712,14 +6900,14 @@ function proxySharedModule(options) {
|
|
|
6712
6900
|
if (shouldSkipTaggedImporterProxy(key, "__loadShare__")) return;
|
|
6713
6901
|
if (shouldSkipTaggedImporterProxy(key, "__prebuild__")) return;
|
|
6714
6902
|
const shareSource = key === "vue" && source.startsWith("vue/dist/") ? key : isNodeModulePath(source) ? getCommonSharedSubpathFromNodeModulePath(source, key) || key : source;
|
|
6715
|
-
const loadSharePath = getLoadShareModulePath(shareSource, useRolldown);
|
|
6903
|
+
const loadSharePath = getLoadShareModulePath(shareSource, useRolldown, federationOptions);
|
|
6716
6904
|
if (!materializedLoadShareSources.has(shareSource)) {
|
|
6717
6905
|
materializedLoadShareSources.add(shareSource);
|
|
6718
|
-
writeLoadShareModule(shareSource, shared[key], _command, useRolldown);
|
|
6719
|
-
if (shared[key].shareConfig.import !== false) writePreBuildLibPath(shareSource, shared[key]);
|
|
6720
|
-
addUsedShares(shareSource);
|
|
6721
|
-
writeLocalSharedImportMap();
|
|
6722
|
-
refreshHostAutoInit();
|
|
6906
|
+
writeLoadShareModule(shareSource, shared[key], _command, useRolldown, federationOptions);
|
|
6907
|
+
if (shared[key].shareConfig.import !== false) writePreBuildLibPath(shareSource, shared[key], federationOptions);
|
|
6908
|
+
addUsedShares(shareSource, federationOptions);
|
|
6909
|
+
writeLocalSharedImportMap(federationOptions);
|
|
6910
|
+
refreshHostAutoInit(federationOptions);
|
|
6723
6911
|
}
|
|
6724
6912
|
return this.resolve(loadSharePath, importer, { skipSelf: true });
|
|
6725
6913
|
}
|
|
@@ -6731,7 +6919,7 @@ function proxySharedModule(options) {
|
|
|
6731
6919
|
if (!source.includes("__prebuild__")) return;
|
|
6732
6920
|
if (source.startsWith(".")) return;
|
|
6733
6921
|
const pkgName = assertModuleFound(PREBUILD_TAG, source).name;
|
|
6734
|
-
const importSource = getPrebuildResolutionSource(pkgName, getPreBuildShareItem(pkgName));
|
|
6922
|
+
const importSource = getPrebuildResolutionSource(pkgName, getPreBuildShareItem(pkgName, federationOptions));
|
|
6735
6923
|
if (_command === "build") return this.resolve(importSource, importer, { skipSelf: true });
|
|
6736
6924
|
const direct = tryResolveFromProjectRoot(importSource);
|
|
6737
6925
|
const directSource = direct && !isNodeModulePath(direct) ? direct : void 0;
|
|
@@ -7025,11 +7213,27 @@ function pluginRemoteNamedExports(options) {
|
|
|
7025
7213
|
//#endregion
|
|
7026
7214
|
//#region src/plugins/pluginSSRRemoteEntry.ts
|
|
7027
7215
|
const MAX_RUNNER_BODY_BYTES = 1024 * 1024;
|
|
7216
|
+
const MAX_RUNNER_START_OFFSET = 1024 * 1024;
|
|
7028
7217
|
const ALLOWED_RUNNER_INVOKE_NAMES = new Set(["fetchModule", "getBuiltins"]);
|
|
7029
7218
|
const VITE_FS_PREFIX = "/@fs/";
|
|
7030
7219
|
function isPlainObject(value) {
|
|
7031
7220
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
7032
7221
|
}
|
|
7222
|
+
function isSafeRunnerFetchModuleOptions(value) {
|
|
7223
|
+
if (!isPlainObject(value)) return false;
|
|
7224
|
+
const allowedKeys = new Set([
|
|
7225
|
+
"cached",
|
|
7226
|
+
"startOffset",
|
|
7227
|
+
"inlineSourceMap"
|
|
7228
|
+
]);
|
|
7229
|
+
for (const [key, option] of Object.entries(value)) {
|
|
7230
|
+
if (!allowedKeys.has(key)) return false;
|
|
7231
|
+
if (key === "startOffset") {
|
|
7232
|
+
if (typeof option !== "number" || !Number.isSafeInteger(option) || option < 0 || option > MAX_RUNNER_START_OFFSET) return false;
|
|
7233
|
+
} else if (typeof option !== "boolean") return false;
|
|
7234
|
+
}
|
|
7235
|
+
return true;
|
|
7236
|
+
}
|
|
7033
7237
|
function stripQueryAndHash(id) {
|
|
7034
7238
|
const queryIndex = id.indexOf("?");
|
|
7035
7239
|
const hashIndex = id.indexOf("#");
|
|
@@ -7067,9 +7271,8 @@ function isPathWithinAllowedDirectories(filePath, allowedDirectories) {
|
|
|
7067
7271
|
}
|
|
7068
7272
|
function isSafeRunnerFetchModuleId(id, config) {
|
|
7069
7273
|
if (typeof id !== "string" || !id) return false;
|
|
7070
|
-
const
|
|
7071
|
-
|
|
7072
|
-
if (!decoded || rawDecoded.startsWith("\0") || decoded.startsWith("virtual:")) return !!decoded;
|
|
7274
|
+
const decoded = decodeViteId(id).replace(/^\0+/, "");
|
|
7275
|
+
if (!decoded || decoded.startsWith("virtual:")) return !!decoded;
|
|
7073
7276
|
if (decoded.startsWith("file://")) try {
|
|
7074
7277
|
const filePath = decodeURIComponent(new URL(decoded).pathname);
|
|
7075
7278
|
return path$1.isAbsolute(filePath) && isPathWithinAllowedDirectories(filePath, getRunnerAllowedDirectories(config));
|
|
@@ -7101,7 +7304,7 @@ function isRunnerInvokePayload(payload, config) {
|
|
|
7101
7304
|
if (name === "getBuiltins") return args.length === 0;
|
|
7102
7305
|
if (args.length < 1 || args.length > 3) return false;
|
|
7103
7306
|
const [id, importer, opts] = args;
|
|
7104
|
-
return isSafeRunnerFetchModuleId(id, config) && (importer === void 0 || importer === null || isSafeRunnerFetchModuleId(importer, config)) && (opts === void 0 ||
|
|
7307
|
+
return isSafeRunnerFetchModuleId(id, config) && (importer === void 0 || importer === null || isSafeRunnerFetchModuleId(importer, config)) && (opts === void 0 || isSafeRunnerFetchModuleOptions(opts));
|
|
7105
7308
|
}
|
|
7106
7309
|
function readBoundedRunnerBody(req, res) {
|
|
7107
7310
|
return new Promise((resolve) => {
|
|
@@ -7217,14 +7420,6 @@ function pluginSSRRemoteEntry(options) {
|
|
|
7217
7420
|
const clientEnv = server.environments?.client;
|
|
7218
7421
|
const runnerEnv = typeof ssrEnv?.hot?.handleInvoke === "function" ? ssrEnv : typeof clientEnv?.hot?.handleInvoke === "function" ? clientEnv : void 0;
|
|
7219
7422
|
if (typeof (ssrEnv?.fetchModule ?? clientEnv?.fetchModule) === "function" && runnerEnv) server.middlewares.use("/__mf_runner__", async (req, res) => {
|
|
7220
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
7221
|
-
if (req.method === "OPTIONS") {
|
|
7222
|
-
res.setHeader("Access-Control-Allow-Methods", "POST");
|
|
7223
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
7224
|
-
res.statusCode = 204;
|
|
7225
|
-
res.end();
|
|
7226
|
-
return;
|
|
7227
|
-
}
|
|
7228
7423
|
if (req.method !== "POST") {
|
|
7229
7424
|
res.statusCode = 405;
|
|
7230
7425
|
res.end("Method not allowed");
|
|
@@ -7381,8 +7576,8 @@ function isWithinDirectory(filePath, directory) {
|
|
|
7381
7576
|
}
|
|
7382
7577
|
//#endregion
|
|
7383
7578
|
//#region src/plugins/pluginVarRemoteEntry.ts
|
|
7384
|
-
const VarRemoteEntry = () => {
|
|
7385
|
-
const mfOptions = getNormalizeModuleFederationOptions();
|
|
7579
|
+
const VarRemoteEntry = (providedOptions) => {
|
|
7580
|
+
const mfOptions = providedOptions ?? getNormalizeModuleFederationOptions();
|
|
7386
7581
|
const { name, varFilename, filename } = mfOptions;
|
|
7387
7582
|
let viteConfig;
|
|
7388
7583
|
return [{
|
|
@@ -7434,7 +7629,7 @@ const VarRemoteEntry = () => {
|
|
|
7434
7629
|
* @returns Complete "var" remoteEntry.js file source
|
|
7435
7630
|
*/
|
|
7436
7631
|
function generateVarRemoteEntry(remoteEntryFile) {
|
|
7437
|
-
const { name, varFilename } =
|
|
7632
|
+
const { name, varFilename } = mfOptions;
|
|
7438
7633
|
const isValidName = isValidVarName(name);
|
|
7439
7634
|
return `
|
|
7440
7635
|
${isValidName ? `var ${name};` : ""}
|
|
@@ -7655,6 +7850,43 @@ function canResolveSharedSubpath(subpath, projectRoot) {
|
|
|
7655
7850
|
}
|
|
7656
7851
|
}
|
|
7657
7852
|
/**
|
|
7853
|
+
* Vite's dependency scanner cannot see through the virtual loadShare modules
|
|
7854
|
+
* generated for shared packages. As a result, dependencies of a linked/shared
|
|
7855
|
+
* package may be discovered one request at a time and each discovery starts a
|
|
7856
|
+
* new optimizer pass. Seed the optimizer with the complete dependency graph
|
|
7857
|
+
* before the first request instead.
|
|
7858
|
+
*
|
|
7859
|
+
* Vite then resolves the package's own dependency graph using its normal
|
|
7860
|
+
* scanner, preserving package and peer-dependency resolution semantics.
|
|
7861
|
+
*/
|
|
7862
|
+
function includeLinkedSharedEntries(optimizeDeps, shared, projectRoot, exposes, outDir) {
|
|
7863
|
+
const additions = /* @__PURE__ */ new Set();
|
|
7864
|
+
const entries = new Set(Array.isArray(optimizeDeps.entries) ? optimizeDeps.entries : optimizeDeps.entries ? [optimizeDeps.entries] : [
|
|
7865
|
+
"**/*.html",
|
|
7866
|
+
"!**/node_modules/**",
|
|
7867
|
+
`!**/${outDir.replace(/\\/g, "/")}/**`,
|
|
7868
|
+
"!**/__tests__/**",
|
|
7869
|
+
"!**/coverage/**"
|
|
7870
|
+
]);
|
|
7871
|
+
for (const [packageName, share] of Object.entries(shared ?? {})) {
|
|
7872
|
+
if (share?.shareConfig?.import === false) continue;
|
|
7873
|
+
const installed = getInstalledPackageJson(packageName, { cwd: projectRoot });
|
|
7874
|
+
if (!installed || installed.dir.replaceAll("\\", "/").includes("/node_modules/")) continue;
|
|
7875
|
+
const entry = getInstalledPackageEntry(packageName, { cwd: projectRoot });
|
|
7876
|
+
if (entry && existsSync(entry)) additions.add(entry);
|
|
7877
|
+
}
|
|
7878
|
+
for (const expose of Object.values(exposes ?? {})) {
|
|
7879
|
+
const source = expose.import;
|
|
7880
|
+
if (source.startsWith(".") || path$1.isAbsolute(source)) {
|
|
7881
|
+
const entry = path$1.resolve(projectRoot, source);
|
|
7882
|
+
if (existsSync(entry)) additions.add(entry);
|
|
7883
|
+
}
|
|
7884
|
+
}
|
|
7885
|
+
if (additions.size === 0) return;
|
|
7886
|
+
for (const entry of additions) entries.add(entry);
|
|
7887
|
+
optimizeDeps.entries = [...entries];
|
|
7888
|
+
}
|
|
7889
|
+
/**
|
|
7658
7890
|
* Plugin that runs FIRST to register generated virtual modules in the config hook.
|
|
7659
7891
|
* This prevents 504 "Outdated Optimize Dep" errors by ensuring ids are known
|
|
7660
7892
|
* before Vite's optimization phase.
|
|
@@ -7670,15 +7902,10 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
7670
7902
|
const root = config.root || process.cwd();
|
|
7671
7903
|
setPackageDetectionCwd(root);
|
|
7672
7904
|
const isVinext = hasPackageDependency("vinext");
|
|
7673
|
-
|
|
7674
|
-
name: key,
|
|
7675
|
-
entry: r.entry,
|
|
7676
|
-
type: r.type ?? "module"
|
|
7677
|
-
})));
|
|
7678
|
-
initVirtualModules(_command, getRemoteEntryId(options));
|
|
7905
|
+
initVirtualModules(_command, getRemoteEntryId(options), false, options);
|
|
7679
7906
|
const isRolldown = getIsRolldown(this);
|
|
7680
7907
|
if (remotes && Object.keys(remotes).length > 0) {
|
|
7681
|
-
for (const key of Object.keys(remotes)) addUsedRemote(key, key);
|
|
7908
|
+
for (const key of Object.keys(remotes)) addUsedRemote(key, key, options);
|
|
7682
7909
|
if (_command === "serve") {
|
|
7683
7910
|
config.optimizeDeps = config.optimizeDeps || {};
|
|
7684
7911
|
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
@@ -7698,11 +7925,11 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
7698
7925
|
name: "module-federation:optimize-shared-resolver",
|
|
7699
7926
|
load(id) {
|
|
7700
7927
|
if (id !== "module-federation:optimized-require-react") return;
|
|
7701
|
-
const loadSharePath = getLoadShareModulePath("react", isRolldown);
|
|
7928
|
+
const loadSharePath = getLoadShareModulePath("react", isRolldown, options);
|
|
7702
7929
|
const source = JSON.stringify(loadSharePath);
|
|
7703
7930
|
return "import * as __mfShared from " + source + ";\nexport * from " + source + ";\nexport default __mfShared.default ?? __mfShared;";
|
|
7704
7931
|
},
|
|
7705
|
-
resolveId(source, importer,
|
|
7932
|
+
resolveId(source, importer, resolveOptions) {
|
|
7706
7933
|
if (createViteEncodedIdPrefixRegExp("virtual:mf:").test(source)) return {
|
|
7707
7934
|
id: source,
|
|
7708
7935
|
external: true
|
|
@@ -7713,19 +7940,19 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
7713
7940
|
if (isAssetLikeImport(source)) return;
|
|
7714
7941
|
const shareItem = shared[key];
|
|
7715
7942
|
const isReactSingleton = source === "react" && key === "react" && shareItem.shareConfig?.singleton === true;
|
|
7716
|
-
const isReactRequire =
|
|
7717
|
-
if (
|
|
7943
|
+
const isReactRequire = resolveOptions?.kind?.startsWith("require") && isReactSingleton;
|
|
7944
|
+
if (resolveOptions?.kind?.startsWith("require") && !isReactSingleton) return;
|
|
7718
7945
|
if (isCommonJsImporter(importer) && !isReactSingleton) return;
|
|
7719
7946
|
if (isReactRequire) {
|
|
7720
|
-
writeLoadShareModule(source, shareItem, _command, isRolldown);
|
|
7721
|
-
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(source, shareItem);
|
|
7722
|
-
addUsedShares(source);
|
|
7947
|
+
writeLoadShareModule(source, shareItem, _command, isRolldown, options);
|
|
7948
|
+
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(source, shareItem, options);
|
|
7949
|
+
addUsedShares(source, options);
|
|
7723
7950
|
return { id: "module-federation:optimized-require-react" };
|
|
7724
7951
|
}
|
|
7725
|
-
const loadSharePath = getLoadShareModulePath(source, isRolldown);
|
|
7726
|
-
writeLoadShareModule(source, shareItem, _command, isRolldown);
|
|
7727
|
-
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(source, shareItem);
|
|
7728
|
-
addUsedShares(source);
|
|
7952
|
+
const loadSharePath = getLoadShareModulePath(source, isRolldown, options);
|
|
7953
|
+
writeLoadShareModule(source, shareItem, _command, isRolldown, options);
|
|
7954
|
+
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(source, shareItem, options);
|
|
7955
|
+
addUsedShares(source, options);
|
|
7729
7956
|
return {
|
|
7730
7957
|
id: loadSharePath,
|
|
7731
7958
|
external: true
|
|
@@ -7759,15 +7986,15 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
7759
7986
|
const key = findSharedKey(args.path, shared);
|
|
7760
7987
|
if (!key) return;
|
|
7761
7988
|
const shareItem = shared[key];
|
|
7762
|
-
const
|
|
7763
|
-
writeLoadShareModule(args.path, shareItem, _command, isRolldown);
|
|
7764
|
-
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(args.path, shareItem);
|
|
7765
|
-
addUsedShares(args.path);
|
|
7989
|
+
const loadSharePath = getLoadShareModulePath(args.path, isRolldown, options);
|
|
7990
|
+
writeLoadShareModule(args.path, shareItem, _command, isRolldown, options);
|
|
7991
|
+
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(args.path, shareItem, options);
|
|
7992
|
+
addUsedShares(args.path, options);
|
|
7766
7993
|
return {
|
|
7767
7994
|
loader: "js",
|
|
7768
7995
|
resolveDir: root,
|
|
7769
|
-
contents: `import * as __mfShared from ${JSON.stringify(
|
|
7770
|
-
export * from ${JSON.stringify(
|
|
7996
|
+
contents: `import * as __mfShared from ${JSON.stringify(loadSharePath)};
|
|
7997
|
+
export * from ${JSON.stringify(loadSharePath)};
|
|
7771
7998
|
export default __mfShared.default ?? __mfShared;`
|
|
7772
7999
|
};
|
|
7773
8000
|
});
|
|
@@ -7783,7 +8010,7 @@ export default __mfShared.default ?? __mfShared;`
|
|
|
7783
8010
|
optimizeDeps.include ??= [];
|
|
7784
8011
|
optimizeDeps.exclude ??= [];
|
|
7785
8012
|
for (const subpath of getCommonSharedSubpaths(key)) {
|
|
7786
|
-
writePreBuildLibPath(subpath, shareItem);
|
|
8013
|
+
writePreBuildLibPath(subpath, shareItem, options);
|
|
7787
8014
|
if (canResolveSharedSubpath(subpath, root)) optimizeDeps.include.push(subpath);
|
|
7788
8015
|
else optimizeDeps.exclude.push(subpath);
|
|
7789
8016
|
}
|
|
@@ -7791,13 +8018,13 @@ export default __mfShared.default ?? __mfShared;`
|
|
|
7791
8018
|
continue;
|
|
7792
8019
|
}
|
|
7793
8020
|
if (isVinext && key === "react") {
|
|
7794
|
-
addUsedShares(key);
|
|
8021
|
+
addUsedShares(key, options);
|
|
7795
8022
|
continue;
|
|
7796
8023
|
}
|
|
7797
|
-
getLoadShareModulePath(key, isRolldown);
|
|
7798
|
-
writeLoadShareModule(key, shareItem, _command, isRolldown);
|
|
7799
|
-
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(key, shareItem);
|
|
7800
|
-
addUsedShares(key);
|
|
8024
|
+
getLoadShareModulePath(key, isRolldown, options);
|
|
8025
|
+
writeLoadShareModule(key, shareItem, _command, isRolldown, options);
|
|
8026
|
+
if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(key, shareItem, options);
|
|
8027
|
+
addUsedShares(key, options);
|
|
7801
8028
|
if (_command === "serve" && shareItem.shareConfig?.import !== false) {
|
|
7802
8029
|
const optimizeDeps = config.optimizeDeps ??= {};
|
|
7803
8030
|
optimizeDeps.include ??= [];
|
|
@@ -7807,16 +8034,20 @@ export default __mfShared.default ?? __mfShared;`
|
|
|
7807
8034
|
else if (shouldBypassOptimizeDep) optimizeDeps.exclude.push(key);
|
|
7808
8035
|
else optimizeDeps.include.push(key);
|
|
7809
8036
|
for (const subpath of getCommonSharedSubpaths(key)) {
|
|
7810
|
-
getLoadShareModulePath(subpath, isRolldown);
|
|
7811
|
-
writeLoadShareModule(subpath, shareItem, _command, isRolldown);
|
|
7812
|
-
writePreBuildLibPath(subpath, shareItem);
|
|
7813
|
-
addUsedShares(subpath);
|
|
8037
|
+
getLoadShareModulePath(subpath, isRolldown, options);
|
|
8038
|
+
writeLoadShareModule(subpath, shareItem, _command, isRolldown, options);
|
|
8039
|
+
writePreBuildLibPath(subpath, shareItem, options);
|
|
8040
|
+
addUsedShares(subpath, options);
|
|
7814
8041
|
if (canResolveSharedSubpath(subpath, root)) optimizeDeps.include.push(subpath);
|
|
7815
8042
|
else optimizeDeps.exclude.push(subpath);
|
|
7816
8043
|
}
|
|
7817
8044
|
}
|
|
7818
8045
|
}
|
|
7819
|
-
writeLocalSharedImportMap();
|
|
8046
|
+
writeLocalSharedImportMap(options);
|
|
8047
|
+
}
|
|
8048
|
+
if (_command === "serve") {
|
|
8049
|
+
config.optimizeDeps ??= {};
|
|
8050
|
+
includeLinkedSharedEntries(config.optimizeDeps, shared, root, options.exposes, config.build?.outDir ?? "dist");
|
|
7820
8051
|
}
|
|
7821
8052
|
},
|
|
7822
8053
|
configResolved(config) {
|
|
@@ -7884,8 +8115,9 @@ function federation(mfUserOptions) {
|
|
|
7884
8115
|
command,
|
|
7885
8116
|
isRolldown: getIsRolldown(this),
|
|
7886
8117
|
findSharedKey,
|
|
7887
|
-
addUsedShares,
|
|
7888
|
-
writeLocalSharedImportMap
|
|
8118
|
+
addUsedShares: (pkg) => addUsedShares(pkg, options),
|
|
8119
|
+
writeLocalSharedImportMap: () => writeLocalSharedImportMap(options),
|
|
8120
|
+
federationOptions: options
|
|
7889
8121
|
});
|
|
7890
8122
|
virtualModule = VirtualModule.findById(id);
|
|
7891
8123
|
}
|
|
@@ -7926,7 +8158,7 @@ function federation(mfUserOptions) {
|
|
|
7926
8158
|
},
|
|
7927
8159
|
configResolved() {
|
|
7928
8160
|
const ssrCapabilities = getSsrCapabilities(parseInt(version, 10), command, Object.keys(options.remotes).length > 0);
|
|
7929
|
-
initVirtualModules(command, remoteEntryId, ssrCapabilities.enableSsrInitBootstrap);
|
|
8161
|
+
initVirtualModules(command, remoteEntryId, ssrCapabilities.enableSsrInitBootstrap, options);
|
|
7930
8162
|
}
|
|
7931
8163
|
},
|
|
7932
8164
|
aliasToArrayPlugin_default,
|
|
@@ -7949,18 +8181,21 @@ function federation(mfUserOptions) {
|
|
|
7949
8181
|
...addEntry({
|
|
7950
8182
|
entryName: "remoteEntry",
|
|
7951
8183
|
entryPath: remoteEntryId,
|
|
7952
|
-
fileName: filename
|
|
8184
|
+
fileName: filename,
|
|
8185
|
+
federationOptions: options
|
|
7953
8186
|
}),
|
|
7954
8187
|
...addEntry({
|
|
7955
8188
|
entryName: "hostInit",
|
|
7956
|
-
entryPath: () => getHostAutoInitPath(),
|
|
8189
|
+
entryPath: () => getHostAutoInitPath(options),
|
|
7957
8190
|
inject: hostInitInjectLocation,
|
|
7958
8191
|
forceClientInjected: Object.keys(options.exposes).length > 0,
|
|
7959
|
-
skipTransformFor: Object.values(options.exposes).map((expose) => expose.import)
|
|
8192
|
+
skipTransformFor: Object.values(options.exposes).map((expose) => expose.import),
|
|
8193
|
+
federationOptions: options
|
|
7960
8194
|
}),
|
|
7961
8195
|
...addEntry({
|
|
7962
8196
|
entryName: "virtualExposes",
|
|
7963
|
-
entryPath: virtualExposesId
|
|
8197
|
+
entryPath: virtualExposesId,
|
|
8198
|
+
federationOptions: options
|
|
7964
8199
|
}),
|
|
7965
8200
|
pluginProxyRemoteEntry_default({
|
|
7966
8201
|
options,
|
|
@@ -7970,20 +8205,23 @@ function federation(mfUserOptions) {
|
|
|
7970
8205
|
pluginProxyRemotes_default(options),
|
|
7971
8206
|
pluginRemoteNamedExports(options),
|
|
7972
8207
|
...pluginModuleParseEnd_default((id) => {
|
|
7973
|
-
return id.includes(getHostAutoInitImportId()) || id.includes(remoteEntryId) || id.includes(virtualExposesId) || id.includes(getLocalSharedImportMapPath()) || id.includes("__loadShare__") || id.includes("__prebuild__") || id.includes("__treeShakingProvider__") || id.includes("__mf_tree_shaking_graph__");
|
|
8208
|
+
return id.includes(getHostAutoInitImportId(options)) || id.includes(remoteEntryId) || id.includes(virtualExposesId) || id.includes(getLocalSharedImportMapPath(options)) || id.includes("__loadShare__") || id.includes("__prebuild__") || id.includes("__treeShakingProvider__") || id.includes("__mf_tree_shaking_graph__");
|
|
7974
8209
|
}, {
|
|
7975
8210
|
moduleParseTimeout: options.moduleParseTimeout,
|
|
7976
8211
|
moduleParseIdleTimeout: options.moduleParseIdleTimeout,
|
|
7977
8212
|
exposedModuleImports: Object.values(options.exposes).map((expose) => expose.import)
|
|
7978
8213
|
}),
|
|
7979
|
-
...proxySharedModule({
|
|
8214
|
+
...proxySharedModule({
|
|
8215
|
+
shared,
|
|
8216
|
+
federationOptions: options
|
|
8217
|
+
}),
|
|
7980
8218
|
{
|
|
7981
8219
|
name: "module-federation-esm-shims",
|
|
7982
8220
|
enforce: "pre",
|
|
7983
8221
|
apply: "build",
|
|
7984
8222
|
config(config) {
|
|
7985
8223
|
isSsrBuild = config.build?.ssr === true;
|
|
7986
|
-
const runtimeInitId =
|
|
8224
|
+
const runtimeInitId = getRuntimeInitStatusImportId(options);
|
|
7987
8225
|
config.build = config.build || {};
|
|
7988
8226
|
if (config.build.modulePreload !== false) {
|
|
7989
8227
|
const currentModulePreload = config.build.modulePreload && typeof config.build.modulePreload === "object" ? config.build.modulePreload : {};
|
|
@@ -8030,7 +8268,7 @@ function federation(mfUserOptions) {
|
|
|
8030
8268
|
mfWarn("Ignoring `output.manualChunks` because it conflicts with module federation. Module federation transforms shared dependency imports with async init wrappers, and grouping these transformed modules into a single chunk creates circular async dependencies that cause the application to silently hang.");
|
|
8031
8269
|
}
|
|
8032
8270
|
const mfChunkName = function(id) {
|
|
8033
|
-
if (id.includes(runtimeInitId)) return "runtimeInit";
|
|
8271
|
+
if (id.includes(runtimeInitId) || id.includes("__mf_v__runtimeInit__mf_v__")) return "runtimeInit";
|
|
8034
8272
|
if (id.includes("__loadShare__")) {
|
|
8035
8273
|
const match = id.match(/([^/\\]+__loadShare__[^/\\]+)/);
|
|
8036
8274
|
return match ? match[1] : "loadShare";
|
|
@@ -8227,9 +8465,9 @@ function federation(mfUserOptions) {
|
|
|
8227
8465
|
if (options.target && config.define["ENV_TARGET"] !== JSON.stringify(options.target)) mfWarn(`ENV_TARGET define (${config.define["ENV_TARGET"]}) differs from target option ("${options.target}"). ENV_TARGET will not be overridden.`);
|
|
8228
8466
|
}
|
|
8229
8467
|
},
|
|
8230
|
-
...Manifest(),
|
|
8468
|
+
...Manifest(options),
|
|
8231
8469
|
...pluginSSRRemoteEntry(options),
|
|
8232
|
-
...VarRemoteEntry(),
|
|
8470
|
+
...VarRemoteEntry(options),
|
|
8233
8471
|
{
|
|
8234
8472
|
name: "module-federation-vinext-fix-rsc-preload-as",
|
|
8235
8473
|
enforce: "post",
|