@module-federation/vite 1.23.4 → 1.23.5
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/lib/{dtsConstants-DSTzyKSG.js → dtsConstants-BQdFpgKb.js} +92 -12
- package/lib/index.js +208 -63
- package/lib/{pluginDts-CVyHPAEq.js → pluginDts-DShMdjzR.js} +1 -1
- package/lib/{sharedKeyMatcher-Od_nYxJA.js → sharedKeyMatcher-CHp4QRNq.js} +1 -1
- package/lib/{ssrEntryLoader-DjZj-5Lw.js → ssrEntryLoader-CHdWk8Yg.js} +31 -17
- package/lib/{ssrVmStrategy-Dk5xXVvR.js → ssrVmStrategy-BkyvcG4s.js} +2 -2
- package/lib/utils/ssrEntryLoader.d.ts +2 -1
- package/lib/utils/ssrEntryLoader.js +2 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as getNodeModulesSuffix, r as getSharedRuntimeKey } from "./sharedKeyMatcher-
|
|
2
|
-
import { r as mfWarn, t as createModuleFederationError } from "./logger-DOwfTlw5.js";
|
|
1
|
+
import { d as getNodeModulesSuffix, r as getSharedRuntimeKey } from "./sharedKeyMatcher-CHp4QRNq.js";
|
|
2
|
+
import { l as normalizePathForImport, r as mfWarn, t as createModuleFederationError } from "./logger-DOwfTlw5.js";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync, realpathSync } from "fs";
|
|
4
4
|
import { createRequire } from "module";
|
|
5
5
|
import * as path$1 from "node:path";
|
|
@@ -93,22 +93,34 @@ function substituteExportsWildcard(target, patternMatch) {
|
|
|
93
93
|
}
|
|
94
94
|
return target;
|
|
95
95
|
}
|
|
96
|
+
/** Splits an exports pattern at its wildcard. Node substitutes only the first one, so a second never matches. */
|
|
97
|
+
function splitExportsPattern(pattern) {
|
|
98
|
+
const wildcardIndex = pattern.indexOf("*");
|
|
99
|
+
if (wildcardIndex === -1) return void 0;
|
|
100
|
+
const trailer = pattern.slice(wildcardIndex + 1);
|
|
101
|
+
if (trailer.includes("*")) return void 0;
|
|
102
|
+
return {
|
|
103
|
+
base: pattern.slice(0, wildcardIndex),
|
|
104
|
+
trailer
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** The text `value` substitutes for the wildcard of a pattern split by `splitExportsPattern`. */
|
|
108
|
+
function matchExportsPatternPart(value, { base, trailer }) {
|
|
109
|
+
if (!value.startsWith(base) || !value.endsWith(trailer)) return void 0;
|
|
110
|
+
if (value.length <= base.length + trailer.length) return void 0;
|
|
111
|
+
return value.slice(base.length, value.length - trailer.length);
|
|
112
|
+
}
|
|
96
113
|
function matchExportsSubpath(record, subpath) {
|
|
97
114
|
if (subpath in record) return record[subpath];
|
|
98
115
|
let bestKey;
|
|
99
116
|
let bestBaseLength = -1;
|
|
100
117
|
let bestKeyLength = -1;
|
|
101
118
|
for (const key of Object.keys(record)) {
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
const patternTrailer = key.slice(wildcardIndex + 1);
|
|
106
|
-
if (patternTrailer.includes("*")) continue;
|
|
107
|
-
if (!subpath.startsWith(patternBase) || !subpath.endsWith(patternTrailer)) continue;
|
|
108
|
-
if (subpath.length <= patternBase.length + patternTrailer.length) continue;
|
|
109
|
-
if (patternBase.length > bestBaseLength || patternBase.length === bestBaseLength && key.length > bestKeyLength) {
|
|
119
|
+
const pattern = splitExportsPattern(key);
|
|
120
|
+
if (!pattern || matchExportsPatternPart(subpath, pattern) === void 0) continue;
|
|
121
|
+
if (pattern.base.length > bestBaseLength || pattern.base.length === bestBaseLength && key.length > bestKeyLength) {
|
|
110
122
|
bestKey = key;
|
|
111
|
-
bestBaseLength =
|
|
123
|
+
bestBaseLength = pattern.base.length;
|
|
112
124
|
bestKeyLength = key.length;
|
|
113
125
|
}
|
|
114
126
|
}
|
|
@@ -139,6 +151,74 @@ function isPackageExportAvailable(pkg, opts = {}) {
|
|
|
139
151
|
if (installed?.packageJson.exports == null) return true;
|
|
140
152
|
return resolveExportsEntry(getPackageExportsTarget(pkg, packageName, installed.packageJson.exports), opts.conditions) !== void 0;
|
|
141
153
|
}
|
|
154
|
+
function stripRelativePrefix(target) {
|
|
155
|
+
return normalizePathForImport(target).replace(/^\.\//, "");
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Specifiers the installed package publishes for the file at `relFilePath` — a path below the
|
|
159
|
+
* package root, such as `dist/button.js` — ordered most specific first.
|
|
160
|
+
*
|
|
161
|
+
* `exports` maps specifiers to files, so a specifier rebuilt from a resolved path is only valid
|
|
162
|
+
* when the package happens to publish its files at the paths they occupy on disk. A package that
|
|
163
|
+
* remaps directories (`"./*": "./dist/*.js"`) publishes `pkg/button` and never
|
|
164
|
+
* `pkg/dist/button.js`, so the rebuilt specifier names a file the package does not export.
|
|
165
|
+
* Reversing the map recovers the specifiers that do resolve back to that file.
|
|
166
|
+
*
|
|
167
|
+
* Candidates are ordered by the same precedence `matchExportsSubpath` applies when resolving
|
|
168
|
+
* forwards — exact keys, then the longest pattern prefix, then the longest key — so a caller
|
|
169
|
+
* that takes the first match picks the same specifier for a file in every build, and in every
|
|
170
|
+
* container that shares the package.
|
|
171
|
+
*
|
|
172
|
+
* Empty when the package exports nothing that resolves to the file, which is the case for its
|
|
173
|
+
* internals and for subpaths an explicit `null` blocks. Lenient when the package cannot be found
|
|
174
|
+
* or has no `exports`, matching `isPackageExportAvailable`: every file is then reachable at its
|
|
175
|
+
* own path, so the path is the specifier.
|
|
176
|
+
*/
|
|
177
|
+
function getPackageExportSpecifiersForFile(packageName, relFilePath, opts = {}) {
|
|
178
|
+
const file = `./${stripRelativePrefix(relFilePath)}`;
|
|
179
|
+
const toSpecifier = (subpath) => subpath === "." ? packageName : `${packageName}${subpath.slice(1)}`;
|
|
180
|
+
const exportsField = getInstalledPackageJson(packageName, opts)?.packageJson.exports;
|
|
181
|
+
if (exportsField == null) return [toSpecifier(file)];
|
|
182
|
+
if (typeof exportsField === "string") return stripRelativePrefix(exportsField) === stripRelativePrefix(file) ? [packageName] : [];
|
|
183
|
+
if (typeof exportsField !== "object") return [];
|
|
184
|
+
const record = exportsField;
|
|
185
|
+
const subpathKeys = Object.keys(record).filter((key) => key.startsWith("."));
|
|
186
|
+
if (subpathKeys.length === 0) {
|
|
187
|
+
const target = resolveExportsEntry(record, opts.conditions);
|
|
188
|
+
return typeof target === "string" && stripRelativePrefix(target) === stripRelativePrefix(file) ? [packageName] : [];
|
|
189
|
+
}
|
|
190
|
+
const candidates = [];
|
|
191
|
+
for (const key of subpathKeys) {
|
|
192
|
+
if (!key.includes("*")) {
|
|
193
|
+
candidates.push({
|
|
194
|
+
subpath: key,
|
|
195
|
+
isPattern: false,
|
|
196
|
+
baseLength: key.length,
|
|
197
|
+
keyLength: key.length
|
|
198
|
+
});
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const keyPattern = splitExportsPattern(key);
|
|
202
|
+
if (!keyPattern) continue;
|
|
203
|
+
const target = resolveExportsEntry(record[key], opts.conditions);
|
|
204
|
+
const targetPattern = typeof target === "string" ? splitExportsPattern(target) : void 0;
|
|
205
|
+
if (!targetPattern) continue;
|
|
206
|
+
const patternMatch = matchExportsPatternPart(file, targetPattern);
|
|
207
|
+
if (patternMatch === void 0) continue;
|
|
208
|
+
candidates.push({
|
|
209
|
+
subpath: keyPattern.base + patternMatch + keyPattern.trailer,
|
|
210
|
+
isPattern: true,
|
|
211
|
+
baseLength: keyPattern.base.length,
|
|
212
|
+
keyLength: key.length
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const verified = candidates.filter((candidate) => {
|
|
216
|
+
const target = resolveExportsEntry(getPackageExportsTarget(toSpecifier(candidate.subpath), packageName, record), opts.conditions);
|
|
217
|
+
return typeof target === "string" && stripRelativePrefix(target) === stripRelativePrefix(file);
|
|
218
|
+
});
|
|
219
|
+
verified.sort((a, b) => Number(a.isPattern) - Number(b.isPattern) || b.baseLength - a.baseLength || b.keyLength - a.keyLength || (a.subpath < b.subpath ? -1 : a.subpath > b.subpath ? 1 : 0));
|
|
220
|
+
return [...new Set(verified.map((candidate) => toSpecifier(candidate.subpath)))];
|
|
221
|
+
}
|
|
142
222
|
/**
|
|
143
223
|
* Escaping rules:
|
|
144
224
|
* Convert using the format __${mapping}__, where _ and $ are not allowed in npm package names but can be used in variable names.
|
|
@@ -664,4 +744,4 @@ function hasPackageDependency(dependencyName, cwd = packageDetectionCwd || proce
|
|
|
664
744
|
//#region src/utils/dtsConstants.ts
|
|
665
745
|
const DEFAULT_PUBLIC_TYPES_FOLDER = "@mf-types";
|
|
666
746
|
//#endregion
|
|
667
|
-
export {
|
|
747
|
+
export { REACT_DOM_CLIENT_SHARE as C, REACT_CLIENT_INTERNALS_KEY as S, resolveImportPath as _, getIsRolldown as a, sharedCacheHelperCode as b, getPackageName as c, hasPackageDependency as d, isNuxtProjectRoot as f, packageNameEncode as g, packageNameDecode as h, getInstalledPackageJson as i, getPackageNameFromNodeModulePath as l, isPackageInstalled as m, getDependencyNames as n, getPackageDetectionCwd as o, isPackageExportAvailable as p, getInstalledPackageEntry as r, getPackageExportSpecifiersForFile as s, DEFAULT_PUBLIC_TYPES_FOLDER as t, getSharedCacheDescriptor as u, resolveModulePath as v, isReactCoreShare as w, supportsCodeSplittingGroupDebugName as x, setPackageDetectionCwd as y };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as removeTrailingSlash, a as matchesSharedSource, b as stripViteFsPrefix, c as filterId, d as getNodeModulesSuffix, f as isAssetLikeImport, g as normalizeNodeModulePath, h as isViteOptimizableEntry, i as invalidateSharedKeyMatcher, l as getBasePath$1, m as isNuxtClientBase, n as getSharedRequest, p as isNodeModulePath, r as getSharedRuntimeKey, s as ensureTrailingSlash, t as findSharedKey, u as getCommonSharedSubpaths, v as resolvePublicPath, y as stripQueryAndHash } from "./sharedKeyMatcher-CHp4QRNq.js";
|
|
2
2
|
import { a as CodeRewriter, c as isAbsoluteUrl, d as resolveHashPlaceholderFileName, i as createCodePositionMap, l as normalizePathForImport, o as createSourceMap, r as mfWarn, t as createModuleFederationError, u as rebaseImport } from "./logger-DOwfTlw5.js";
|
|
3
|
-
import { C as
|
|
3
|
+
import { C as REACT_DOM_CLIENT_SHARE, S as REACT_CLIENT_INTERNALS_KEY, _ as resolveImportPath, a as getIsRolldown, b as sharedCacheHelperCode, c as getPackageName, d as hasPackageDependency, f as isNuxtProjectRoot, g as packageNameEncode, h as packageNameDecode, i as getInstalledPackageJson, l as getPackageNameFromNodeModulePath, m as isPackageInstalled, n as getDependencyNames, o as getPackageDetectionCwd, p as isPackageExportAvailable, r as getInstalledPackageEntry, s as getPackageExportSpecifiersForFile, u as getSharedCacheDescriptor, v as resolveModulePath, w as isReactCoreShare, x as supportsCodeSplittingGroupDebugName, y as setPackageDetectionCwd } from "./dtsConstants-BQdFpgKb.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import * as fs$2 from "fs";
|
|
6
6
|
import { existsSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "fs";
|
|
@@ -977,6 +977,16 @@ function getSsrCapabilities(viteMajor, command, hasRemotes, isSsr = false) {
|
|
|
977
977
|
};
|
|
978
978
|
}
|
|
979
979
|
//#endregion
|
|
980
|
+
//#region src/utils/runtimePluginSpecifier.ts
|
|
981
|
+
function getRuntimePluginSpecifier(plugin) {
|
|
982
|
+
return typeof plugin === "string" ? plugin : plugin[0];
|
|
983
|
+
}
|
|
984
|
+
/** Drop SSR-only plugins from a client graph; a server graph keeps them all. */
|
|
985
|
+
function filterRuntimePluginsForTarget(runtimePlugins, ssrOnlySpecifiers, isServer) {
|
|
986
|
+
if (isServer) return [...runtimePlugins];
|
|
987
|
+
return runtimePlugins.filter((plugin) => !ssrOnlySpecifiers.has(getRuntimePluginSpecifier(plugin)));
|
|
988
|
+
}
|
|
989
|
+
//#endregion
|
|
980
990
|
//#region src/utils/serializeRuntimeOptions.ts
|
|
981
991
|
const UNSAFE_JS_CHAR_MAP = {
|
|
982
992
|
"<": "\\u003C",
|
|
@@ -1074,16 +1084,6 @@ function isParsableExpression(source) {
|
|
|
1074
1084
|
}
|
|
1075
1085
|
}
|
|
1076
1086
|
//#endregion
|
|
1077
|
-
//#region src/utils/runtimePluginSpecifier.ts
|
|
1078
|
-
function getRuntimePluginSpecifier(plugin) {
|
|
1079
|
-
return typeof plugin === "string" ? plugin : plugin[0];
|
|
1080
|
-
}
|
|
1081
|
-
/** Drop SSR-only plugins from a client graph; a server graph keeps them all. */
|
|
1082
|
-
function filterRuntimePluginsForTarget(runtimePlugins, ssrOnlySpecifiers, isServer) {
|
|
1083
|
-
if (isServer) return [...runtimePlugins];
|
|
1084
|
-
return runtimePlugins.filter((plugin) => !ssrOnlySpecifiers.has(getRuntimePluginSpecifier(plugin)));
|
|
1085
|
-
}
|
|
1086
|
-
//#endregion
|
|
1087
1087
|
//#region src/utils/importAnalysis.ts
|
|
1088
1088
|
const analysisByBuild = /* @__PURE__ */ new WeakMap();
|
|
1089
1089
|
/**
|
|
@@ -2281,8 +2281,37 @@ function hasCodeMatch(source, regex, codePositions) {
|
|
|
2281
2281
|
while ((match = regex.exec(source)) !== null) if (codePositions[match.index]) return true;
|
|
2282
2282
|
return false;
|
|
2283
2283
|
}
|
|
2284
|
+
/**
|
|
2285
|
+
* True when the file contains a top-level static `import`/`export` declaration.
|
|
2286
|
+
* Local identifiers named `module` or `exports` (webpack/rspack helpers,
|
|
2287
|
+
* function parameters, etc.) must not override that module format.
|
|
2288
|
+
*/
|
|
2289
|
+
function hasEsmModuleSyntax(source, codePositions) {
|
|
2290
|
+
const keywordRegex = /(?<![$\w])(?:import|export)\b/g;
|
|
2291
|
+
let match;
|
|
2292
|
+
let braceDepth = 0;
|
|
2293
|
+
let braceScanIndex = 0;
|
|
2294
|
+
while ((match = keywordRegex.exec(source)) !== null) {
|
|
2295
|
+
for (; braceScanIndex < match.index; braceScanIndex++) {
|
|
2296
|
+
if (!codePositions[braceScanIndex]) continue;
|
|
2297
|
+
if (source[braceScanIndex] === "{") braceDepth++;
|
|
2298
|
+
else if (source[braceScanIndex] === "}") braceDepth--;
|
|
2299
|
+
}
|
|
2300
|
+
if (!codePositions[match.index]) continue;
|
|
2301
|
+
if (braceDepth !== 0) continue;
|
|
2302
|
+
let previousCodeIndex = match.index - 1;
|
|
2303
|
+
while (previousCodeIndex >= 0 && (/\s/.test(source[previousCodeIndex]) || !codePositions[previousCodeIndex])) previousCodeIndex--;
|
|
2304
|
+
if (source[previousCodeIndex] === ".") continue;
|
|
2305
|
+
let nextCodeIndex = match.index + match[0].length;
|
|
2306
|
+
while (nextCodeIndex < source.length && (/\s/.test(source[nextCodeIndex]) || !codePositions[nextCodeIndex])) nextCodeIndex++;
|
|
2307
|
+
if (source[nextCodeIndex] === "(") continue;
|
|
2308
|
+
return true;
|
|
2309
|
+
}
|
|
2310
|
+
return false;
|
|
2311
|
+
}
|
|
2284
2312
|
function hasCommonJsExports(source) {
|
|
2285
2313
|
const codePositions = createCodePositionMap(source);
|
|
2314
|
+
if (hasEsmModuleSyntax(source, codePositions)) return false;
|
|
2286
2315
|
if (hasCodeMatch(source, /\bmodule\s*(?:\.exports|\[\s*['"]exports['"]\s*\])/g, codePositions)) return true;
|
|
2287
2316
|
const exportsRegex = /\bexports\s*(?:\.|\[|[,)]|=(?!=|>))/g;
|
|
2288
2317
|
let match;
|
|
@@ -2895,7 +2924,15 @@ function getWorkspacePackageJson(pkg) {
|
|
|
2895
2924
|
fromResolvedEntry: resolved
|
|
2896
2925
|
})?.packageJson;
|
|
2897
2926
|
}
|
|
2927
|
+
const sharedDependencyGraphPackageJsonCache = /* @__PURE__ */ new Map();
|
|
2898
2928
|
function getSharedDependencyGraphPackageJson(pkg) {
|
|
2929
|
+
const cacheKey = `${getPackageDetectionCwd()}\0${pkg}`;
|
|
2930
|
+
if (sharedDependencyGraphPackageJsonCache.has(cacheKey)) return sharedDependencyGraphPackageJsonCache.get(cacheKey);
|
|
2931
|
+
const packageJson = resolveSharedDependencyGraphPackageJson(pkg);
|
|
2932
|
+
sharedDependencyGraphPackageJsonCache.set(cacheKey, packageJson);
|
|
2933
|
+
return packageJson;
|
|
2934
|
+
}
|
|
2935
|
+
function resolveSharedDependencyGraphPackageJson(pkg) {
|
|
2899
2936
|
const installedPackageJson = getInstalledPackageJson(pkg, { packageName: getPackageName(pkg) })?.packageJson;
|
|
2900
2937
|
if (installedPackageJson) return installedPackageJson;
|
|
2901
2938
|
try {
|
|
@@ -2904,7 +2941,16 @@ function getSharedDependencyGraphPackageJson(pkg) {
|
|
|
2904
2941
|
} catch {}
|
|
2905
2942
|
return getWorkspacePackageJson(pkg);
|
|
2906
2943
|
}
|
|
2944
|
+
const sharedSingletonConsumedByPeerCache = /* @__PURE__ */ new WeakMap();
|
|
2907
2945
|
function isSharedSingletonConsumedByPeer(pkg, options = getNormalizeModuleFederationOptions(), requireFederationRuntimeDependency = false) {
|
|
2946
|
+
if (!options) return computeSharedSingletonConsumedByPeer(pkg, options, requireFederationRuntimeDependency);
|
|
2947
|
+
let cache = sharedSingletonConsumedByPeerCache.get(options);
|
|
2948
|
+
if (!cache) sharedSingletonConsumedByPeerCache.set(options, cache = /* @__PURE__ */ new Map());
|
|
2949
|
+
const cacheKey = `${getPackageDetectionCwd()}\0${pkg}\0${requireFederationRuntimeDependency}`;
|
|
2950
|
+
if (!cache.has(cacheKey)) cache.set(cacheKey, computeSharedSingletonConsumedByPeer(pkg, options, requireFederationRuntimeDependency));
|
|
2951
|
+
return cache.get(cacheKey);
|
|
2952
|
+
}
|
|
2953
|
+
function computeSharedSingletonConsumedByPeer(pkg, options, requireFederationRuntimeDependency) {
|
|
2908
2954
|
const shared = options?.shared || {};
|
|
2909
2955
|
if (!requireFederationRuntimeDependency && Object.entries(shared).some(([key, item]) => key !== pkg && key.startsWith(`${pkg}/`) && item.shareConfig.singleton === true)) return true;
|
|
2910
2956
|
const sharedKeyByPackageName = /* @__PURE__ */ new Map();
|
|
@@ -3356,6 +3402,7 @@ function generateLazyWorkspaceSingletonExports(edges, namedExports, importSource
|
|
|
3356
3402
|
const trackPendingLoad = `__mfTrackPendingShareLoad(${deferredEntryFallback ? deferredEntryLoad : deferredInitLoad});`;
|
|
3357
3403
|
return `${declarations}
|
|
3358
3404
|
const __mfApplyLazyShareExports = (mod) => {
|
|
3405
|
+
exportModule = mod;
|
|
3359
3406
|
${assignments}
|
|
3360
3407
|
};
|
|
3361
3408
|
__mfSubscribeSharedCache(__mfModuleCache.share, ${cacheDescriptor}, __mfApplyLazyShareExports);
|
|
@@ -3369,7 +3416,7 @@ function generateLazyWorkspaceSingletonExports(edges, namedExports, importSource
|
|
|
3369
3416
|
} else {
|
|
3370
3417
|
__mfApplyLazyShareExports(exportModule);
|
|
3371
3418
|
}
|
|
3372
|
-
export { __mf_default as default };${namedExportLine}${mutableExportLine}`;
|
|
3419
|
+
export { __mf_default as default, exportModule as __moduleExports };${namedExportLine}${mutableExportLine}`;
|
|
3373
3420
|
}
|
|
3374
3421
|
const WORKSPACE_SINGLETON_SSR_LOCAL_SHARE = "__mfNormalizeShareModule(__mfLocalShare)";
|
|
3375
3422
|
function prependWorkspaceSingletonSsrImport(code) {
|
|
@@ -3769,7 +3816,24 @@ function generateLocalSharedImportMap(options) {
|
|
|
3769
3816
|
// A host seed from an older React family is not coherent with the newer cached react
|
|
3770
3817
|
const cachedVersion = cached?.version ?? cached?.default?.version;
|
|
3771
3818
|
if (cachedVersion !== undefined && isOlder(cachedVersion)) continue;
|
|
3772
|
-
if (!requiredExport || typeof cached?.[requiredExport] === 'function' || typeof cached?.default?.[requiredExport] === 'function')
|
|
3819
|
+
if (!requiredExport || typeof cached?.[requiredExport] === 'function' || typeof cached?.default?.[requiredExport] === 'function') {
|
|
3820
|
+
const dom = typeof cached?.[requiredExport] === 'function' ? cached : cached?.default;
|
|
3821
|
+
const internals = dom?.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
3822
|
+
if (!requiredExport || key.endsWith('/client') || !internals) return cached;
|
|
3823
|
+
// React 18 root: mirror react-dom/client.js, or createRoot warns it was imported from "react-dom"
|
|
3824
|
+
const client = {};
|
|
3825
|
+
for (const name of ['createRoot', 'hydrateRoot']) {
|
|
3826
|
+
client[name] = (...args) => {
|
|
3827
|
+
internals.usingClientEntryPoint = true;
|
|
3828
|
+
try {
|
|
3829
|
+
return dom[name](...args);
|
|
3830
|
+
} finally {
|
|
3831
|
+
internals.usingClientEntryPoint = false;
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
}
|
|
3835
|
+
return { ...client, default: client };
|
|
3836
|
+
}
|
|
3773
3837
|
}
|
|
3774
3838
|
return undefined;
|
|
3775
3839
|
};
|
|
@@ -3992,7 +4056,8 @@ function getMaterializedShares(options) {
|
|
|
3992
4056
|
const dependencies = {
|
|
3993
4057
|
...packageJson?.dependencies || {},
|
|
3994
4058
|
...packageJson?.peerDependencies || {},
|
|
3995
|
-
...packageJson?.optionalDependencies || {}
|
|
4059
|
+
...packageJson?.optionalDependencies || {},
|
|
4060
|
+
...packageJson?.peerDependenciesMeta || {}
|
|
3996
4061
|
};
|
|
3997
4062
|
for (const dependency of Object.keys(dependencies)) {
|
|
3998
4063
|
const sharedDependency = configured.get(dependency);
|
|
@@ -4028,7 +4093,8 @@ function getSharePrerequisites(ordered) {
|
|
|
4028
4093
|
const dependencies = {
|
|
4029
4094
|
...packageJson?.dependencies || {},
|
|
4030
4095
|
...packageJson?.peerDependencies || {},
|
|
4031
|
-
...packageJson?.optionalDependencies || {}
|
|
4096
|
+
...packageJson?.optionalDependencies || {},
|
|
4097
|
+
...packageJson?.peerDependenciesMeta || {}
|
|
4032
4098
|
};
|
|
4033
4099
|
const prerequisites = Object.keys(dependencies).map((dependency) => roots.get(dependency)).filter((dependency) => Boolean(dependency));
|
|
4034
4100
|
if (pkg !== packageName && (packageName === "react" || packageName === "react-dom")) {
|
|
@@ -4072,7 +4138,8 @@ function orderSharedDependenciesFirst(sharedPackages) {
|
|
|
4072
4138
|
const dependencies = {
|
|
4073
4139
|
...packageJson?.dependencies || {},
|
|
4074
4140
|
...packageJson?.peerDependencies || {},
|
|
4075
|
-
...packageJson?.optionalDependencies || {}
|
|
4141
|
+
...packageJson?.optionalDependencies || {},
|
|
4142
|
+
...packageJson?.peerDependenciesMeta || {}
|
|
4076
4143
|
};
|
|
4077
4144
|
Object.keys(dependencies).forEach((dependency) => {
|
|
4078
4145
|
const sharedDependency = sharedKeyByPackageName.get(dependency);
|
|
@@ -4312,21 +4379,33 @@ const externalSharedProviderSelectionHelperCode = `const __mfSelectExternalShare
|
|
|
4312
4379
|
/**
|
|
4313
4380
|
* A consume-only stub never outranks a provider: when registering this container's
|
|
4314
4381
|
* `import: false` share replaces an unloaded provider of the same version (#1311),
|
|
4315
|
-
* the `afterRegisterShare` hook restores the provider
|
|
4382
|
+
* the `afterRegisterShare` hook restores the provider, and a provider kept out by an
|
|
4383
|
+
* unloaded stub takes its slot. Registered once per instance.
|
|
4316
4384
|
*/
|
|
4317
4385
|
function generateKeepProvidersOverStubsCode(runtimeVar) {
|
|
4318
4386
|
return `if (!${runtimeVar}.__mfKeepAdoptedProviders) {
|
|
4319
4387
|
${runtimeVar}.__mfKeepAdoptedProviders = true;
|
|
4320
4388
|
${runtimeVar}.sharedHandler?.hooks?.lifecycle?.afterRegisterShare?.on?.((args) => {
|
|
4321
4389
|
const { shared, previousShared, registeredShared } = args || {};
|
|
4390
|
+
const versions = ${runtimeVar}.shareScopeMap?.[args.scope]?.[args.pkgName];
|
|
4391
|
+
if (!shared || !versions) return;
|
|
4392
|
+
// The reverse: a stub already in the slot (e.g. a loaded-first parent's) keeps a provider
|
|
4393
|
+
// out, and a webpack consumer reading the scope then falls back to its own copy.
|
|
4394
|
+
if (shared.shareConfig?.import !== false) {
|
|
4395
|
+
if (
|
|
4396
|
+
registeredShared !== shared &&
|
|
4397
|
+
registeredShared?.shareConfig?.import === false &&
|
|
4398
|
+
!registeredShared.loaded &&
|
|
4399
|
+
versions[shared.version] === registeredShared
|
|
4400
|
+
) versions[shared.version] = shared;
|
|
4401
|
+
return;
|
|
4402
|
+
}
|
|
4322
4403
|
if (
|
|
4323
|
-
shared?.shareConfig?.import !== false ||
|
|
4324
4404
|
registeredShared !== shared ||
|
|
4325
4405
|
!previousShared ||
|
|
4326
4406
|
previousShared.shareConfig?.import === false
|
|
4327
4407
|
) return;
|
|
4328
|
-
|
|
4329
|
-
if (versions && versions[shared.version] === shared) versions[shared.version] = previousShared;
|
|
4408
|
+
if (versions[shared.version] === shared) versions[shared.version] = previousShared;
|
|
4330
4409
|
});
|
|
4331
4410
|
}`;
|
|
4332
4411
|
}
|
|
@@ -4510,7 +4589,7 @@ function generateRuntimeSharedCacheSeedCode(shareStrategy, options, command = "b
|
|
|
4510
4589
|
var __mfDeferredSeedKeys = __mfSeedKeys.filter(
|
|
4511
4590
|
(pkg) => __mfPreInitBlockedSeedKeys.has(__mfSeedIndex.get(pkg))
|
|
4512
4591
|
);
|
|
4513
|
-
await __mfSeedLocalShared(__mfImmediateSeedKeys);`;
|
|
4592
|
+
await __mfSeedLocalShared(__mfImmediateSeedKeys).catch(__mfRejectInit);`;
|
|
4514
4593
|
}
|
|
4515
4594
|
function getBrowserImportPath(importPath) {
|
|
4516
4595
|
if (/^(?:[a-zA-Z]:[\\/]|\/)/.test(importPath) && !importPath.startsWith("/@")) return `/@fs/${importPath}`;
|
|
@@ -4761,7 +4840,12 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
4761
4840
|
${runtimeHelperImports.length ? `import {${runtimeHelperImports.join(", ")}} from "@module-federation/runtime/helpers";` : ""}
|
|
4762
4841
|
${pluginImportNames.filter((item) => !isSsrOnlyPlugin(item[1])).map((item) => item[1]).join("\n")}
|
|
4763
4842
|
import __mfExposesMap from "${virtualExposesId}"
|
|
4764
|
-
${command === "build" ? getRuntimeInitResolveBootstrapCode(false, getRuntimeInitStatusImportId(options)) : getRuntimeInitBootstrapCode(false, getRuntimeInitStatusImportId(options), void 0, void 0, exportConditions) + "\n const { initResolve } = globalThis[globalKey];"}
|
|
4843
|
+
${command === "build" ? getRuntimeInitResolveBootstrapCode(false, getRuntimeInitStatusImportId(options)) + "\n const { initReject } = __mfResolveState;" : getRuntimeInitBootstrapCode(false, getRuntimeInitStatusImportId(options), void 0, void 0, exportConditions) + "\n const { initResolve, initReject } = globalThis[globalKey];"}
|
|
4844
|
+
// A failed seed must settle initPromise, or every pending share load hangs forever.
|
|
4845
|
+
const __mfRejectInit = (err) => {
|
|
4846
|
+
initReject(err);
|
|
4847
|
+
throw err;
|
|
4848
|
+
};
|
|
4765
4849
|
${getRuntimeModuleCacheBootstrapCode(exportConditions)}
|
|
4766
4850
|
const initTokens = {}
|
|
4767
4851
|
const shareScopeNames = Array.isArray(${toSafeJsLiteral(options.shareScope)}) ? ${toSafeJsLiteral(options.shareScope)} : [${toSafeJsLiteral(options.shareScope)}]
|
|
@@ -5655,7 +5739,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
5655
5739
|
__mfReadyDeferredSeedKeys.push(...__mfDeferredSeedKeys.filter(
|
|
5656
5740
|
(pkg) => !__mfBlockedSeedKeys.has(__mfSeedIndex.get(pkg))
|
|
5657
5741
|
));
|
|
5658
|
-
await __mfSeedLocalShared(__mfReadyDeferredSeedKeys);
|
|
5742
|
+
await __mfSeedLocalShared(__mfReadyDeferredSeedKeys).catch(__mfRejectInit);
|
|
5659
5743
|
${command === "build" ? `// A consume-only share reached only through import() is bridged when that import runs
|
|
5660
5744
|
// (see pluginLazyConsumeOnlyShares), through the same provider selection init() uses.
|
|
5661
5745
|
const __mfLazyShareLoads = new Map();
|
|
@@ -8266,7 +8350,7 @@ function ${helperName}(names) {
|
|
|
8266
8350
|
}
|
|
8267
8351
|
//#endregion
|
|
8268
8352
|
//#region package.json
|
|
8269
|
-
var version$1 = "1.23.
|
|
8353
|
+
var version$1 = "1.23.5";
|
|
8270
8354
|
//#endregion
|
|
8271
8355
|
//#region src/virtualModules/virtualExposesSSR.ts
|
|
8272
8356
|
/**
|
|
@@ -8988,43 +9072,89 @@ function getStatsFileName(manifestFileName) {
|
|
|
8988
9072
|
//#endregion
|
|
8989
9073
|
//#region src/utils/sharedSource.ts
|
|
8990
9074
|
const pendingEntryLookups = /* @__PURE__ */ new Map();
|
|
9075
|
+
const pendingLookupImporters = /* @__PURE__ */ new Map();
|
|
9076
|
+
const increment = (map, key) => map.set(key, (map.get(key) ?? 0) + 1);
|
|
9077
|
+
const decrement = (map, key) => {
|
|
9078
|
+
const remaining = map.get(key) - 1;
|
|
9079
|
+
if (remaining) map.set(key, remaining);
|
|
9080
|
+
else map.delete(key);
|
|
9081
|
+
};
|
|
8991
9082
|
const getEntryLookupKey = (source, importer) => `${source}\0${importer}`;
|
|
9083
|
+
/**
|
|
9084
|
+
* Rolldown saves each this.resolve() call's options under the map's current size and deletes the
|
|
9085
|
+
* entry when the call settles, so an overlapping call can receive the wrong `custom` metadata.
|
|
9086
|
+
* Taking the first free key keeps every in-flight entry intact. A no-op when the internals differ.
|
|
9087
|
+
*/
|
|
9088
|
+
function patchRolldownResolveOptionKeys(context) {
|
|
9089
|
+
const data = context?.data;
|
|
9090
|
+
const map = data?.resolveOptionsMap;
|
|
9091
|
+
if (!data || !(map instanceof Map) || typeof data.saveResolveOptions !== "function") return;
|
|
9092
|
+
if (data.__mfFreeKeyPatch) return;
|
|
9093
|
+
data.saveResolveOptions = (options) => {
|
|
9094
|
+
let index = map.size;
|
|
9095
|
+
while (map.has(index)) index++;
|
|
9096
|
+
map.set(index, options);
|
|
9097
|
+
return index;
|
|
9098
|
+
};
|
|
9099
|
+
data.__mfFreeKeyPatch = true;
|
|
9100
|
+
}
|
|
8992
9101
|
/** Whether a resolveId call is one of the shared source resolver's own entry lookups. */
|
|
8993
9102
|
function isSharedEntryLookup(source, importer, options) {
|
|
8994
|
-
|
|
9103
|
+
if (pendingEntryLookups.has(getEntryLookupKey(source, importer))) return true;
|
|
9104
|
+
return options?.custom?.__mfSharedEntryLookupImporter === importer && pendingLookupImporters.has(importer);
|
|
8995
9105
|
}
|
|
8996
9106
|
/**
|
|
8997
9107
|
* Runs one of the plugin's own `this.resolve()` calls (a shared entry lookup, a
|
|
8998
|
-
* parse-barrier external probe),
|
|
9108
|
+
* parse-barrier external probe), tracked so `isSharedEntryLookup` recognizes it
|
|
8999
9109
|
* and the share hooks neither proxy it nor register a used share for it.
|
|
9000
9110
|
*/
|
|
9001
9111
|
async function resolveInternally(context, source, importer, options = {}) {
|
|
9002
9112
|
const lookupKey = getEntryLookupKey(source, importer);
|
|
9003
|
-
pendingEntryLookups
|
|
9113
|
+
increment(pendingEntryLookups, lookupKey);
|
|
9114
|
+
increment(pendingLookupImporters, importer);
|
|
9004
9115
|
try {
|
|
9005
9116
|
return await context.resolve(source, importer, {
|
|
9006
9117
|
...options,
|
|
9007
|
-
skipSelf: true,
|
|
9008
9118
|
custom: {
|
|
9009
9119
|
...options.custom,
|
|
9010
|
-
|
|
9011
|
-
}
|
|
9120
|
+
__mfSharedEntryLookupImporter: importer
|
|
9121
|
+
},
|
|
9122
|
+
skipSelf: true
|
|
9012
9123
|
});
|
|
9013
9124
|
} finally {
|
|
9014
|
-
|
|
9015
|
-
|
|
9016
|
-
else pendingEntryLookups.delete(lookupKey);
|
|
9125
|
+
decrement(pendingEntryLookups, lookupKey);
|
|
9126
|
+
decrement(pendingLookupImporters, importer);
|
|
9017
9127
|
}
|
|
9018
9128
|
}
|
|
9019
9129
|
/** Identify shared entries through Vite, with a cache scoped to this federation instance. */
|
|
9020
9130
|
function createSharedSourceResolver(shared, getResolutionConfig) {
|
|
9021
9131
|
const caches = /* @__PURE__ */ new Map();
|
|
9022
|
-
|
|
9132
|
+
const wildcardSubpathCaches = /* @__PURE__ */ new Map();
|
|
9133
|
+
async function resolveEntry(context, request, options, { root, conditions }) {
|
|
9134
|
+
if (!path$1.isAbsolute(request) && !isPackageExportAvailable(request, {
|
|
9135
|
+
cwd: root,
|
|
9136
|
+
conditions
|
|
9137
|
+
})) return void 0;
|
|
9138
|
+
const importer = path$1.join(root, "package.json");
|
|
9139
|
+
try {
|
|
9140
|
+
const resolved = await resolveInternally(context, request, importer, options);
|
|
9141
|
+
return resolved && !resolved.external ? resolved.id : void 0;
|
|
9142
|
+
} catch {
|
|
9143
|
+
return;
|
|
9144
|
+
}
|
|
9145
|
+
}
|
|
9146
|
+
async function matchEntry(source, suffix, entryOptions, resolveEntry) {
|
|
9023
9147
|
const packageName = getPackageNameFromNodeModulePath(source);
|
|
9024
9148
|
if (!packageName) return;
|
|
9025
9149
|
const candidates = /* @__PURE__ */ new Set();
|
|
9026
9150
|
if (findSharedKey(packageName, shared)) candidates.add(packageName);
|
|
9027
|
-
|
|
9151
|
+
const packageSubpath = suffix.slice(packageName.length + 1);
|
|
9152
|
+
if (packageSubpath) {
|
|
9153
|
+
for (const specifier of getPackageExportSpecifiersForFile(packageName, packageSubpath, {
|
|
9154
|
+
...entryOptions,
|
|
9155
|
+
fromResolvedEntry: source
|
|
9156
|
+
})) if (findSharedKey(specifier, shared)) candidates.add(specifier);
|
|
9157
|
+
}
|
|
9028
9158
|
for (const key of Object.keys(shared)) {
|
|
9029
9159
|
const request = getSharedRequest(key, shared[key]);
|
|
9030
9160
|
if (getPackageName(request) !== packageName) continue;
|
|
@@ -9044,6 +9174,7 @@ function createSharedSourceResolver(shared, getResolutionConfig) {
|
|
|
9044
9174
|
return {
|
|
9045
9175
|
clear() {
|
|
9046
9176
|
caches.clear();
|
|
9177
|
+
wildcardSubpathCaches.clear();
|
|
9047
9178
|
},
|
|
9048
9179
|
async resolve(context, source, options = {}) {
|
|
9049
9180
|
if (source.startsWith("\0") || source.includes("#")) return;
|
|
@@ -9054,32 +9185,39 @@ function createSharedSourceResolver(shared, getResolutionConfig) {
|
|
|
9054
9185
|
"t",
|
|
9055
9186
|
"import"
|
|
9056
9187
|
].includes(key))) return;
|
|
9057
|
-
if (findSharedKey(source, shared)) return source;
|
|
9058
|
-
const suffix = getNodeModulesSuffix(source);
|
|
9059
|
-
if (!suffix) return;
|
|
9060
|
-
const normalizedSource = stripViteFsPrefix(normalizeNodeModulePath(source));
|
|
9061
9188
|
const environment = context.environment ?? !!options.ssr;
|
|
9062
9189
|
const cacheable = !options.isEntry && !options.scan && (!options.kind || options.kind === "import-statement") && Object.keys(options.attributes ?? {}).length === 0 && Object.keys(options.custom ?? {}).length === 0;
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
cache =
|
|
9066
|
-
|
|
9190
|
+
const getCache = (byEnvironment) => {
|
|
9191
|
+
if (!cacheable) return;
|
|
9192
|
+
let cache = byEnvironment.get(environment);
|
|
9193
|
+
if (!cache) {
|
|
9194
|
+
cache = /* @__PURE__ */ new Map();
|
|
9195
|
+
byEnvironment.set(environment, cache);
|
|
9196
|
+
}
|
|
9197
|
+
return cache;
|
|
9198
|
+
};
|
|
9199
|
+
const directKey = findSharedKey(source, shared);
|
|
9200
|
+
if (directKey) {
|
|
9201
|
+
const request = getSharedRequest(directKey, shared[directKey]);
|
|
9202
|
+
if (!(request.endsWith("/") && source !== removeTrailingSlash(request) && !getCommonSharedSubpaths(request).includes(source))) return source;
|
|
9203
|
+
const cache = getCache(wildcardSubpathCaches);
|
|
9204
|
+
let resolvable = cache?.get(source);
|
|
9205
|
+
if (resolvable === void 0) {
|
|
9206
|
+
resolvable = await resolveEntry(context, source, options, getResolutionConfig(context, options)) !== void 0;
|
|
9207
|
+
cache?.set(source, resolvable);
|
|
9208
|
+
}
|
|
9209
|
+
return resolvable ? source : void 0;
|
|
9067
9210
|
}
|
|
9211
|
+
const suffix = getNodeModulesSuffix(source);
|
|
9212
|
+
if (!suffix) return;
|
|
9213
|
+
const normalizedSource = stripViteFsPrefix(normalizeNodeModulePath(source));
|
|
9214
|
+
const cache = getCache(caches);
|
|
9068
9215
|
if (cache?.has(normalizedSource)) return cache.get(normalizedSource);
|
|
9069
|
-
const
|
|
9070
|
-
const result = await matchEntry(normalizedSource, suffix,
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
})) return void 0;
|
|
9075
|
-
const importer = path$1.join(root, "package.json");
|
|
9076
|
-
try {
|
|
9077
|
-
const resolved = await resolveInternally(context, request, importer, options);
|
|
9078
|
-
return resolved && !resolved.external ? resolved.id : void 0;
|
|
9079
|
-
} catch {
|
|
9080
|
-
return;
|
|
9081
|
-
}
|
|
9082
|
-
});
|
|
9216
|
+
const config = getResolutionConfig(context, options);
|
|
9217
|
+
const result = await matchEntry(normalizedSource, suffix, {
|
|
9218
|
+
cwd: config.root,
|
|
9219
|
+
conditions: config.conditions
|
|
9220
|
+
}, (request) => resolveEntry(context, request, options, config));
|
|
9083
9221
|
cache?.set(normalizedSource, result);
|
|
9084
9222
|
return result;
|
|
9085
9223
|
}
|
|
@@ -9195,8 +9333,7 @@ function pluginModuleParseEnd_default(excludeFn, options, controller = createMod
|
|
|
9195
9333
|
},
|
|
9196
9334
|
async buildStart() {
|
|
9197
9335
|
resetParseState(controller);
|
|
9198
|
-
if (idleTimeout)
|
|
9199
|
-
else if (options.moduleParseTimeout) setParseTimeout(controller, options.moduleParseTimeout);
|
|
9336
|
+
if (!idleTimeout && options.moduleParseTimeout) setParseTimeout(controller, options.moduleParseTimeout);
|
|
9200
9337
|
const entryImports = /* @__PURE__ */ new Set([...options.exposedModuleImports || [], ...configuredInputImports]);
|
|
9201
9338
|
for (const importSource of entryImports) {
|
|
9202
9339
|
const resolved = await this.resolve(importSource);
|
|
@@ -10079,6 +10216,7 @@ function proxySharedModule(options) {
|
|
|
10079
10216
|
},
|
|
10080
10217
|
buildStart() {
|
|
10081
10218
|
sharedSourceResolver.clear();
|
|
10219
|
+
patchRolldownResolveOptionKeys(this);
|
|
10082
10220
|
if (_command !== "build") return;
|
|
10083
10221
|
if (hasAnalyzableShares) getBuildImportAnalysis(this.environment).clear();
|
|
10084
10222
|
resetTreeShakingExports(federationOptions);
|
|
@@ -10479,8 +10617,15 @@ function pluginRemoteNamedExports(options) {
|
|
|
10479
10617
|
if (id.includes("__loadRemote__") || id.includes("__loadShare__")) return;
|
|
10480
10618
|
if (!JS_EXTENSIONS_RE.test(id)) return;
|
|
10481
10619
|
if (!remoteNames.some((name) => code.includes(name))) return;
|
|
10482
|
-
const
|
|
10483
|
-
|
|
10620
|
+
const descriptors = findModuleImportDescriptors(code);
|
|
10621
|
+
const resolvedElsewhere = /* @__PURE__ */ new Set();
|
|
10622
|
+
for (const source of new Set(descriptors.map((d) => d.source))) {
|
|
10623
|
+
if (source.includes("__loadRemote__") || !isRemoteImport(source, id)) continue;
|
|
10624
|
+
const resolved = await this.resolve(source, id);
|
|
10625
|
+
if (resolved && !resolved.id.includes("__loadRemote__")) resolvedElsewhere.add(source);
|
|
10626
|
+
}
|
|
10627
|
+
const matchesRemoteImport = (source) => !resolvedElsewhere.has(source) && isRemoteImport(source, id);
|
|
10628
|
+
for (const { kind, source, typeOnly } of descriptors) if (kind === "static" && !typeOnly && matchesRemoteImport(source)) markStaticRemote(source, options);
|
|
10484
10629
|
let imports;
|
|
10485
10630
|
try {
|
|
10486
10631
|
imports = await collectFromAST(this.parse(code), code, matchesRemoteImport);
|
|
@@ -12132,7 +12277,7 @@ function withoutDynamicRemoteTypeHints(options) {
|
|
|
12132
12277
|
}
|
|
12133
12278
|
function loadPluginDts(options) {
|
|
12134
12279
|
if (options.dts === false) return [];
|
|
12135
|
-
return [import("./pluginDts-
|
|
12280
|
+
return [import("./pluginDts-DShMdjzR.js").then(({ default: pluginDts }) => pluginDts(options))];
|
|
12136
12281
|
}
|
|
12137
12282
|
const INJECT_EXTERNAL_RUNTIME_CORE_PLUGIN = "@module-federation/vite/injectExternalRuntimeCorePlugin";
|
|
12138
12283
|
function isInjectExternalRuntimeCorePlugin(specifier) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as normalizePathForImport, n as mfError, t as createModuleFederationError } from "./logger-DOwfTlw5.js";
|
|
2
|
-
import {
|
|
2
|
+
import { _ as resolveImportPath, d as hasPackageDependency } from "./dtsConstants-BQdFpgKb.js";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import * as path$1 from "node:path";
|
|
5
5
|
import { normalizeOptions } from "@module-federation/sdk";
|
|
@@ -218,4 +218,4 @@ function getSharedKeyMatcher(shared) {
|
|
|
218
218
|
return matcher;
|
|
219
219
|
}
|
|
220
220
|
//#endregion
|
|
221
|
-
export {
|
|
221
|
+
export { removeTrailingSlash as _, matchesSharedSource as a, stripViteFsPrefix as b, filterId as c, getNodeModulesSuffix as d, isAssetLikeImport as f, normalizeNodeModulePath as g, isViteOptimizableEntry as h, invalidateSharedKeyMatcher as i, getBasePath as l, isNuxtClientBase as m, getSharedRequest as n, VITE_FS_PREFIX as o, isNodeModulePath as p, getSharedRuntimeKey as r, ensureTrailingSlash as s, findSharedKey as t, getCommonSharedSubpaths as u, resolvePublicPath as v, stripQueryAndHash as y };
|
|
@@ -146,7 +146,23 @@ async function nodeImport(id) {
|
|
|
146
146
|
const isNodeServer = () => {
|
|
147
147
|
return import.meta.env?.SSR ?? typeof globalThis.process?.versions?.node === "string";
|
|
148
148
|
};
|
|
149
|
-
const
|
|
149
|
+
const SSR_ENTRY_LOADER_STATE_KEY = Symbol.for("module-federation.vite.ssrEntryLoader.state");
|
|
150
|
+
function getLoaderState() {
|
|
151
|
+
const holder = globalThis;
|
|
152
|
+
const state = holder[SSR_ENTRY_LOADER_STATE_KEY] ??= {};
|
|
153
|
+
state.runnerCache ??= /* @__PURE__ */ new Map();
|
|
154
|
+
state.unversionedGenerations ??= /* @__PURE__ */ new Map();
|
|
155
|
+
state.unversionedGlobalGeneration ??= 0;
|
|
156
|
+
state.ssrEntryCache ??= /* @__PURE__ */ new Map();
|
|
157
|
+
state.manifestFetchCache ??= /* @__PURE__ */ new Map();
|
|
158
|
+
state.tempFileCache ??= /* @__PURE__ */ new Map();
|
|
159
|
+
state.tempFilePathCache ??= /* @__PURE__ */ new Map();
|
|
160
|
+
state.tempFileRecords ??= /* @__PURE__ */ new Map();
|
|
161
|
+
state.scheduledTempFileCleanup ??= /* @__PURE__ */ new Set();
|
|
162
|
+
return state;
|
|
163
|
+
}
|
|
164
|
+
const loaderState = getLoaderState();
|
|
165
|
+
const runnerCache = loaderState.runnerCache;
|
|
150
166
|
function getSortedRecordEntries(record) {
|
|
151
167
|
return Object.entries(record).sort(([left], [right]) => left.localeCompare(right));
|
|
152
168
|
}
|
|
@@ -271,10 +287,9 @@ function parseRunnerInvokeResult(data) {
|
|
|
271
287
|
* advance a process-local generation so the next import is fresh.
|
|
272
288
|
*/
|
|
273
289
|
const UNVERSIONED = "unversioned";
|
|
274
|
-
const unversionedGenerations =
|
|
275
|
-
let unversionedGlobalGeneration = 0;
|
|
290
|
+
const unversionedGenerations = loaderState.unversionedGenerations;
|
|
276
291
|
function getUnversionedVersionKey(remoteEntryUrl) {
|
|
277
|
-
return `${UNVERSIONED}-${unversionedGlobalGeneration}-${unversionedGenerations.get(remoteEntryUrl) ?? 0}`;
|
|
292
|
+
return `${UNVERSIONED}-${loaderState.unversionedGlobalGeneration}-${unversionedGenerations.get(remoteEntryUrl) ?? 0}`;
|
|
278
293
|
}
|
|
279
294
|
function bumpUnversionedGeneration(remoteEntryUrl) {
|
|
280
295
|
unversionedGenerations.set(remoteEntryUrl, (unversionedGenerations.get(remoteEntryUrl) ?? 0) + 1);
|
|
@@ -292,8 +307,8 @@ function computeManifestVersionKey(manifest) {
|
|
|
292
307
|
const contentHash = hashString(JSON.stringify(manifest));
|
|
293
308
|
return buildVersion ? `${buildVersion}-${contentHash}` : contentHash;
|
|
294
309
|
}
|
|
295
|
-
const ssrEntryCache =
|
|
296
|
-
const manifestFetchCache =
|
|
310
|
+
const ssrEntryCache = loaderState.ssrEntryCache;
|
|
311
|
+
const manifestFetchCache = loaderState.manifestFetchCache;
|
|
297
312
|
function makeUrlCacheKey(url, fetchTimeoutMs, fetchMaxBytes) {
|
|
298
313
|
return `${fetchTimeoutMs}::${fetchMaxBytes}::${url}`;
|
|
299
314
|
}
|
|
@@ -514,8 +529,8 @@ function invalidateRemoteCaches(remoteEntryUrl) {
|
|
|
514
529
|
* static import cycle between the two SSR strategies.
|
|
515
530
|
*/
|
|
516
531
|
function scheduleVmCacheCleanup(remoteEntryUrl) {
|
|
517
|
-
if (!vmStrategyModulePromise) return;
|
|
518
|
-
vmStrategyModulePromise.then(({ clearVmStrategyCaches }) => clearVmStrategyCaches(remoteEntryUrl)).catch(() => {});
|
|
532
|
+
if (!loaderState.vmStrategyModulePromise) return;
|
|
533
|
+
loaderState.vmStrategyModulePromise.then(({ clearVmStrategyCaches }) => clearVmStrategyCaches(remoteEntryUrl)).catch(() => {});
|
|
519
534
|
}
|
|
520
535
|
/**
|
|
521
536
|
* A dev-mode ModuleRunner is created per origin (one Vite dev server) and is
|
|
@@ -575,7 +590,7 @@ function revalidate(remoteEntryUrl) {
|
|
|
575
590
|
for (const key of manifestFetchCache.keys()) if (key.endsWith(`::${manifestUrl}`)) manifestFetchCache.delete(key);
|
|
576
591
|
invalidateRemoteCaches(remoteEntryUrl);
|
|
577
592
|
} else {
|
|
578
|
-
unversionedGlobalGeneration += 1;
|
|
593
|
+
loaderState.unversionedGlobalGeneration += 1;
|
|
579
594
|
ssrEntryCache.clear();
|
|
580
595
|
manifestFetchCache.clear();
|
|
581
596
|
invalidateAllRemoteCaches();
|
|
@@ -585,11 +600,11 @@ function revalidate(remoteEntryUrl) {
|
|
|
585
600
|
instance?.moduleCache?.clear?.();
|
|
586
601
|
} catch {}
|
|
587
602
|
}
|
|
588
|
-
const tempFileCache =
|
|
589
|
-
const tempFilePathCache =
|
|
603
|
+
const tempFileCache = loaderState.tempFileCache;
|
|
604
|
+
const tempFilePathCache = loaderState.tempFilePathCache;
|
|
590
605
|
const TEMP_FILE_CLEANUP_DELAY_MS = 3e4;
|
|
591
|
-
const tempFileRecords =
|
|
592
|
-
const scheduledTempFileCleanup =
|
|
606
|
+
const tempFileRecords = loaderState.tempFileRecords;
|
|
607
|
+
const scheduledTempFileCleanup = loaderState.scheduledTempFileCleanup;
|
|
593
608
|
function scheduleTempFileCleanup(records) {
|
|
594
609
|
for (const record of records) {
|
|
595
610
|
if (scheduledTempFileCleanup.has(record.cacheKey)) continue;
|
|
@@ -832,10 +847,9 @@ async function importTempModule(filePath, versionKey) {
|
|
|
832
847
|
);
|
|
833
848
|
}
|
|
834
849
|
let warnedVmUnavailable = false;
|
|
835
|
-
let vmStrategyModulePromise;
|
|
836
850
|
function getVmStrategyModule() {
|
|
837
|
-
if (!vmStrategyModulePromise) vmStrategyModulePromise = import("./ssrVmStrategy-
|
|
838
|
-
return vmStrategyModulePromise;
|
|
851
|
+
if (!loaderState.vmStrategyModulePromise) loaderState.vmStrategyModulePromise = import("./ssrVmStrategy-BkyvcG4s.js");
|
|
852
|
+
return loaderState.vmStrategyModulePromise;
|
|
839
853
|
}
|
|
840
854
|
/**
|
|
841
855
|
* Non-HTTP failures keep falling back (to temp-file after vm, to the federation
|
|
@@ -954,4 +968,4 @@ function ssrEntryLoaderPlugin(options = {}) {
|
|
|
954
968
|
};
|
|
955
969
|
}
|
|
956
970
|
//#endregion
|
|
957
|
-
export {
|
|
971
|
+
export { ssrEntryLoaderPlugin as a, fetchWithTimeout as c, revalidate as i, readResponseTextBounded as l, SsrEntryHttpError as n, DEFAULT_SSR_FETCH_MAX_BYTES as o, neutralizeBrowserPreloadHelpers as r, DEFAULT_SSR_FETCH_TIMEOUT_MS as s, SSR_ENTRY_LOADER_STATE_KEY as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as findSharedKey } from "./sharedKeyMatcher-
|
|
2
|
-
import { c as
|
|
1
|
+
import { t as findSharedKey } from "./sharedKeyMatcher-CHp4QRNq.js";
|
|
2
|
+
import { c as fetchWithTimeout, l as readResponseTextBounded, n as SsrEntryHttpError, r as neutralizeBrowserPreloadHelpers } from "./ssrEntryLoader-CHdWk8Yg.js";
|
|
3
3
|
//#region src/utils/ssrVmStrategy.ts
|
|
4
4
|
/**
|
|
5
5
|
* vm.SourceTextModule strategy for loading remote SSR entries.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { i as SsrEntryLoaderConfig } from "../normalizeModuleFederationOptions-DNUlv-AL.js";
|
|
2
2
|
//#region src/utils/ssrEntryLoader.d.ts
|
|
3
|
+
declare const SSR_ENTRY_LOADER_STATE_KEY: unique symbol;
|
|
3
4
|
interface RemoteInfo {
|
|
4
5
|
name: string;
|
|
5
6
|
entry: string;
|
|
@@ -64,4 +65,4 @@ declare function ssrEntryLoaderPlugin(options?: SsrEntryLoaderOptions): {
|
|
|
64
65
|
} | undefined>;
|
|
65
66
|
};
|
|
66
67
|
//#endregion
|
|
67
|
-
export { SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
|
|
68
|
+
export { SSR_ENTRY_LOADER_STATE_KEY, SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
|
|
1
|
+
import { a as ssrEntryLoaderPlugin, i as revalidate, n as SsrEntryHttpError, r as neutralizeBrowserPreloadHelpers, t as SSR_ENTRY_LOADER_STATE_KEY } from "../ssrEntryLoader-CHdWk8Yg.js";
|
|
2
|
+
export { SSR_ENTRY_LOADER_STATE_KEY, SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
|