@module-federation/vite 1.16.7 → 1.16.9
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 +8 -2
- package/lib/index.js +293 -118
- package/lib/{pluginDts-Cpmdbbr0.js → pluginDts-CrSsDUnT.js} +2 -1
- package/lib/utils/ssrEntryLoader.js +89 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@module-federation/vite)
|
|
4
4
|
|
|
5
|
+
## Vite and VoidZero recommend this plugin
|
|
6
|
+
|
|
7
|
+
[Read the announcement](https://www.linkedin.com/posts/voidzero_github-module-federationvite-vite-plugin-activity-7449452398202241024-JyAL).
|
|
8
|
+
|
|
5
9
|
## Reason why 🤔
|
|
6
10
|
|
|
7
11
|
[Microservices](https://martinfowler.com/articles/microservices.html) nowadays is a well-known concept and maybe you are using it in your current company.
|
|
@@ -47,7 +51,7 @@ pnpm run multi-example
|
|
|
47
51
|
|
|
48
52
|
## Getting started 🚀
|
|
49
53
|
|
|
50
|
-
[https://module-federation.io/
|
|
54
|
+
[https://module-federation.io/integrations/build-tool/vite](https://module-federation.io/integrations/build-tool/vite)
|
|
51
55
|
|
|
52
56
|
With **@module-federation/vite**, the process becomes delightfully simple, you will only find the differences from a normal Vite configuration.
|
|
53
57
|
|
|
@@ -143,7 +147,9 @@ export default defineConfig({
|
|
|
143
147
|
// Optional parameter that controls where the host initialization script is injected.
|
|
144
148
|
// By default, it is injected into the index.html file.
|
|
145
149
|
// You can set this to "entry" to inject it into the entry script instead.
|
|
146
|
-
//
|
|
150
|
+
// Recommended for SSR hosts without index.html (Nitro, TanStack Start) so
|
|
151
|
+
// initHost() completes before hydrateRoot and @module-federation/bridge-react
|
|
152
|
+
// remotes render on first paint.
|
|
147
153
|
hostInitInjectLocation: "html", // or "entry"
|
|
148
154
|
// Controls whether all CSS assets from the bundle should be added to every exposed module.
|
|
149
155
|
// When false (default), the plugin will not process any CSS assets.
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as mfWarn, a as getIsRolldown, c as getPackageNameFromNodeModulePath, d as isNuxtProjectRoot, f as packageNameDecode, g as createModuleFederationError, h as setPackageDetectionCwd, i as getInstalledPackageJson, l as getSharedCacheKey, m as resolveImportPath, o as getPackageDetectionCwd, p as packageNameEncode, r as getInstalledPackageEntry, s as getPackageName, u as hasPackageDependency, v as normalizePathForImport, y as rebaseImport } from "./pluginDts-
|
|
1
|
+
import { _ as mfWarn, a as getIsRolldown, c as getPackageNameFromNodeModulePath, d as isNuxtProjectRoot, f as packageNameDecode, g as createModuleFederationError, h as setPackageDetectionCwd, i as getInstalledPackageJson, l as getSharedCacheKey, m as resolveImportPath, o as getPackageDetectionCwd, p as packageNameEncode, r as getInstalledPackageEntry, s as getPackageName, u as hasPackageDependency, v as normalizePathForImport, y as rebaseImport } from "./pluginDts-CrSsDUnT.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import * as fs$1 from "fs";
|
|
4
4
|
import { existsSync, readFileSync, realpathSync, statSync, writeFileSync } from "fs";
|
|
@@ -171,6 +171,71 @@ function injectEntryScript(html, initSrc) {
|
|
|
171
171
|
return html.replace("<head>", `<head><script type="module" src=${JSON.stringify(src)}><\/script>`);
|
|
172
172
|
}
|
|
173
173
|
//#endregion
|
|
174
|
+
//#region src/utils/pathNormalization.ts
|
|
175
|
+
const COMMON_SHARED_SUBPATHS = {
|
|
176
|
+
react: [
|
|
177
|
+
"react/jsx-runtime",
|
|
178
|
+
"react/jsx-dev-runtime",
|
|
179
|
+
"react/compiler-runtime"
|
|
180
|
+
],
|
|
181
|
+
"react-dom": [
|
|
182
|
+
"react-dom/client",
|
|
183
|
+
"react-dom/server",
|
|
184
|
+
"react-dom/server.browser"
|
|
185
|
+
],
|
|
186
|
+
"solid-js": [
|
|
187
|
+
"solid-js/web",
|
|
188
|
+
"solid-js/store",
|
|
189
|
+
"solid-js/html",
|
|
190
|
+
"solid-js/h"
|
|
191
|
+
],
|
|
192
|
+
zustand: ["zustand/vanilla", "zustand/react"]
|
|
193
|
+
};
|
|
194
|
+
function removeTrailingSlash(value) {
|
|
195
|
+
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
196
|
+
}
|
|
197
|
+
function ensureTrailingSlash(value) {
|
|
198
|
+
return `${removeTrailingSlash(value)}/`;
|
|
199
|
+
}
|
|
200
|
+
function getBasePath$1(base) {
|
|
201
|
+
return removeTrailingSlash(base || "/");
|
|
202
|
+
}
|
|
203
|
+
function isNuxtClientBase(base) {
|
|
204
|
+
return getBasePath$1(base).endsWith("/_nuxt");
|
|
205
|
+
}
|
|
206
|
+
function normalizeNodeModulePath(source) {
|
|
207
|
+
return source.replace(/\\/g, "/").replace(/\?.*$/, "");
|
|
208
|
+
}
|
|
209
|
+
function isNodeModulePath(source) {
|
|
210
|
+
return source.includes("/node_modules/") || source.includes("\\node_modules\\");
|
|
211
|
+
}
|
|
212
|
+
function filterId(id) {
|
|
213
|
+
return typeof id === "string" && !id.includes("\0");
|
|
214
|
+
}
|
|
215
|
+
function getMatchingNodeModuleSubpath(source, candidates) {
|
|
216
|
+
const normalized = normalizeNodeModulePath(source);
|
|
217
|
+
return [...candidates].sort((a, b) => b.length - a.length).find((candidate) => normalized.includes(`/node_modules/${candidate}/`) || normalized.includes(`/node_modules/${candidate}.`));
|
|
218
|
+
}
|
|
219
|
+
function getCommonSharedSubpaths(sharedKey) {
|
|
220
|
+
return COMMON_SHARED_SUBPATHS[removeTrailingSlash(sharedKey)] || [];
|
|
221
|
+
}
|
|
222
|
+
function getCommonSharedSubpathFromNodeModulePath(source, sharedKey) {
|
|
223
|
+
return getMatchingNodeModuleSubpath(source, getCommonSharedSubpaths(removeTrailingSlash(sharedKey)));
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Resolves the public path for remote entries
|
|
227
|
+
* @param options - Module Federation options
|
|
228
|
+
* @param viteBase - Vite's base config value
|
|
229
|
+
* @param originalBase - Original base config before any transformations
|
|
230
|
+
* @returns The resolved public path
|
|
231
|
+
*/
|
|
232
|
+
function resolvePublicPath(options, viteBase, originalBase) {
|
|
233
|
+
if (options.publicPath && options.publicPath !== "auto") return options.publicPath;
|
|
234
|
+
if (!originalBase) return "auto";
|
|
235
|
+
if (viteBase) return ensureTrailingSlash(viteBase);
|
|
236
|
+
return "auto";
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
174
239
|
//#region src/utils/normalizeModuleFederationOptions.ts
|
|
175
240
|
const INTERNAL_NAME_PREFIX = "__mfe_internal__";
|
|
176
241
|
function toInternalModuleFederationName(name) {
|
|
@@ -257,7 +322,9 @@ function getLitExportSubpathShares(sharedName) {
|
|
|
257
322
|
}
|
|
258
323
|
function normalizeShareItem(key, shareItem) {
|
|
259
324
|
const isImportFalse = typeof shareItem === "object" && shareItem.import === false;
|
|
260
|
-
const
|
|
325
|
+
const explicitVersion = typeof shareItem === "object" ? shareItem.version : void 0;
|
|
326
|
+
const inferredVersion = typeof shareItem === "object" ? inferVersionFromRequiredVersion(shareItem.requiredVersion) : void 0;
|
|
327
|
+
const version = explicitVersion || searchPackageVersion(key) || inferredVersion;
|
|
261
328
|
if (typeof shareItem === "string") return {
|
|
262
329
|
name: shareItem,
|
|
263
330
|
version,
|
|
@@ -282,6 +349,11 @@ function normalizeShareItem(key, shareItem) {
|
|
|
282
349
|
}
|
|
283
350
|
};
|
|
284
351
|
}
|
|
352
|
+
function normalizeSharedKey(key) {
|
|
353
|
+
if (!key.endsWith("/")) return key;
|
|
354
|
+
const baseKey = key.slice(0, -1);
|
|
355
|
+
return getCommonSharedSubpaths(baseKey).length > 0 ? baseKey : key;
|
|
356
|
+
}
|
|
285
357
|
function normalizeShared(shared) {
|
|
286
358
|
explicitSharedKeys = /* @__PURE__ */ new Set();
|
|
287
359
|
if (!shared) {
|
|
@@ -306,16 +378,18 @@ function normalizeShared(shared) {
|
|
|
306
378
|
const sourceEntries = [];
|
|
307
379
|
if (Array.isArray(shared)) shared.forEach((key) => {
|
|
308
380
|
if (isModuleFederationRuntimePackage(key)) return;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
381
|
+
const normalizedKey = normalizeSharedKey(key);
|
|
382
|
+
result[normalizedKey] = normalizeShareItem(normalizedKey, normalizedKey);
|
|
383
|
+
explicitSharedKeys.add(normalizedKey);
|
|
384
|
+
sourceEntries.push([normalizedKey, normalizedKey]);
|
|
312
385
|
});
|
|
313
386
|
else if (typeof shared === "object") Object.keys(shared).forEach((key) => {
|
|
314
387
|
if (isModuleFederationRuntimePackage(key)) return;
|
|
388
|
+
const normalizedKey = normalizeSharedKey(key);
|
|
315
389
|
const value = shared[key];
|
|
316
|
-
result[
|
|
317
|
-
explicitSharedKeys.add(
|
|
318
|
-
sourceEntries.push([
|
|
390
|
+
result[normalizedKey] = normalizeShareItem(normalizedKey, value);
|
|
391
|
+
explicitSharedKeys.add(normalizedKey);
|
|
392
|
+
sourceEntries.push([normalizedKey, value]);
|
|
319
393
|
});
|
|
320
394
|
sourceEntries.forEach(([key, value]) => {
|
|
321
395
|
for (const subpathShare of getLitExportSubpathShares(key)) {
|
|
@@ -985,6 +1059,49 @@ function isWorkspacePackageEntry(pkg, resolved) {
|
|
|
985
1059
|
fromResolvedEntry: resolved
|
|
986
1060
|
});
|
|
987
1061
|
}
|
|
1062
|
+
function getWorkspacePackageJson(pkg) {
|
|
1063
|
+
const resolved = getLocalProviderImportPath(pkg) || getProjectResolvedImportPath(pkg);
|
|
1064
|
+
if (!isWorkspacePackageEntry(pkg, resolved)) return;
|
|
1065
|
+
return getInstalledPackageJson(pkg, {
|
|
1066
|
+
packageName: getPackageName(pkg),
|
|
1067
|
+
fromResolvedEntry: resolved
|
|
1068
|
+
})?.packageJson;
|
|
1069
|
+
}
|
|
1070
|
+
function getDependencyNames(packageJson) {
|
|
1071
|
+
if (!packageJson) return [];
|
|
1072
|
+
const names = /* @__PURE__ */ new Set();
|
|
1073
|
+
for (const field of [
|
|
1074
|
+
"dependencies",
|
|
1075
|
+
"peerDependencies",
|
|
1076
|
+
"optionalDependencies"
|
|
1077
|
+
]) {
|
|
1078
|
+
const deps = packageJson[field];
|
|
1079
|
+
if (!deps || typeof deps !== "object") continue;
|
|
1080
|
+
for (const dep of Object.keys(deps)) names.add(dep);
|
|
1081
|
+
}
|
|
1082
|
+
return Array.from(names);
|
|
1083
|
+
}
|
|
1084
|
+
function isWorkspaceSingletonConsumedByPeer(pkg) {
|
|
1085
|
+
const shared = getNormalizeModuleFederationOptions()?.shared || {};
|
|
1086
|
+
const sharedKeyByPackageName = /* @__PURE__ */ new Map();
|
|
1087
|
+
Object.entries(shared).filter(([, item]) => item.shareConfig.singleton === true).forEach(([key]) => {
|
|
1088
|
+
const packageName = getPackageName(key);
|
|
1089
|
+
if (!sharedKeyByPackageName.get(packageName) || key === packageName) sharedKeyByPackageName.set(packageName, key);
|
|
1090
|
+
});
|
|
1091
|
+
const reachesPkg = (current, seen) => {
|
|
1092
|
+
const packageJson = getWorkspacePackageJson(current);
|
|
1093
|
+
for (const dependency of getDependencyNames(packageJson)) {
|
|
1094
|
+
const sharedDependency = sharedKeyByPackageName.get(dependency);
|
|
1095
|
+
if (!sharedDependency) continue;
|
|
1096
|
+
if (sharedDependency === pkg) return true;
|
|
1097
|
+
if (seen.has(sharedDependency)) continue;
|
|
1098
|
+
seen.add(sharedDependency);
|
|
1099
|
+
if (reachesPkg(sharedDependency, seen)) return true;
|
|
1100
|
+
}
|
|
1101
|
+
return false;
|
|
1102
|
+
};
|
|
1103
|
+
return Array.from(sharedKeyByPackageName.values()).some((sharedPkg) => sharedPkg !== pkg && reachesPkg(sharedPkg, new Set([sharedPkg])));
|
|
1104
|
+
}
|
|
988
1105
|
function tryResolveImportFromPackageRoot(pkg, root) {
|
|
989
1106
|
try {
|
|
990
1107
|
return createRequire$1(pathToFileURL(path$1.join(root, "package.json"))).resolve(pkg);
|
|
@@ -1114,26 +1231,46 @@ function materializeCachedLoadShareModule(options) {
|
|
|
1114
1231
|
options.addUsedShares(pkg);
|
|
1115
1232
|
options.writeLocalSharedImportMap();
|
|
1116
1233
|
}
|
|
1234
|
+
function generateEagerWorkspaceSingletonExports(namedExports, importSource, cacheKey) {
|
|
1235
|
+
const namedExportLine = namedExports.length > 0 ? `\n export { ${namedExports.join(", ")} } from ${escapeGeneratedStringLiteral(importSource)};` : "";
|
|
1236
|
+
return `import * as __mfLocalShare from ${escapeGeneratedStringLiteral(importSource)};
|
|
1237
|
+
let exportModule = __mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}];
|
|
1238
|
+
if (exportModule === undefined) {
|
|
1239
|
+
Promise.resolve().then(() => {
|
|
1240
|
+
if (__mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}] === undefined) {
|
|
1241
|
+
__mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}] = __mfNormalizeShareModule(__mfLocalShare);
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
exportModule = __mfLocalShare;
|
|
1245
|
+
}
|
|
1246
|
+
const __mf_default = exportModule.default ?? exportModule;
|
|
1247
|
+
export { __mf_default as default };${namedExportLine}`;
|
|
1248
|
+
}
|
|
1117
1249
|
function generateLazyWorkspaceSingletonExports(namedExports, importSource, cacheKey, eagerLocalFallback) {
|
|
1118
1250
|
const namedExportVars = namedExports.map((_name, i) => `__mf_${i}`);
|
|
1119
1251
|
const declarations = namedExports.length > 0 ? ["let __mf_default;", ...namedExportVars.map((name) => `let ${name};`)].join("\n ") : "let __mf_default;";
|
|
1120
1252
|
const assignments = namedExports.length > 0 ? [...namedExports.map((name, i) => `${namedExportVars[i]} = mod[${escapeGeneratedStringLiteral(name)}];`), "__mf_default = mod.default ?? mod;"].join("\n ") : "__mf_default = mod.default ?? mod;";
|
|
1121
1253
|
const namedExportLine = namedExports.length > 0 ? `\n export { ${namedExports.map((name, i) => `${namedExportVars[i]} as ${name}`).join(", ")} };` : "";
|
|
1254
|
+
const applyLocalFallback = `exportModule = __mfNormalizeShareModule(__mfLocalShare);
|
|
1255
|
+
__mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}] = exportModule;
|
|
1256
|
+
__mfApplyLazyShareExports(exportModule);`;
|
|
1122
1257
|
const body = `${declarations}
|
|
1123
1258
|
const __mfApplyLazyShareExports = (mod) => {
|
|
1124
1259
|
${assignments}
|
|
1125
1260
|
};
|
|
1126
1261
|
let exportModule = __mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}];
|
|
1127
1262
|
if (exportModule === undefined) {
|
|
1128
|
-
${eagerLocalFallback ? `
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1263
|
+
${eagerLocalFallback ? applyLocalFallback : `if (import.meta.env.SSR) {
|
|
1264
|
+
${applyLocalFallback}
|
|
1265
|
+
} else {
|
|
1266
|
+
initPromise.then(() =>
|
|
1267
|
+
import(${escapeGeneratedStringLiteral(importSource)}).then((mod) => {
|
|
1268
|
+
exportModule = __mfNormalizeShareModule(mod);
|
|
1269
|
+
__mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}] = exportModule;
|
|
1270
|
+
__mfApplyLazyShareExports(exportModule);
|
|
1271
|
+
})
|
|
1272
|
+
);
|
|
1273
|
+
}`}
|
|
1137
1274
|
} else {
|
|
1138
1275
|
__mfApplyLazyShareExports(exportModule);
|
|
1139
1276
|
}
|
|
@@ -1141,6 +1278,16 @@ function generateLazyWorkspaceSingletonExports(namedExports, importSource, cache
|
|
|
1141
1278
|
return eagerLocalFallback ? `import * as __mfLocalShare from ${escapeGeneratedStringLiteral(importSource)};
|
|
1142
1279
|
${body}` : body;
|
|
1143
1280
|
}
|
|
1281
|
+
const WORKSPACE_SINGLETON_SSR_LOCAL_SHARE = "__mfNormalizeShareModule(__mfLocalShare)";
|
|
1282
|
+
function prependWorkspaceSingletonSsrImport(code) {
|
|
1283
|
+
if (!code.includes("if (import.meta.env.SSR)")) return code;
|
|
1284
|
+
if (!code.includes(WORKSPACE_SINGLETON_SSR_LOCAL_SHARE)) return code;
|
|
1285
|
+
if (code.includes("import * as __mfLocalShare")) return code;
|
|
1286
|
+
const importMatch = code.match(/initPromise\.then\(\(\)\s*=>\s*\n\s*import\((["'])(.+?)\1\)\.then\(\(mod\)\s*=>\s*\{[\s\S]*?__mfApplyLazyShareExports/);
|
|
1287
|
+
if (!importMatch) return code;
|
|
1288
|
+
const quote = importMatch[1];
|
|
1289
|
+
return `import * as __mfLocalShare from ${quote}${importMatch[2]}${quote};\n${code}`;
|
|
1290
|
+
}
|
|
1144
1291
|
function generateDeferredHostProvidedExports(namedExports, pkg, cacheKey) {
|
|
1145
1292
|
const namedExportVars = namedExports.map((_name, i) => `__mf_${i}`);
|
|
1146
1293
|
const declarations = ["let __mf_default;", ...namedExportVars.map((name) => `let ${name};`)].join("\n ");
|
|
@@ -1207,11 +1354,13 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
|
|
|
1207
1354
|
const isWorkspacePackage = isWorkspacePackageEntry(pkg, localProviderPath) || isWorkspacePackageEntry(pkg, concreteSharedImportSource);
|
|
1208
1355
|
const lazyLocalFallbackSource = concreteSharedImportSource || localProviderPath || sharedImportSource;
|
|
1209
1356
|
const skipServePrebuildWarmup = command !== "build" && (pkg === "lit" || pkg.startsWith("lit/"));
|
|
1210
|
-
const
|
|
1357
|
+
const isWorkspaceSingleton = isWorkspacePackage && shareItem.shareConfig.singleton === true;
|
|
1358
|
+
const usesEagerWorkspaceFallback = isWorkspaceSingleton && isWorkspaceSingletonConsumedByPeer(pkg);
|
|
1211
1359
|
const namedExports = getSharedNamedExports(pkg, shareItem);
|
|
1212
1360
|
let exportLine;
|
|
1213
1361
|
let initBlock = "";
|
|
1214
|
-
if (
|
|
1362
|
+
if (usesEagerWorkspaceFallback) exportLine = generateEagerWorkspaceSingletonExports(namedExports, lazyLocalFallbackSource, cacheKey);
|
|
1363
|
+
else if (isWorkspaceSingleton) {
|
|
1215
1364
|
importLine = `${getRuntimeInitPromiseBootstrapCode()}\n ${importLine}`;
|
|
1216
1365
|
exportLine = generateLazyWorkspaceSingletonExports(namedExports, lazyLocalFallbackSource, cacheKey, command !== "build");
|
|
1217
1366
|
} else if (namedExports.length > 0) {
|
|
@@ -1234,9 +1383,9 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
|
|
|
1234
1383
|
initBlock = `exportModule = __mfNormalizeShareModule(__mfLocalShare);
|
|
1235
1384
|
__mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}] = exportModule;`;
|
|
1236
1385
|
}
|
|
1237
|
-
const prebuildImportLine =
|
|
1386
|
+
const prebuildImportLine = isWorkspaceSingleton || isWorkspacePackage && command !== "build" ? "" : `import * as __mfLocalShare from ${escapeGeneratedStringLiteral(skipServePrebuildWarmup ? devImportSource : sharedImportSource)};`;
|
|
1238
1387
|
const devDynamicImportLine = isWorkspacePackage ? "" : command !== "build" && !skipServePrebuildWarmup ? `;() => import(${escapeGeneratedStringLiteral(devImportSource)}).catch(() => {});` : "";
|
|
1239
|
-
const moduleBody =
|
|
1388
|
+
const moduleBody = isWorkspaceSingleton ? `
|
|
1240
1389
|
${prebuildImportLine}
|
|
1241
1390
|
${devDynamicImportLine}
|
|
1242
1391
|
${importLine}
|
|
@@ -1372,6 +1521,8 @@ function generateUsedSharedPreloadConfig() {
|
|
|
1372
1521
|
const shareItem = getShareItemForPreload(pkg);
|
|
1373
1522
|
if (!shareItem) return null;
|
|
1374
1523
|
return `${JSON.stringify(pkg)}: {
|
|
1524
|
+
version: ${JSON.stringify(shareItem.version)},
|
|
1525
|
+
scope: ${JSON.stringify(shareItem.scope)},
|
|
1375
1526
|
shareConfig: {
|
|
1376
1527
|
singleton: ${shareItem.shareConfig.singleton},
|
|
1377
1528
|
requiredVersion: ${JSON.stringify(shareItem.shareConfig.requiredVersion)},
|
|
@@ -1394,7 +1545,11 @@ function getOrderedUsedShares() {
|
|
|
1394
1545
|
}));
|
|
1395
1546
|
}
|
|
1396
1547
|
function orderSharedDependenciesFirst(sharedPackages) {
|
|
1397
|
-
const sharedKeyByPackageName = new Map(
|
|
1548
|
+
const sharedKeyByPackageName = /* @__PURE__ */ new Map();
|
|
1549
|
+
sharedPackages.forEach((pkg) => {
|
|
1550
|
+
const packageName = getPackageName(pkg);
|
|
1551
|
+
if (!sharedKeyByPackageName.get(packageName) || pkg === packageName) sharedKeyByPackageName.set(packageName, pkg);
|
|
1552
|
+
});
|
|
1398
1553
|
const visiting = /* @__PURE__ */ new Set();
|
|
1399
1554
|
const visited = /* @__PURE__ */ new Set();
|
|
1400
1555
|
const ordered = [];
|
|
@@ -1439,6 +1594,11 @@ function generateSharedCacheSeedItem(pkg, shareItem, importPath) {
|
|
|
1439
1594
|
__mfModuleCache.share[${JSON.stringify(cacheKey)}] = exportModule;
|
|
1440
1595
|
}`;
|
|
1441
1596
|
}
|
|
1597
|
+
const sharedCacheKeyHelperCode = `const __mfGetSharedCacheKey = (pkg, singleton, version, scope) => {
|
|
1598
|
+
const normalizedScope = Array.isArray(scope) ? scope[0] : scope;
|
|
1599
|
+
const prefix = (normalizedScope || "default") + ":";
|
|
1600
|
+
return singleton || !version ? prefix + pkg : prefix + pkg + "@" + version;
|
|
1601
|
+
};`;
|
|
1442
1602
|
const normalizeRuntimeShareCode = `const __mfNormalizeRuntimeShare = (mod) => {
|
|
1443
1603
|
let current = mod;
|
|
1444
1604
|
for (let i = 0; i < 5; i++) {
|
|
@@ -1555,6 +1715,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
1555
1715
|
}
|
|
1556
1716
|
|
|
1557
1717
|
async function init(shared = {}, initScope = []) {
|
|
1718
|
+
${sharedCacheKeyHelperCode}
|
|
1558
1719
|
const {usedShared, usedRemotes} = await getLocalSharedImportMap()
|
|
1559
1720
|
try {
|
|
1560
1721
|
const allInstances = globalThis.__FEDERATION__?.__SHARE__;
|
|
@@ -1566,11 +1727,19 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
1566
1727
|
for (const [pkg, versionMap] of Object.entries(scopeShare)) {
|
|
1567
1728
|
for (const [version, provider] of Object.entries(versionMap)) {
|
|
1568
1729
|
if (!provider.lib) continue;
|
|
1569
|
-
const cacheKey = provider.shareConfig?.singleton
|
|
1730
|
+
const cacheKey = __mfGetSharedCacheKey(pkg, provider.shareConfig?.singleton, version, ${JSON.stringify(options.shareScope)});
|
|
1570
1731
|
if (__mfModuleCache.share[cacheKey] !== undefined) continue;
|
|
1571
1732
|
const mod = typeof provider.lib === "function" ? provider.lib() : provider.lib;
|
|
1572
1733
|
const resolved = await Promise.resolve(mod);
|
|
1573
|
-
|
|
1734
|
+
const normalized = __mfNormalizeRuntimeShare(resolved);
|
|
1735
|
+
__mfModuleCache.share[cacheKey] = normalized;
|
|
1736
|
+
const usedShare = usedShared?.[pkg];
|
|
1737
|
+
if (provider.shareConfig?.singleton && usedShare) {
|
|
1738
|
+
const usedCacheKey = __mfGetSharedCacheKey(pkg, usedShare.shareConfig?.singleton, usedShare.version, usedShare.scope);
|
|
1739
|
+
if (__mfModuleCache.share[usedCacheKey] === undefined) {
|
|
1740
|
+
__mfModuleCache.share[usedCacheKey] = normalized;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1574
1743
|
}
|
|
1575
1744
|
}
|
|
1576
1745
|
}
|
|
@@ -1578,6 +1747,14 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
1578
1747
|
} catch (e) {
|
|
1579
1748
|
console.error('[Module Federation] Failed to bridge external shared modules', e)
|
|
1580
1749
|
}
|
|
1750
|
+
for (const [pkg, share] of Object.entries(usedShared)) {
|
|
1751
|
+
const cacheKey = __mfGetSharedCacheKey(pkg, share.shareConfig?.singleton, share.version, share.scope);
|
|
1752
|
+
if (__mfModuleCache.share[cacheKey] !== undefined) continue;
|
|
1753
|
+
const singletonCacheKey = __mfGetSharedCacheKey(pkg, true, share.version, share.scope);
|
|
1754
|
+
if (__mfModuleCache.share[singletonCacheKey] !== undefined) {
|
|
1755
|
+
__mfModuleCache.share[cacheKey] = __mfModuleCache.share[singletonCacheKey];
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1581
1758
|
${generateDirectSharedCacheSeedCode(command)}
|
|
1582
1759
|
const __browserPlugins = [${pluginImportNames.filter((item) => !isSsrOnlyPlugin(item[1])).map((item) => `${item[0]}(${item[2]})`).join(", ")}];
|
|
1583
1760
|
const __ssrPlugins = typeof globalThis.window === 'undefined'
|
|
@@ -1614,7 +1791,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
1614
1791
|
console.error('[Module Federation]', e)
|
|
1615
1792
|
}
|
|
1616
1793
|
for (const [pkg, share] of Object.entries(usedShared)) {
|
|
1617
|
-
const cacheKey = share.shareConfig?.singleton
|
|
1794
|
+
const cacheKey = __mfGetSharedCacheKey(pkg, share.shareConfig?.singleton, share.version, share.scope);
|
|
1618
1795
|
if (share.shareConfig?.import !== false || __mfModuleCache.share[cacheKey] !== undefined) continue;
|
|
1619
1796
|
${normalizeRuntimeShareCode}
|
|
1620
1797
|
const versions = shared?.[pkg];
|
|
@@ -1654,10 +1831,11 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build") {
|
|
|
1654
1831
|
const remoteEntry = await import(${remoteEntryImport});
|
|
1655
1832
|
const runtime = await remoteEntry.init();
|
|
1656
1833
|
const usedShared = ${generateUsedSharedPreloadConfig()};
|
|
1834
|
+
${sharedCacheKeyHelperCode}
|
|
1657
1835
|
${normalizeRuntimeShareCode}
|
|
1658
1836
|
${shouldPreloadShares ? `
|
|
1659
1837
|
for (const [pkg, share] of Object.entries(usedShared)) {
|
|
1660
|
-
const cacheKey = share.shareConfig?.singleton
|
|
1838
|
+
const cacheKey = __mfGetSharedCacheKey(pkg, share.shareConfig?.singleton, share.version, share.scope);
|
|
1661
1839
|
if (__mfModuleCache.share[cacheKey] !== undefined) {
|
|
1662
1840
|
continue;
|
|
1663
1841
|
}
|
|
@@ -1866,7 +2044,7 @@ function getRemoteExportBlock(command, deferRemoteLoad, consumer) {
|
|
|
1866
2044
|
if (command !== "serve" && command !== "build") return `__mfSyncDefaultExport();
|
|
1867
2045
|
export { __mfDefaultExport as default };`;
|
|
1868
2046
|
return `__mfSyncDefaultExport();
|
|
1869
|
-
__mfRemotePending?.then(__mfSyncDefaultExport);
|
|
2047
|
+
__mfRemotePending?.then(__mfSyncDefaultExport, () => {});
|
|
1870
2048
|
export { exportModule as __moduleExports };
|
|
1871
2049
|
${deferRemoteLoad ? getLazyRemotePendingExport() : getEagerRemotePendingExport()}
|
|
1872
2050
|
${command === "serve" && consumer === "server" ? getServerThenExport() : ""}
|
|
@@ -1897,8 +2075,9 @@ function generateRemotes(id, command, enableSsrInit = false, consumer = "unified
|
|
|
1897
2075
|
const remoteLoadFailureHandler = command === "build" ? `.catch((error) => {
|
|
1898
2076
|
delete __mfModuleCache.remote[pendingKey];
|
|
1899
2077
|
throw error;
|
|
1900
|
-
})` : `.catch(() => {
|
|
2078
|
+
})` : `.catch((error) => {
|
|
1901
2079
|
delete __mfModuleCache.remote[pendingKey];
|
|
2080
|
+
throw error;
|
|
1902
2081
|
})`;
|
|
1903
2082
|
const remoteLoadCode = `
|
|
1904
2083
|
function __mfStartRemoteLoad() {
|
|
@@ -2024,9 +2203,11 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
|
|
|
2024
2203
|
let _command;
|
|
2025
2204
|
let emitFileId;
|
|
2026
2205
|
let viteConfig;
|
|
2027
|
-
let
|
|
2206
|
+
let skipHtmlDevFallback = forceClientInjected ?? false;
|
|
2207
|
+
let clientInjected = false;
|
|
2028
2208
|
let emittedFileName;
|
|
2029
2209
|
let skipTransformIds = /* @__PURE__ */ new Set();
|
|
2210
|
+
let injectedTransformIds = /* @__PURE__ */ new Set();
|
|
2030
2211
|
let bootstrapDir = "";
|
|
2031
2212
|
function skipSvelteKitSsrBuild() {
|
|
2032
2213
|
return (_command === "build" || viteConfig?.command === "build") && viteConfig?.build?.ssr && hasPackageDependency("@sveltejs/kit");
|
|
@@ -2116,7 +2297,9 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
|
|
|
2116
2297
|
await Promise.allSettled(__mfRemotePreloads);` : `await initHost();`;
|
|
2117
2298
|
const importCode = `
|
|
2118
2299
|
(async () => {
|
|
2119
|
-
const
|
|
2300
|
+
const __mfHostInit = await ${importExpression(initSrc)};
|
|
2301
|
+
await __mfHostInit.__tla;
|
|
2302
|
+
const { initHost } = __mfHostInit;
|
|
2120
2303
|
${preloadBlock}
|
|
2121
2304
|
})().then(() => ${importExpression(entrySrc)});
|
|
2122
2305
|
`;
|
|
@@ -2146,6 +2329,10 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
|
|
|
2146
2329
|
if (id.startsWith("\0") || id.startsWith("virtual:")) return normalizeModuleId(id);
|
|
2147
2330
|
return normalizeModuleId(path$1.isAbsolute(id) ? id : path$1.resolve(viteConfig.root, id));
|
|
2148
2331
|
}
|
|
2332
|
+
function isFederationInternalVirtualId(id) {
|
|
2333
|
+
const normalized = decodeViteId(id).replace(/^\0+/, "");
|
|
2334
|
+
return normalized.includes("virtual:mf:") || /__(?:loadShare|prebuild|loadRemote)__/.test(normalized);
|
|
2335
|
+
}
|
|
2149
2336
|
function addEntryFile(file) {
|
|
2150
2337
|
const normalized = normalizeModuleId(file);
|
|
2151
2338
|
if (!entryFiles.includes(normalized)) entryFiles.push(normalized);
|
|
@@ -2253,9 +2440,9 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
|
|
|
2253
2440
|
if (envName?.name && envName.name !== "client") return;
|
|
2254
2441
|
const inputOptions = getBuildInput(config);
|
|
2255
2442
|
if (!inputOptions) htmlFilePath = path$1.resolve(config.root, "index.html");
|
|
2256
|
-
else if (typeof inputOptions === "string") entryFiles = [
|
|
2257
|
-
else if (Array.isArray(inputOptions)) entryFiles = inputOptions.map(
|
|
2258
|
-
else if (typeof inputOptions === "object") entryFiles = Object.values(inputOptions).map((input) =>
|
|
2443
|
+
else if (typeof inputOptions === "string") entryFiles = [resolveProjectId(inputOptions)];
|
|
2444
|
+
else if (Array.isArray(inputOptions)) entryFiles = inputOptions.map(resolveProjectId);
|
|
2445
|
+
else if (typeof inputOptions === "object") entryFiles = Object.values(inputOptions).map((input) => resolveProjectId(String(input)));
|
|
2259
2446
|
if (entryFiles.length > 0) htmlFilePath = getFirstHtmlEntryFile(entryFiles);
|
|
2260
2447
|
if (htmlFilePath) addHtmlScriptEntries(htmlFilePath);
|
|
2261
2448
|
},
|
|
@@ -2355,7 +2542,8 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
|
|
|
2355
2542
|
if (isSvelteKitServerModule(id)) return;
|
|
2356
2543
|
if (hasEntryBootstrapParam(id)) return;
|
|
2357
2544
|
if (normalizeModuleId(id).endsWith(".html")) return;
|
|
2358
|
-
|
|
2545
|
+
const projectId = resolveProjectId(id);
|
|
2546
|
+
if (skipTransformIds.has(projectId)) return;
|
|
2359
2547
|
const transformCtx = this;
|
|
2360
2548
|
const transformEnv = transformCtx != null && typeof transformCtx === "object" ? transformCtx["environment"] : void 0;
|
|
2361
2549
|
if (transformEnv?.name && transformEnv.name !== "client") return;
|
|
@@ -2380,12 +2568,13 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
|
|
|
2380
2568
|
const injection = `await import(${JSON.stringify(getEntryPath())}).then(({ initHost }) => initHost());\n `;
|
|
2381
2569
|
return mapCodeToCodeWithSourcemap(code.replace("vueApp.mount(vueAppRootContainer);", `${injection}vueApp.mount(vueAppRootContainer);`));
|
|
2382
2570
|
}
|
|
2383
|
-
const isHydrationEntryFallback = inject === "entry" && entryFiles.length === 0 && (!htmlFilePath || !fs$1.existsSync(htmlFilePath)) && !clientInjected && !id.includes("node_modules") && (id.startsWith("\0") || /\.(js|ts|mjs|vue|jsx|tsx)(\?|$)/.test(id)) && /hydrateRoot|createRoot|ReactDOM\.render/.test(code);
|
|
2571
|
+
const isHydrationEntryFallback = inject === "entry" && entryFiles.length === 0 && (!htmlFilePath || !fs$1.existsSync(htmlFilePath)) && !clientInjected && !isFederationInternalVirtualId(id) && !id.includes("node_modules") && (id.startsWith("\0") || /\.(js|ts|mjs|vue|jsx|tsx)(\?|$)/.test(id)) && (/hydrateRoot|createRoot|ReactDOM\.render/.test(code) || /\.mount\s*\(\s*['"#]/.test(code) || /\.mount\s*\(/.test(code) && /createSSRApp|createApp/.test(code));
|
|
2384
2572
|
const isNuxtEntryAsyncModule = /(?:^|\/)nuxt\/dist\/app\/entry\.async\.js(?:\?|$)/.test(id) && code.includes("entry();");
|
|
2385
|
-
const isNuxtClientEntryFallback = _command === "serve" && inject === "entry" && (!htmlFilePath || !fs$1.existsSync(htmlFilePath)) && !clientInjected && !hasEntryBootstrapParam(id) && !id.includes("node_modules/.vite") && isNuxtEntryAsyncModule && !entryFiles.some((file) =>
|
|
2386
|
-
if (!(_command === "serve" && isNuxtEntryAsyncModule) && (injectEntry() && entryFiles.some((file) =>
|
|
2573
|
+
const isNuxtClientEntryFallback = _command === "serve" && inject === "entry" && (!htmlFilePath || !fs$1.existsSync(htmlFilePath)) && !clientInjected && !hasEntryBootstrapParam(id) && !id.includes("node_modules/.vite") && isNuxtEntryAsyncModule && !entryFiles.some((file) => projectId === file);
|
|
2574
|
+
if (!(_command === "serve" && isNuxtEntryAsyncModule) && (injectedTransformIds.has(projectId) || injectEntry() && entryFiles.some((file) => projectId === file) || _command === "serve" && inject === "html" && !isVinext && !clientInjected && !skipHtmlDevFallback && !id.startsWith("\0") && !id.includes("node_modules") && /\.(js|ts|mjs|vue|jsx|tsx)(\?|$)/.test(id) || isHydrationEntryFallback || isNuxtClientEntryFallback)) {
|
|
2387
2575
|
clientInjected = true;
|
|
2388
|
-
|
|
2576
|
+
injectedTransformIds.add(projectId);
|
|
2577
|
+
if (!waitsForInit) return mapCodeToCodeWithSourcemap(`import ${JSON.stringify(getEntryPath())};\n` + code);
|
|
2389
2578
|
const entrySrc = id.includes("?") ? `${id}&${ENTRY_BOOTSTRAP_QUERY.slice(1)}` : `${id}${ENTRY_BOOTSTRAP_QUERY}`;
|
|
2390
2579
|
return mapCodeToCodeWithSourcemap(getBootstrapSource(getEntryPath(), entrySrc, false, { skipRemotePreload: _command === "serve" && isNuxtEntryAsyncModule }));
|
|
2391
2580
|
}
|
|
@@ -2477,7 +2666,7 @@ const REACT_REFRESH_PROXY_MODULE = [
|
|
|
2477
2666
|
].join("\n");
|
|
2478
2667
|
const reactAdapter = {
|
|
2479
2668
|
name: "react",
|
|
2480
|
-
pluginNames: ["vite:react-refresh", "vite:react-swc
|
|
2669
|
+
pluginNames: ["vite:react-refresh", "vite:react-swc"],
|
|
2481
2670
|
remote: { configureServer({ server }) {
|
|
2482
2671
|
let reactRefreshRuntime;
|
|
2483
2672
|
server.middlewares.use((req, res, next) => {
|
|
@@ -2590,7 +2779,7 @@ const REMOTE_HMR_ENDPOINT = "__mf_hmr";
|
|
|
2590
2779
|
const REMOTE_HMR_EVENT = "mf:remote-update";
|
|
2591
2780
|
const REMOTE_HMR_CONNECT_RETRY_DELAY_MS = 1e3;
|
|
2592
2781
|
const REMOTE_HMR_CONNECT_MAX_RETRIES = 10;
|
|
2593
|
-
function getBasePath
|
|
2782
|
+
function getBasePath(base) {
|
|
2594
2783
|
if (!base) return "/";
|
|
2595
2784
|
if (base.startsWith("http://") || base.startsWith("https://")) try {
|
|
2596
2785
|
return new URL(base).pathname || "/";
|
|
@@ -2600,11 +2789,11 @@ function getBasePath$1(base) {
|
|
|
2600
2789
|
return base;
|
|
2601
2790
|
}
|
|
2602
2791
|
function getRemoteHmrPath(base) {
|
|
2603
|
-
return `${getBasePath
|
|
2792
|
+
return `${getBasePath(base).replace(/\/?$/, "/")}${REMOTE_HMR_ENDPOINT}`.replace(/\/{2,}/g, "/");
|
|
2604
2793
|
}
|
|
2605
2794
|
function getHmrWsPath(base, hmrPath) {
|
|
2606
|
-
const normalizedBase = getBasePath
|
|
2607
|
-
const normalizedPath = getBasePath
|
|
2795
|
+
const normalizedBase = getBasePath(base);
|
|
2796
|
+
const normalizedPath = getBasePath(hmrPath || "");
|
|
2608
2797
|
if (!normalizedPath || normalizedPath === "/") return normalizedBase;
|
|
2609
2798
|
return `${normalizedBase.endsWith("/") ? normalizedBase.slice(0, -1) : normalizedBase}/${normalizedPath.startsWith("/") ? normalizedPath.slice(1) : normalizedPath}`;
|
|
2610
2799
|
}
|
|
@@ -3253,70 +3442,6 @@ const buildFileToShareKeyMap = async (shareKeys, resolveFn) => {
|
|
|
3253
3442
|
return fileToShareKey;
|
|
3254
3443
|
};
|
|
3255
3444
|
//#endregion
|
|
3256
|
-
//#region src/utils/pathNormalization.ts
|
|
3257
|
-
const COMMON_SHARED_SUBPATHS = {
|
|
3258
|
-
react: [
|
|
3259
|
-
"react/jsx-runtime",
|
|
3260
|
-
"react/jsx-dev-runtime",
|
|
3261
|
-
"react/compiler-runtime"
|
|
3262
|
-
],
|
|
3263
|
-
"react-dom": [
|
|
3264
|
-
"react-dom/client",
|
|
3265
|
-
"react-dom/server",
|
|
3266
|
-
"react-dom/server.browser"
|
|
3267
|
-
],
|
|
3268
|
-
"solid-js": [
|
|
3269
|
-
"solid-js/web",
|
|
3270
|
-
"solid-js/store",
|
|
3271
|
-
"solid-js/html",
|
|
3272
|
-
"solid-js/h"
|
|
3273
|
-
]
|
|
3274
|
-
};
|
|
3275
|
-
function removeTrailingSlash(value) {
|
|
3276
|
-
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
3277
|
-
}
|
|
3278
|
-
function ensureTrailingSlash(value) {
|
|
3279
|
-
return `${removeTrailingSlash(value)}/`;
|
|
3280
|
-
}
|
|
3281
|
-
function getBasePath(base) {
|
|
3282
|
-
return removeTrailingSlash(base || "/");
|
|
3283
|
-
}
|
|
3284
|
-
function isNuxtClientBase(base) {
|
|
3285
|
-
return getBasePath(base).endsWith("/_nuxt");
|
|
3286
|
-
}
|
|
3287
|
-
function normalizeNodeModulePath(source) {
|
|
3288
|
-
return source.replace(/\\/g, "/").replace(/\?.*$/, "");
|
|
3289
|
-
}
|
|
3290
|
-
function isNodeModulePath(source) {
|
|
3291
|
-
return source.includes("/node_modules/") || source.includes("\\node_modules\\");
|
|
3292
|
-
}
|
|
3293
|
-
function filterId(id) {
|
|
3294
|
-
return typeof id === "string" && !id.includes("\0");
|
|
3295
|
-
}
|
|
3296
|
-
function getMatchingNodeModuleSubpath(source, candidates) {
|
|
3297
|
-
const normalized = normalizeNodeModulePath(source);
|
|
3298
|
-
return [...candidates].sort((a, b) => b.length - a.length).find((candidate) => normalized.includes(`/node_modules/${candidate}/`) || normalized.includes(`/node_modules/${candidate}.`));
|
|
3299
|
-
}
|
|
3300
|
-
function getCommonSharedSubpaths(sharedKey) {
|
|
3301
|
-
return COMMON_SHARED_SUBPATHS[removeTrailingSlash(sharedKey)] || [];
|
|
3302
|
-
}
|
|
3303
|
-
function getCommonSharedSubpathFromNodeModulePath(source, sharedKey) {
|
|
3304
|
-
return getMatchingNodeModuleSubpath(source, getCommonSharedSubpaths(removeTrailingSlash(sharedKey)));
|
|
3305
|
-
}
|
|
3306
|
-
/**
|
|
3307
|
-
* Resolves the public path for remote entries
|
|
3308
|
-
* @param options - Module Federation options
|
|
3309
|
-
* @param viteBase - Vite's base config value
|
|
3310
|
-
* @param originalBase - Original base config before any transformations
|
|
3311
|
-
* @returns The resolved public path
|
|
3312
|
-
*/
|
|
3313
|
-
function resolvePublicPath(options, viteBase, originalBase) {
|
|
3314
|
-
if (options.publicPath && options.publicPath !== "auto") return options.publicPath;
|
|
3315
|
-
if (!originalBase) return "auto";
|
|
3316
|
-
if (viteBase) return ensureTrailingSlash(viteBase);
|
|
3317
|
-
return "auto";
|
|
3318
|
-
}
|
|
3319
|
-
//#endregion
|
|
3320
3445
|
//#region src/virtualModules/virtualExposesSSR.ts
|
|
3321
3446
|
/**
|
|
3322
3447
|
* Virtual module ID for the SSR exposes map.
|
|
@@ -3469,6 +3594,24 @@ function resolveTypesMeta(dts) {
|
|
|
3469
3594
|
api: `${typesFolder}.d.ts`
|
|
3470
3595
|
};
|
|
3471
3596
|
}
|
|
3597
|
+
function resolveDevRemoteEntryFileName(fileName) {
|
|
3598
|
+
if (!fileName.includes("[hash")) return fileName;
|
|
3599
|
+
const normalized = fileName.replace(/(?:[._-]?\[hash(?::\d+)?\])/g, "");
|
|
3600
|
+
const baseName = path$1.basename(normalized);
|
|
3601
|
+
return path$1.extname(baseName) ? normalized : `${normalized}.js`;
|
|
3602
|
+
}
|
|
3603
|
+
function createRemoteEntryAssetMap(fileName) {
|
|
3604
|
+
return {
|
|
3605
|
+
js: {
|
|
3606
|
+
async: [],
|
|
3607
|
+
sync: [fileName]
|
|
3608
|
+
},
|
|
3609
|
+
css: {
|
|
3610
|
+
async: [],
|
|
3611
|
+
sync: []
|
|
3612
|
+
}
|
|
3613
|
+
};
|
|
3614
|
+
}
|
|
3472
3615
|
const Manifest = () => {
|
|
3473
3616
|
const mfOptions = getNormalizeModuleFederationOptions();
|
|
3474
3617
|
const { name, filename, getPublicPath, manifest: manifestOptions, varFilename } = mfOptions;
|
|
@@ -3502,6 +3645,12 @@ const Manifest = () => {
|
|
|
3502
3645
|
next();
|
|
3503
3646
|
return;
|
|
3504
3647
|
}
|
|
3648
|
+
const devRemoteEntryFile = resolveDevRemoteEntryFileName(filename);
|
|
3649
|
+
if (devRemoteEntryFile !== filename && req.url?.startsWith((viteConfig.base + devRemoteEntryFile).replace(/^\/?/, "/"))) {
|
|
3650
|
+
req.url = req.url.replace(devRemoteEntryFile, filename);
|
|
3651
|
+
next();
|
|
3652
|
+
return;
|
|
3653
|
+
}
|
|
3505
3654
|
if (req.url?.replace(/\?.*/, "") === (viteConfig.base + mfManifestName).replace(/^\/?/, "/")) {
|
|
3506
3655
|
res.setHeader("Content-Type", "application/json");
|
|
3507
3656
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
@@ -3518,12 +3667,12 @@ const Manifest = () => {
|
|
|
3518
3667
|
buildName: name
|
|
3519
3668
|
},
|
|
3520
3669
|
remoteEntry: {
|
|
3521
|
-
name:
|
|
3670
|
+
name: devRemoteEntryFile,
|
|
3522
3671
|
path: "",
|
|
3523
3672
|
type: "module"
|
|
3524
3673
|
},
|
|
3525
3674
|
ssrRemoteEntry: {
|
|
3526
|
-
name: getSsrRemoteEntryFileName(
|
|
3675
|
+
name: getSsrRemoteEntryFileName(devRemoteEntryFile),
|
|
3527
3676
|
path: "/__mf_ssr__/",
|
|
3528
3677
|
type: "module"
|
|
3529
3678
|
},
|
|
@@ -3564,10 +3713,10 @@ const Manifest = () => {
|
|
|
3564
3713
|
if (!mfManifestName) return;
|
|
3565
3714
|
let filesMap = {};
|
|
3566
3715
|
const foundRemoteEntryFile = findRemoteEntryFile(mfOptions.filename, bundle);
|
|
3567
|
-
const expectedSsrRemoteEntryFile = getSsrRemoteEntryFileName(mfOptions.filename);
|
|
3716
|
+
const expectedSsrRemoteEntryFile = getSsrRemoteEntryFileName(foundRemoteEntryFile || mfOptions.filename);
|
|
3568
3717
|
const foundSsrRemoteEntryFile = Object.values(bundle).find((file) => file.fileName === expectedSsrRemoteEntryFile)?.fileName;
|
|
3569
3718
|
if (foundRemoteEntryFile) remoteEntryFile = foundRemoteEntryFile;
|
|
3570
|
-
ssrRemoteEntryFile = foundSsrRemoteEntryFile || expectedSsrRemoteEntryFile;
|
|
3719
|
+
ssrRemoteEntryFile = foundSsrRemoteEntryFile || (_command === "serve" ? getSsrRemoteEntryFileName(resolveDevRemoteEntryFileName(mfOptions.filename)) : expectedSsrRemoteEntryFile);
|
|
3571
3720
|
const allCssAssets = mfOptions.bundleAllCSS && !disableAssetsAnalyze ? collectCssAssets(bundle) : /* @__PURE__ */ new Set();
|
|
3572
3721
|
if (!disableAssetsAnalyze) {
|
|
3573
3722
|
const exposesModules = Object.keys(mfOptions.exposes).map((item) => mfOptions.exposes[item].import);
|
|
@@ -3608,13 +3757,14 @@ const Manifest = () => {
|
|
|
3608
3757
|
function generateMFManifest(preloadMap, disableAssetsAnalyze = false) {
|
|
3609
3758
|
const options = getNormalizeModuleFederationOptions();
|
|
3610
3759
|
const { name, varFilename } = options;
|
|
3760
|
+
const resolvedRemoteEntryFile = _command === "serve" ? remoteEntryFile || resolveDevRemoteEntryFileName(filename) : remoteEntryFile;
|
|
3611
3761
|
const remoteEntry = {
|
|
3612
|
-
name:
|
|
3762
|
+
name: resolvedRemoteEntryFile,
|
|
3613
3763
|
path: "",
|
|
3614
3764
|
type: "module"
|
|
3615
3765
|
};
|
|
3616
3766
|
const ssrRemoteEntry = {
|
|
3617
|
-
name: ssrRemoteEntryFile || getSsrRemoteEntryFileName(filename),
|
|
3767
|
+
name: ssrRemoteEntryFile || getSsrRemoteEntryFileName(_command === "serve" ? resolveDevRemoteEntryFileName(filename) : filename),
|
|
3618
3768
|
path: _command === "serve" ? "/__mf_ssr__/" : "",
|
|
3619
3769
|
type: "module"
|
|
3620
3770
|
};
|
|
@@ -3632,7 +3782,7 @@ const Manifest = () => {
|
|
|
3632
3782
|
const shared = Array.from(getUsedShares()).flatMap((shareKey) => {
|
|
3633
3783
|
const shareItem = getNormalizeShareItem(shareKey);
|
|
3634
3784
|
if (!shareItem) return [];
|
|
3635
|
-
const assets = preloadMap[shareKey] || createEmptyAssetMap();
|
|
3785
|
+
const assets = preloadMap[shareKey] || (_command === "serve" && resolvedRemoteEntryFile ? createRemoteEntryAssetMap(resolvedRemoteEntryFile) : createEmptyAssetMap());
|
|
3636
3786
|
return [{
|
|
3637
3787
|
id: `${name}:${shareKey}`,
|
|
3638
3788
|
name: shareKey,
|
|
@@ -3653,7 +3803,7 @@ const Manifest = () => {
|
|
|
3653
3803
|
});
|
|
3654
3804
|
const exposes = Object.entries(options.exposes).map(([key, value]) => {
|
|
3655
3805
|
const formatKey = key.replace("./", "");
|
|
3656
|
-
const assets = preloadMap[value.import] || createEmptyAssetMap();
|
|
3806
|
+
const assets = preloadMap[value.import] || (_command === "serve" && resolvedRemoteEntryFile ? createRemoteEntryAssetMap(resolvedRemoteEntryFile) : createEmptyAssetMap());
|
|
3657
3807
|
return {
|
|
3658
3808
|
id: `${name}:${formatKey}`,
|
|
3659
3809
|
name: formatKey,
|
|
@@ -4649,7 +4799,7 @@ function pluginSSRRemoteEntry(options) {
|
|
|
4649
4799
|
},
|
|
4650
4800
|
configureServer(server) {
|
|
4651
4801
|
const base = "/__mf_ssr__";
|
|
4652
|
-
const basePath = getBasePath(viteConfig?.base);
|
|
4802
|
+
const basePath = getBasePath$1(viteConfig?.base);
|
|
4653
4803
|
const ssrEntryFileName = getSsrRemoteEntryFileName(options.filename);
|
|
4654
4804
|
if (isNuxtProject || isNuxtClientBase(basePath)) server.middlewares.use((req, _res, next) => {
|
|
4655
4805
|
if (req.url?.replace(/\?.*/, "") === `${basePath}/${ssrEntryFileName}`) req.url = `${basePath}/__mf_ssr__/${ssrEntryFileName}`;
|
|
@@ -4953,6 +5103,13 @@ var normalizeOptimizeDeps_default = {
|
|
|
4953
5103
|
if (!optimizeDeps.include) optimizeDeps.include = [];
|
|
4954
5104
|
if (!optimizeDeps.exclude) optimizeDeps.exclude = [];
|
|
4955
5105
|
if (!optimizeDeps.needsInterop) optimizeDeps.needsInterop = [];
|
|
5106
|
+
},
|
|
5107
|
+
configResolved: (config) => {
|
|
5108
|
+
const include = config.optimizeDeps?.include;
|
|
5109
|
+
const exclude = config.optimizeDeps?.exclude;
|
|
5110
|
+
if (!include?.length || !exclude?.length) return;
|
|
5111
|
+
const included = new Set(include);
|
|
5112
|
+
config.optimizeDeps.exclude = exclude.filter((dep) => !included.has(dep));
|
|
4956
5113
|
}
|
|
4957
5114
|
};
|
|
4958
5115
|
//#endregion
|
|
@@ -5106,6 +5263,7 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
5106
5263
|
external: true
|
|
5107
5264
|
}));
|
|
5108
5265
|
build.onResolve({ filter: /.*/ }, (args) => {
|
|
5266
|
+
if (args.kind === "entry-point") return;
|
|
5109
5267
|
if (!args.importer || args.namespace === "mf-shared") return;
|
|
5110
5268
|
if (isSharedResolverInternalImporter(args.importer)) return;
|
|
5111
5269
|
if (!findSharedKey(args.path, shared) || args.path.endsWith(".css")) return;
|
|
@@ -5164,7 +5322,9 @@ export default __mfShared.default ?? __mfShared;`
|
|
|
5164
5322
|
const optimizeDeps = config.optimizeDeps ??= {};
|
|
5165
5323
|
optimizeDeps.include ??= [];
|
|
5166
5324
|
optimizeDeps.exclude ??= [];
|
|
5167
|
-
|
|
5325
|
+
const shouldBypassOptimizeDep = isLitShare(key) || key === "react" && hasPackageDependency("react-redux", root);
|
|
5326
|
+
if (optimizeDeps.include.includes(key)) optimizeDeps.exclude = optimizeDeps.exclude.filter((dep) => dep !== key);
|
|
5327
|
+
else if (shouldBypassOptimizeDep) optimizeDeps.exclude.push(key);
|
|
5168
5328
|
else optimizeDeps.include.push(key);
|
|
5169
5329
|
for (const subpath of getCommonSharedSubpaths(key)) {
|
|
5170
5330
|
getLoadShareModulePath(subpath, isRolldown);
|
|
@@ -5217,7 +5377,7 @@ export default __mfShared.default ?? __mfShared;`
|
|
|
5217
5377
|
const SSR_ONLY_PLUGINS = new Set(["@module-federation/vite/ssrEntryLoader"]);
|
|
5218
5378
|
function loadPluginDts(options) {
|
|
5219
5379
|
if (options.dts === false) return [];
|
|
5220
|
-
return [import("./pluginDts-
|
|
5380
|
+
return [import("./pluginDts-CrSsDUnT.js").then((n) => n.n).then(({ default: pluginDts }) => pluginDts(options))];
|
|
5221
5381
|
}
|
|
5222
5382
|
function federation(mfUserOptions) {
|
|
5223
5383
|
if (isTestEnv()) return [];
|
|
@@ -5229,6 +5389,7 @@ function federation(mfUserOptions) {
|
|
|
5229
5389
|
const virtualExposesId = getVirtualExposesId(options);
|
|
5230
5390
|
let command;
|
|
5231
5391
|
let desiredRolldownOutput;
|
|
5392
|
+
let isSsrBuild = false;
|
|
5232
5393
|
return [
|
|
5233
5394
|
{
|
|
5234
5395
|
name: "vite:module-federation-virtual-modules",
|
|
@@ -5340,6 +5501,7 @@ function federation(mfUserOptions) {
|
|
|
5340
5501
|
enforce: "pre",
|
|
5341
5502
|
apply: "build",
|
|
5342
5503
|
config(config) {
|
|
5504
|
+
isSsrBuild = config.build?.ssr === true;
|
|
5343
5505
|
const runtimeInitId = virtualRuntimeInitStatus.getImportId();
|
|
5344
5506
|
config.build = config.build || {};
|
|
5345
5507
|
if (config.build.modulePreload !== false) {
|
|
@@ -5461,6 +5623,8 @@ function federation(mfUserOptions) {
|
|
|
5461
5623
|
load(id) {
|
|
5462
5624
|
if (id.includes("__loadShare__") || id.includes("__loadRemote__")) {
|
|
5463
5625
|
let code = VirtualModule.findById(id)?.code ?? readFileSync(id, "utf-8");
|
|
5626
|
+
const environmentName = this.environment?.name;
|
|
5627
|
+
if (environmentName && environmentName !== "client" || !environmentName && isSsrBuild) code = prependWorkspaceSingletonSsrImport(code);
|
|
5464
5628
|
code = code.replace(/import\s+["'][^"']*__prebuild__[^"']*["']\s*;?/g, "");
|
|
5465
5629
|
code = code.replace(/export\s+\*\s+from\s+["'][^"']*__prebuild__[^"']*["']\s*;?/g, "");
|
|
5466
5630
|
if (!(/\b(?:var|let|const)\s+__moduleExports\b/.test(code) || /\bexport\s+const\s+__moduleExports\b/.test(code) || /\bexport\s*\{[^}]*__moduleExports/.test(code))) {
|
|
@@ -5522,6 +5686,7 @@ function federation(mfUserOptions) {
|
|
|
5522
5686
|
_options: options,
|
|
5523
5687
|
config(config, { command: _command }) {
|
|
5524
5688
|
const isRolldown = getIsRolldown(this);
|
|
5689
|
+
isSsrBuild = _command === "build" && config.build?.ssr === true;
|
|
5525
5690
|
appendResolveAlias(config, {
|
|
5526
5691
|
find: "@module-federation/runtime",
|
|
5527
5692
|
replacement: options.implementation
|
|
@@ -5546,7 +5711,17 @@ function federation(mfUserOptions) {
|
|
|
5546
5711
|
const envTargetDefineValue = !options.target && isAstro ? "undefined" : JSON.stringify(resolvedTarget);
|
|
5547
5712
|
if (!config.define) config.define = {};
|
|
5548
5713
|
if (!("ENV_TARGET" in config.define)) config.define["ENV_TARGET"] = envTargetDefineValue;
|
|
5714
|
+
if (resolvedTarget === "node" && !("FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN" in config.define)) config.define["FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN"] = "true";
|
|
5549
5715
|
if (options.target && "ENV_TARGET" in config.define && 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.`);
|
|
5716
|
+
},
|
|
5717
|
+
configEnvironment(name, config) {
|
|
5718
|
+
if (!(config.consumer === "server" || name === "ssr" || name === "server" || config.build?.ssr === true)) return;
|
|
5719
|
+
const isAstro = hasPackageDependency("astro");
|
|
5720
|
+
const envTargetDefineValue = !options.target && isAstro ? "undefined" : JSON.stringify(options.target ?? "node");
|
|
5721
|
+
config.define = { ...config.define ?? {} };
|
|
5722
|
+
if (!("ENV_TARGET" in config.define)) config.define["ENV_TARGET"] = envTargetDefineValue;
|
|
5723
|
+
if (!("FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN" in config.define)) config.define["FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN"] = "true";
|
|
5724
|
+
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.`);
|
|
5550
5725
|
}
|
|
5551
5726
|
},
|
|
5552
5727
|
...Manifest(),
|
|
@@ -194,7 +194,8 @@ function getPackageNameFromNodeModulePath(source) {
|
|
|
194
194
|
return parts[0];
|
|
195
195
|
}
|
|
196
196
|
function getSharedCacheKey(pkg, shareItem) {
|
|
197
|
-
|
|
197
|
+
const prefix = `${shareItem.scope || "default"}:`;
|
|
198
|
+
return shareItem.shareConfig.singleton || !shareItem.version ? `${prefix}${pkg}` : `${prefix}${pkg}@${shareItem.version}`;
|
|
198
199
|
}
|
|
199
200
|
function getInstalledPackageJson(pkg, opts) {
|
|
200
201
|
const cwd = opts?.cwd || getPackageDetectionCwd();
|
|
@@ -87,7 +87,8 @@ const _path = () => nodeImport("path");
|
|
|
87
87
|
const _fs = () => nodeImport("fs");
|
|
88
88
|
const _crypto = () => nodeImport("crypto");
|
|
89
89
|
const _module = () => nodeImport("module");
|
|
90
|
-
const
|
|
90
|
+
const ssrEntryCache = /* @__PURE__ */ new Map();
|
|
91
|
+
const manifestFetchCache = /* @__PURE__ */ new Map();
|
|
91
92
|
async function fetchManifest(manifestUrl) {
|
|
92
93
|
try {
|
|
93
94
|
const res = await fetch(manifestUrl);
|
|
@@ -97,9 +98,33 @@ async function fetchManifest(manifestUrl) {
|
|
|
97
98
|
return null;
|
|
98
99
|
}
|
|
99
100
|
}
|
|
101
|
+
async function fetchManifestCached(manifestUrl) {
|
|
102
|
+
if (!manifestFetchCache.has(manifestUrl)) manifestFetchCache.set(manifestUrl, fetchManifest(manifestUrl));
|
|
103
|
+
return manifestFetchCache.get(manifestUrl);
|
|
104
|
+
}
|
|
105
|
+
/** True when the host configured a manifest URL as the remote entry (any .json name). */
|
|
106
|
+
function isManifestEntry(remoteEntryUrl) {
|
|
107
|
+
try {
|
|
108
|
+
const { pathname } = new URL(remoteEntryUrl);
|
|
109
|
+
return /\.json$/i.test(pathname);
|
|
110
|
+
} catch {
|
|
111
|
+
return /\.json(?:[?#]|$)/i.test(remoteEntryUrl);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function isSsrEntry(remoteEntryUrl) {
|
|
115
|
+
return /\.ssr\.js(?:[?#].*)?$/.test(remoteEntryUrl);
|
|
116
|
+
}
|
|
100
117
|
function getManifestUrl(remoteEntryUrl) {
|
|
118
|
+
if (isManifestEntry(remoteEntryUrl)) return remoteEntryUrl;
|
|
101
119
|
return remoteEntryUrl.replace(/\/[^/]+$/, "/mf-manifest.json");
|
|
102
120
|
}
|
|
121
|
+
function getEntryFilename(entryUrl) {
|
|
122
|
+
return entryUrl.split("/").pop()?.replace(/[?#].*$/, "").replace(/\.[^.]+$/, "") ?? "remoteEntry";
|
|
123
|
+
}
|
|
124
|
+
function resolveEntryAssetUrl(entry, manifestUrl) {
|
|
125
|
+
const base = manifestUrl.replace(/\/[^/]+$/, "/");
|
|
126
|
+
return new URL(`${entry.path || ""}${entry.name}`, base).href;
|
|
127
|
+
}
|
|
103
128
|
function resolveSSREntryUrl(manifest, manifestUrl) {
|
|
104
129
|
const meta = manifest?.metaData;
|
|
105
130
|
if (!meta?.ssrRemoteEntry?.name) return null;
|
|
@@ -124,48 +149,72 @@ async function headCheckSsrEntry(candidate) {
|
|
|
124
149
|
} catch {}
|
|
125
150
|
return null;
|
|
126
151
|
}
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
function resolveAssetBaseUrl(entryUrl, manifest, manifestUrl) {
|
|
153
|
+
const remoteEntry = manifest?.metaData?.remoteEntry;
|
|
154
|
+
if (remoteEntry?.name) return resolveEntryAssetUrl(remoteEntry, manifestUrl);
|
|
155
|
+
if (!isManifestEntry(entryUrl)) return entryUrl;
|
|
156
|
+
return new URL("remoteEntry.js", manifestUrl.replace(/\/[^/]+$/, "/")).href;
|
|
157
|
+
}
|
|
158
|
+
async function buildEntryContext(entryUrl) {
|
|
159
|
+
const manifestUrl = getManifestUrl(entryUrl);
|
|
160
|
+
const manifest = await fetchManifestCached(manifestUrl);
|
|
161
|
+
const assetBaseUrl = resolveAssetBaseUrl(entryUrl, manifest, manifestUrl);
|
|
162
|
+
return {
|
|
163
|
+
entryUrl,
|
|
164
|
+
manifestUrl,
|
|
165
|
+
manifest,
|
|
166
|
+
assetBaseUrl,
|
|
167
|
+
filename: getEntryFilename(assetBaseUrl),
|
|
168
|
+
remoteOrigin: assetBaseUrl.replace(/\/[^/]+$/, "")
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function buildSsrEntryCandidates(ctx, options = {}) {
|
|
172
|
+
const { assetBaseUrl, filename, remoteOrigin } = ctx;
|
|
173
|
+
const base = assetBaseUrl.replace(/\.[^.]+$/, "");
|
|
174
|
+
const candidates = [];
|
|
175
|
+
if (!options.skipServerBuild) candidates.push({
|
|
176
|
+
url: `${remoteOrigin}/__mf_server__/${filename}.ssr.js`,
|
|
177
|
+
type: "module"
|
|
178
|
+
});
|
|
179
|
+
candidates.push({
|
|
180
|
+
url: `${base}.ssr.js`,
|
|
181
|
+
type: "module"
|
|
182
|
+
}, {
|
|
183
|
+
url: `${remoteOrigin}/__mf_ssr__/${filename}.ssr.js`,
|
|
184
|
+
type: "module"
|
|
185
|
+
});
|
|
186
|
+
return candidates;
|
|
187
|
+
}
|
|
188
|
+
async function resolveFirstReachableCandidate(candidates) {
|
|
145
189
|
for (const candidate of candidates) {
|
|
146
190
|
const hit = await headCheckSsrEntry(candidate);
|
|
147
191
|
if (hit) return hit;
|
|
148
192
|
}
|
|
149
193
|
return null;
|
|
150
194
|
}
|
|
151
|
-
async function
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
195
|
+
async function resolveSSREntryImpl(remoteEntryUrl) {
|
|
196
|
+
if (isSsrEntry(remoteEntryUrl)) return {
|
|
197
|
+
url: remoteEntryUrl,
|
|
198
|
+
type: "module"
|
|
199
|
+
};
|
|
200
|
+
if (!isManifestEntry(remoteEntryUrl)) {
|
|
201
|
+
const filename = getEntryFilename(remoteEntryUrl);
|
|
156
202
|
const fromServerBuild = await headCheckSsrEntry({
|
|
157
|
-
url: `${
|
|
203
|
+
url: `${remoteEntryUrl.replace(/\/[^/]+$/, "")}/__mf_server__/${filename}.ssr.js`,
|
|
158
204
|
type: "module"
|
|
159
205
|
});
|
|
160
206
|
if (fromServerBuild) return fromServerBuild;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
})
|
|
168
|
-
|
|
207
|
+
}
|
|
208
|
+
const ctx = await buildEntryContext(remoteEntryUrl);
|
|
209
|
+
if (ctx.manifest) {
|
|
210
|
+
const fromManifest = resolveSSREntryUrl(ctx.manifest, ctx.manifestUrl);
|
|
211
|
+
if (fromManifest) return fromManifest;
|
|
212
|
+
}
|
|
213
|
+
return resolveFirstReachableCandidate(buildSsrEntryCandidates(ctx, { skipServerBuild: !isManifestEntry(remoteEntryUrl) }));
|
|
214
|
+
}
|
|
215
|
+
async function getSSREntry(remoteEntryUrl) {
|
|
216
|
+
if (!ssrEntryCache.has(remoteEntryUrl)) ssrEntryCache.set(remoteEntryUrl, resolveSSREntryImpl(remoteEntryUrl));
|
|
217
|
+
return ssrEntryCache.get(remoteEntryUrl);
|
|
169
218
|
}
|
|
170
219
|
const tempFileCache = /* @__PURE__ */ new Map();
|
|
171
220
|
let ssrCacheDirPromise;
|
|
@@ -257,11 +306,14 @@ async function loadSSRRemoteEntry(ssrEntry, resolvedShared = {}) {
|
|
|
257
306
|
if (urlObj.pathname.includes("/__mf_ssr__/")) {
|
|
258
307
|
const remoteOrigin = urlObj.origin;
|
|
259
308
|
const runner = await getOrCreateRunner(remoteOrigin);
|
|
260
|
-
if (!runner)
|
|
261
|
-
|
|
262
|
-
|
|
309
|
+
if (!runner) {
|
|
310
|
+
if (process.env.NODE_ENV !== "production") return null;
|
|
311
|
+
} else try {
|
|
312
|
+
const mod = await runner.import(urlObj.pathname);
|
|
313
|
+
if (mod && typeof mod === "object" && "init" in mod) return mod;
|
|
314
|
+
if (process.env.NODE_ENV !== "production") return null;
|
|
263
315
|
} catch {
|
|
264
|
-
return null;
|
|
316
|
+
if (process.env.NODE_ENV !== "production") return null;
|
|
265
317
|
}
|
|
266
318
|
}
|
|
267
319
|
const { mkdirSync } = await _fs();
|