@module-federation/vite 1.16.14 → 1.16.15
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/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as createModuleFederationError, a as getIsRolldown, b as rebaseImport, c as getPackageNameFromNodeModulePath, d as isNuxtProjectRoot, f as packageNameDecode, g as sharedCacheHelperCode, h as setPackageDetectionCwd, i as getInstalledPackageJson, l as getSharedCacheDescriptor, m as resolveImportPath, o as getPackageDetectionCwd, p as packageNameEncode, r as getInstalledPackageEntry, s as getPackageName, u as hasPackageDependency, v as mfWarn, y as normalizePathForImport } from "./pluginDts-
|
|
1
|
+
import { _ as createModuleFederationError, a as getIsRolldown, b as rebaseImport, c as getPackageNameFromNodeModulePath, d as isNuxtProjectRoot, f as packageNameDecode, g as sharedCacheHelperCode, h as setPackageDetectionCwd, i as getInstalledPackageJson, l as getSharedCacheDescriptor, m as resolveImportPath, o as getPackageDetectionCwd, p as packageNameEncode, r as getInstalledPackageEntry, s as getPackageName, u as hasPackageDependency, v as mfWarn, y as normalizePathForImport } from "./pluginDts-Bo95ELmX.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import * as fs$2 from "fs";
|
|
4
4
|
import { existsSync, readFileSync, realpathSync, statSync, writeFileSync } from "fs";
|
|
@@ -192,6 +192,51 @@ const COMMON_SHARED_SUBPATHS = {
|
|
|
192
192
|
],
|
|
193
193
|
zustand: ["zustand/vanilla", "zustand/react"]
|
|
194
194
|
};
|
|
195
|
+
const VITE_DEFAULT_ASSET_TYPES = [
|
|
196
|
+
"apng",
|
|
197
|
+
"bmp",
|
|
198
|
+
"png",
|
|
199
|
+
"jpe?g",
|
|
200
|
+
"jfif",
|
|
201
|
+
"pjpeg",
|
|
202
|
+
"pjp",
|
|
203
|
+
"gif",
|
|
204
|
+
"svg",
|
|
205
|
+
"ico",
|
|
206
|
+
"webp",
|
|
207
|
+
"avif",
|
|
208
|
+
"cur",
|
|
209
|
+
"jxl",
|
|
210
|
+
"mp4",
|
|
211
|
+
"webm",
|
|
212
|
+
"ogg",
|
|
213
|
+
"mp3",
|
|
214
|
+
"wav",
|
|
215
|
+
"flac",
|
|
216
|
+
"aac",
|
|
217
|
+
"opus",
|
|
218
|
+
"mov",
|
|
219
|
+
"m4a",
|
|
220
|
+
"vtt",
|
|
221
|
+
"woff2?",
|
|
222
|
+
"eot",
|
|
223
|
+
"ttf",
|
|
224
|
+
"otf",
|
|
225
|
+
"webmanifest",
|
|
226
|
+
"pdf",
|
|
227
|
+
"txt"
|
|
228
|
+
];
|
|
229
|
+
const ASSET_LIKE_IMPORT_RE = new RegExp(`\\.(${[...[
|
|
230
|
+
"css",
|
|
231
|
+
"scss",
|
|
232
|
+
"sass",
|
|
233
|
+
"less",
|
|
234
|
+
"styl",
|
|
235
|
+
"stylus"
|
|
236
|
+
], ...VITE_DEFAULT_ASSET_TYPES].join("|")})(?:[?#].*)?$`, "i");
|
|
237
|
+
function isAssetLikeImport(source) {
|
|
238
|
+
return ASSET_LIKE_IMPORT_RE.test(source);
|
|
239
|
+
}
|
|
195
240
|
function removeTrailingSlash(value) {
|
|
196
241
|
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
197
242
|
}
|
|
@@ -233,7 +278,10 @@ function getCommonSharedSubpathFromNodeModulePath(source, sharedKey) {
|
|
|
233
278
|
function resolvePublicPath(options, viteBase, originalBase) {
|
|
234
279
|
if (options.publicPath && options.publicPath !== "auto") return options.publicPath;
|
|
235
280
|
if (!originalBase) return "auto";
|
|
236
|
-
if (viteBase)
|
|
281
|
+
if (viteBase) {
|
|
282
|
+
if (viteBase === "./") return "auto";
|
|
283
|
+
return ensureTrailingSlash(viteBase);
|
|
284
|
+
}
|
|
237
285
|
return "auto";
|
|
238
286
|
}
|
|
239
287
|
//#endregion
|
|
@@ -1001,6 +1049,25 @@ function resolveRelativeModule(filePath, specifier) {
|
|
|
1001
1049
|
if (existsSync(candidate)) return candidate;
|
|
1002
1050
|
}
|
|
1003
1051
|
}
|
|
1052
|
+
function resolveReExportModule(filePath, specifier) {
|
|
1053
|
+
if (specifier.startsWith(".")) return resolveRelativeModule(filePath, specifier);
|
|
1054
|
+
const esmEntry = getInstalledPackageEntry(specifier, {
|
|
1055
|
+
cwd: path$1.dirname(filePath),
|
|
1056
|
+
conditions: [
|
|
1057
|
+
"browser",
|
|
1058
|
+
"import",
|
|
1059
|
+
"module",
|
|
1060
|
+
"default"
|
|
1061
|
+
],
|
|
1062
|
+
resolveSubpathWithRequire: false
|
|
1063
|
+
});
|
|
1064
|
+
if (esmEntry) return esmEntry;
|
|
1065
|
+
try {
|
|
1066
|
+
return resolveFileLikeModule(createRequire$1(pathToFileURL(filePath)).resolve(specifier));
|
|
1067
|
+
} catch {
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1004
1071
|
function getNamedExportsViaRegex(source, filePath, visited) {
|
|
1005
1072
|
const names = /* @__PURE__ */ new Set();
|
|
1006
1073
|
visited = visited || /* @__PURE__ */ new Set();
|
|
@@ -1044,8 +1111,7 @@ function getNamedExportsViaRegex(source, filePath, visited) {
|
|
|
1044
1111
|
const starExportRegex = /export\s+\*\s+from\s+['"]([^'"]+)['"]/g;
|
|
1045
1112
|
while ((match = starExportRegex.exec(source)) !== null) {
|
|
1046
1113
|
const specifier = match[1];
|
|
1047
|
-
|
|
1048
|
-
const resolvedPath = resolveRelativeModule(filePath, specifier);
|
|
1114
|
+
const resolvedPath = resolveReExportModule(filePath, specifier);
|
|
1049
1115
|
if (!resolvedPath || visited.has(resolvedPath)) continue;
|
|
1050
1116
|
try {
|
|
1051
1117
|
const reExportNames = getNamedExportsViaRegex(readFileSync(resolvedPath, "utf-8"), resolvedPath, visited);
|
|
@@ -1363,13 +1429,18 @@ function generateLazyWorkspaceSingletonExports(namedExports, importSource, cache
|
|
|
1363
1429
|
__mfWriteSharedCache(__mfModuleCache.share, ${cacheDescriptor}, exportModule);
|
|
1364
1430
|
__mfApplyLazyShareExports(exportModule);`}
|
|
1365
1431
|
} else {
|
|
1366
|
-
(__mfModuleCache.pendingShareLoads ||= []).push(initPromise.then(() =>
|
|
1367
|
-
|
|
1432
|
+
(__mfModuleCache.pendingShareLoads ||= []).push(initPromise.then(() => {
|
|
1433
|
+
exportModule = __mfReadSharedCache(__mfModuleCache.share, ${cacheDescriptor});
|
|
1434
|
+
if (exportModule !== undefined) {
|
|
1435
|
+
__mfApplyLazyShareExports(exportModule);
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
return import(${escapeGeneratedStringLiteral(importSource)}).then((mod) => {
|
|
1368
1439
|
exportModule = __mfNormalizeShareModule(mod);
|
|
1369
1440
|
__mfWriteSharedCache(__mfModuleCache.share, ${cacheDescriptor}, exportModule);
|
|
1370
1441
|
__mfApplyLazyShareExports(exportModule);
|
|
1371
|
-
})
|
|
1372
|
-
));
|
|
1442
|
+
});
|
|
1443
|
+
}));
|
|
1373
1444
|
}
|
|
1374
1445
|
} else {
|
|
1375
1446
|
__mfApplyLazyShareExports(exportModule);
|
|
@@ -1381,7 +1452,7 @@ function prependWorkspaceSingletonSsrImport(code) {
|
|
|
1381
1452
|
if (!code.includes("if (import.meta.env.SSR)")) return code;
|
|
1382
1453
|
if (!code.includes(WORKSPACE_SINGLETON_SSR_LOCAL_SHARE)) return code;
|
|
1383
1454
|
if (code.includes("import * as __mfLocalShare")) return code;
|
|
1384
|
-
const importMatch = code.match(/initPromise\.then\(\(\)\s*=>\s*\n\s*import\((["'])(.+?)\1\)\.then\(\(mod\)\s*=>\s*\{[\s\S]*?__mfApplyLazyShareExports/);
|
|
1455
|
+
const importMatch = code.match(/initPromise\.then\(\(\)\s*=>\s*\{[\s\S]*?\breturn import\((["'])(.+?)\1\)\.then\(\(mod\)\s*=>\s*\{[\s\S]*?__mfApplyLazyShareExports/) ?? code.match(/initPromise\.then\(\(\)\s*=>\s*\n\s*import\((["'])(.+?)\1\)\.then\(\(mod\)\s*=>\s*\{[\s\S]*?__mfApplyLazyShareExports/);
|
|
1385
1456
|
if (!importMatch) return code;
|
|
1386
1457
|
const quote = importMatch[1];
|
|
1387
1458
|
return `import * as __mfLocalShare from ${quote}${importMatch[2]}${quote};\n${code}`;
|
|
@@ -1955,6 +2026,9 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
1955
2026
|
async function getExposes(moduleName) {
|
|
1956
2027
|
const exposesMap = await getExposesMap()
|
|
1957
2028
|
if (!(moduleName in exposesMap)) throw new Error(\`[Module Federation] Module \${moduleName} does not exist in container.\`)
|
|
2029
|
+
if (__mfModuleCache.pendingShareLoads) {
|
|
2030
|
+
await Promise.all(__mfModuleCache.pendingShareLoads)
|
|
2031
|
+
}
|
|
1958
2032
|
return (exposesMap[moduleName])().then(res => () => res)
|
|
1959
2033
|
}
|
|
1960
2034
|
export {
|
|
@@ -4576,7 +4650,7 @@ function proxySharedModule(options) {
|
|
|
4576
4650
|
const key = findSharedKeyForSource(source, shared);
|
|
4577
4651
|
if (!key) return;
|
|
4578
4652
|
if (useDirectReactImport && key === "react") return;
|
|
4579
|
-
if (
|
|
4653
|
+
if (isAssetLikeImport(source)) return;
|
|
4580
4654
|
if (isBuildConfigImporter(importer)) return;
|
|
4581
4655
|
if (useDirectReactImport && source === "react") return;
|
|
4582
4656
|
if (importer && importer.includes("localSharedImportMap")) return;
|
|
@@ -5622,7 +5696,7 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
5622
5696
|
if (isSharedResolverInternalImporter(importer)) return;
|
|
5623
5697
|
const key = findSharedKey(source, shared);
|
|
5624
5698
|
if (!key) return;
|
|
5625
|
-
if (source
|
|
5699
|
+
if (isAssetLikeImport(source)) return;
|
|
5626
5700
|
const shareItem = shared[key];
|
|
5627
5701
|
const isReactSingleton = source === "react" && key === "react" && shareItem.shareConfig?.singleton === true;
|
|
5628
5702
|
const isReactRequire = options?.kind?.startsWith("require") && isReactSingleton;
|
|
@@ -5658,7 +5732,7 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
5658
5732
|
if (args.kind === "entry-point") return;
|
|
5659
5733
|
if (!args.importer || args.namespace === "mf-shared") return;
|
|
5660
5734
|
if (isSharedResolverInternalImporter(args.importer)) return;
|
|
5661
|
-
if (!findSharedKey(args.path, shared) || args.path
|
|
5735
|
+
if (!findSharedKey(args.path, shared) || isAssetLikeImport(args.path)) return;
|
|
5662
5736
|
return {
|
|
5663
5737
|
path: args.path,
|
|
5664
5738
|
namespace: "mf-shared"
|
|
@@ -5769,7 +5843,7 @@ export default __mfShared.default ?? __mfShared;`
|
|
|
5769
5843
|
const SSR_ONLY_PLUGINS = new Set(["@module-federation/vite/ssrEntryLoader"]);
|
|
5770
5844
|
function loadPluginDts(options) {
|
|
5771
5845
|
if (options.dts === false) return [];
|
|
5772
|
-
return [import("./pluginDts-
|
|
5846
|
+
return [import("./pluginDts-Bo95ELmX.js").then((n) => n.n).then(({ default: pluginDts }) => pluginDts(options))];
|
|
5773
5847
|
}
|
|
5774
5848
|
function federation(mfUserOptions) {
|
|
5775
5849
|
if (isTestEnv()) return [];
|
|
@@ -141,12 +141,47 @@ function resolveExportsEntry(exportsField, conditions = DEFAULT_EXPORT_CONDITION
|
|
|
141
141
|
if (resolved) return resolved;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
function substituteExportsWildcard(target, patternMatch) {
|
|
145
|
+
if (typeof target === "string") return target.split("*").join(patternMatch);
|
|
146
|
+
if (Array.isArray(target)) return target.map((entry) => substituteExportsWildcard(entry, patternMatch));
|
|
147
|
+
if (target && typeof target === "object") {
|
|
148
|
+
const source = target;
|
|
149
|
+
const out = {};
|
|
150
|
+
for (const key of Object.keys(source)) out[key] = substituteExportsWildcard(source[key], patternMatch);
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
return target;
|
|
154
|
+
}
|
|
155
|
+
function matchExportsSubpath(record, subpath) {
|
|
156
|
+
if (subpath in record) return record[subpath];
|
|
157
|
+
let bestKey;
|
|
158
|
+
let bestBaseLength = -1;
|
|
159
|
+
let bestKeyLength = -1;
|
|
160
|
+
for (const key of Object.keys(record)) {
|
|
161
|
+
const wildcardIndex = key.indexOf("*");
|
|
162
|
+
if (wildcardIndex === -1) continue;
|
|
163
|
+
const patternBase = key.slice(0, wildcardIndex);
|
|
164
|
+
const patternTrailer = key.slice(wildcardIndex + 1);
|
|
165
|
+
if (patternTrailer.includes("*")) continue;
|
|
166
|
+
if (!subpath.startsWith(patternBase) || !subpath.endsWith(patternTrailer)) continue;
|
|
167
|
+
if (subpath.length <= patternBase.length + patternTrailer.length) continue;
|
|
168
|
+
if (patternBase.length > bestBaseLength || patternBase.length === bestBaseLength && key.length > bestKeyLength) {
|
|
169
|
+
bestKey = key;
|
|
170
|
+
bestBaseLength = patternBase.length;
|
|
171
|
+
bestKeyLength = key.length;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (bestKey === void 0) return void 0;
|
|
175
|
+
const patternTrailer = bestKey.slice(bestKey.indexOf("*") + 1);
|
|
176
|
+
const patternMatch = subpath.slice(bestBaseLength, subpath.length - patternTrailer.length);
|
|
177
|
+
return substituteExportsWildcard(record[bestKey], patternMatch);
|
|
178
|
+
}
|
|
144
179
|
function getPackageExportsTarget(pkg, packageName, exportsField) {
|
|
145
180
|
if (typeof exportsField === "string") return pkg === packageName ? exportsField : void 0;
|
|
146
181
|
if (!exportsField || typeof exportsField !== "object") return void 0;
|
|
147
182
|
const record = exportsField;
|
|
148
183
|
const subpath = pkg === packageName ? "." : `.${pkg.slice(packageName.length)}`;
|
|
149
|
-
if (subpath !== ".") return record
|
|
184
|
+
if (subpath !== ".") return matchExportsSubpath(record, subpath);
|
|
150
185
|
return record["."] ?? (!Object.keys(record).some((key) => key.startsWith(".")) ? record : void 0);
|
|
151
186
|
}
|
|
152
187
|
/**
|