@module-federation/vite 1.23.3 → 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 +519 -215
- 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 };
|