@module-federation/vite 1.21.0 → 1.21.1
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
|
@@ -707,9 +707,26 @@ function normalizeShareItem(key, shareItem) {
|
|
|
707
707
|
}
|
|
708
708
|
};
|
|
709
709
|
}
|
|
710
|
+
/**
|
|
711
|
+
* Trailing-slash keys are package namespace prefixes (`lodash/`, `@scope/ui/`).
|
|
712
|
+
*
|
|
713
|
+
* Packages in COMMON_SHARED_SUBPATHS historically collapsed `pkg/` → `pkg` so
|
|
714
|
+
* Vite would not resolve the invalid `pkg/` specifier, while still auto-mapping
|
|
715
|
+
* known subpaths when a local provider exists.
|
|
716
|
+
*
|
|
717
|
+
* `react/` is different: consumer-only shares need true namespace coverage for
|
|
718
|
+
* any actually-imported subpath, not a hardcoded export list. Keep `react/` as
|
|
719
|
+
* a prefix; concrete subpaths materialize on import via the generic matcher.
|
|
720
|
+
*
|
|
721
|
+
* `react-dom/` must keep collapsing. A browser-wide `react-dom/` prefix would
|
|
722
|
+
* also capture `react-dom/server*`, which is unsafe without environment-aware
|
|
723
|
+
* filtering. Browser-safe entries such as `react-dom/client` stay explicit via
|
|
724
|
+
* COMMON_SHARED_SUBPATHS (local provider) or an exact shared key.
|
|
725
|
+
*/
|
|
710
726
|
function normalizeSharedKey(key) {
|
|
711
727
|
if (!key.endsWith("/")) return key;
|
|
712
728
|
const baseKey = key.slice(0, -1);
|
|
729
|
+
if (baseKey === "react") return key;
|
|
713
730
|
return getCommonSharedSubpaths(baseKey).length > 0 ? baseKey : key;
|
|
714
731
|
}
|
|
715
732
|
function normalizeShared(shared) {
|
|
@@ -1982,6 +1999,10 @@ function getPackageEsmEntryPath(pkg) {
|
|
|
1982
1999
|
}) || resolvePackageEntryFromProjectRoot(pkg);
|
|
1983
2000
|
}
|
|
1984
2001
|
const packageNamedExportsCache = /* @__PURE__ */ new Map();
|
|
2002
|
+
const sharedExportInspectionCache = /* @__PURE__ */ new Map();
|
|
2003
|
+
function invalidateSharedExportInspectionCache(filePath) {
|
|
2004
|
+
if (!/(?:^|[/\\])node_modules(?:[/\\]|$)/.test(filePath)) sharedExportInspectionCache.clear();
|
|
2005
|
+
}
|
|
1985
2006
|
const DEFAULT_SHARED_EXPORT_CONDITIONS = [
|
|
1986
2007
|
"browser",
|
|
1987
2008
|
"import",
|
|
@@ -2009,17 +2030,22 @@ function hasCommonJsExports(source) {
|
|
|
2009
2030
|
return false;
|
|
2010
2031
|
}
|
|
2011
2032
|
function inspectSharedExportsFromFile(entryPath, exportConditions = DEFAULT_SHARED_EXPORT_CONDITIONS) {
|
|
2033
|
+
if (!entryPath) return void 0;
|
|
2034
|
+
const cacheKey = `${entryPath}\0${exportConditions.join("\0")}`;
|
|
2035
|
+
if (sharedExportInspectionCache.has(cacheKey)) return sharedExportInspectionCache.get(cacheKey);
|
|
2012
2036
|
try {
|
|
2013
|
-
if (!entryPath) return void 0;
|
|
2014
2037
|
const source = readFileSync(entryPath, "utf-8");
|
|
2015
2038
|
const scanState = { complete: true };
|
|
2016
2039
|
const namedExports = getNamedExportsViaRegex(source, entryPath, void 0, scanState, exportConditions);
|
|
2017
2040
|
const commonJs = hasCommonJsExports(source);
|
|
2018
|
-
|
|
2041
|
+
const inspection = {
|
|
2019
2042
|
namedExports: scanState.complete && !commonJs ? namedExports : void 0,
|
|
2020
2043
|
commonJs
|
|
2021
2044
|
};
|
|
2045
|
+
sharedExportInspectionCache.set(cacheKey, inspection);
|
|
2046
|
+
return inspection;
|
|
2022
2047
|
} catch {
|
|
2048
|
+
sharedExportInspectionCache.set(cacheKey, void 0);
|
|
2023
2049
|
return;
|
|
2024
2050
|
}
|
|
2025
2051
|
}
|
|
@@ -3616,7 +3642,9 @@ const externalSharedProviderSelectionHelperCode = `const __mfSelectExternalShare
|
|
|
3616
3642
|
) => {
|
|
3617
3643
|
const isLocalProvider = (provider) => __mfMatchesSharedProvider(provider, localShare);
|
|
3618
3644
|
const candidates = Object.fromEntries(
|
|
3619
|
-
Object.entries(versions || {}).filter(([, provider]) =>
|
|
3645
|
+
Object.entries(versions || {}).filter(([, provider]) =>
|
|
3646
|
+
!isLocalProvider(provider) && provider?.shareConfig?.import !== false
|
|
3647
|
+
)
|
|
3620
3648
|
);
|
|
3621
3649
|
if (localShare?.version && localShare.shareConfig?.import !== false) {
|
|
3622
3650
|
const sameVersionProvider = candidates[localShare.version];
|
|
@@ -4019,6 +4047,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
4019
4047
|
const needsSharedProviderSelectionHelper = Object.keys(options.shared ?? {}).length > 0;
|
|
4020
4048
|
const hasTreeShakingShared = Object.values(options.shared ?? {}).some((share) => !!share?.shareConfig.treeShaking);
|
|
4021
4049
|
const hasMultipleShareScopes = Array.isArray(options.shareScope);
|
|
4050
|
+
const guardHostAutoInit = command === "build" && Object.keys(options.exposes ?? {}).length > 0 && Object.keys(options.remotes ?? {}).length > 0;
|
|
4022
4051
|
const materializedShareBatches = toSafeJsLiteral(getShareBatches(options, false));
|
|
4023
4052
|
const runtimeImports = [
|
|
4024
4053
|
"init as runtimeInit",
|
|
@@ -4925,10 +4954,13 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
|
|
|
4925
4954
|
}
|
|
4926
4955
|
return (exposesMap[moduleName])().then(res => () => res)
|
|
4927
4956
|
}
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4957
|
+
${guardHostAutoInit ? `let __mfInitPromise;
|
|
4958
|
+
function __mfGuardedInit(shared, initScope) {
|
|
4959
|
+
if (shared === undefined && __mfInitPromise) return __mfInitPromise;
|
|
4960
|
+
__mfInitPromise = init(shared, initScope);
|
|
4961
|
+
return __mfInitPromise;
|
|
4931
4962
|
}
|
|
4963
|
+
export { __mfGuardedInit as init, getExposes as get }` : `export { init, getExposes as get }`}
|
|
4932
4964
|
`;
|
|
4933
4965
|
}
|
|
4934
4966
|
/**
|
|
@@ -5563,6 +5595,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
|
|
|
5563
5595
|
let emittedFileName;
|
|
5564
5596
|
let skipTransformIds = /* @__PURE__ */ new Set();
|
|
5565
5597
|
let injectedTransformIds = /* @__PURE__ */ new Set();
|
|
5598
|
+
const ignoredHtmlScriptSources = /* @__PURE__ */ new Set();
|
|
5566
5599
|
let bootstrapDir = "";
|
|
5567
5600
|
function skipSvelteKitSsrBuild() {
|
|
5568
5601
|
return (_command === "build" || viteConfig?.command === "build") && viteConfig?.build?.ssr && hasPackageDependency("@sveltejs/kit");
|
|
@@ -5764,6 +5797,10 @@ for (const __mfRemoteEntryPrefetchUrl of __mfRemoteEntryPrefetchUrls) {
|
|
|
5764
5797
|
const scriptRegex = /<script\b(?=[^>]*\btype=["']module["'])(?=[^>]*\bsrc=["']([^"']+)["'])[^>]*>/gi;
|
|
5765
5798
|
let match;
|
|
5766
5799
|
while ((match = scriptRegex.exec(htmlContent)) !== null) {
|
|
5800
|
+
if (/\svite-ignore(?:\s|=|\/?>)/i.test(match[0])) {
|
|
5801
|
+
ignoredHtmlScriptSources.add(match[1]);
|
|
5802
|
+
continue;
|
|
5803
|
+
}
|
|
5767
5804
|
const scriptSrc = stripQueryAndHash$1(match[1]);
|
|
5768
5805
|
if (/^(?:[a-z]+:)?\/\//i.test(scriptSrc)) continue;
|
|
5769
5806
|
addEntryFile(scriptSrc);
|
|
@@ -5945,6 +5982,7 @@ for (const __mfRemoteEntryPrefetchUrl of __mfRemoteEntryPrefetchUrls) {
|
|
|
5945
5982
|
const scriptRegex = /<script\b(?=[^>]*\btype=["']module["'])(?=[^>]*\bsrc=["']([^"']+)["'])[^>]*>\s*<\/script>/gi;
|
|
5946
5983
|
let rewritten = false;
|
|
5947
5984
|
htmlContent = htmlContent.replace(scriptRegex, (scriptTag, entrySrc) => {
|
|
5985
|
+
if (ignoredHtmlScriptSources.has(entrySrc)) return scriptTag;
|
|
5948
5986
|
rewritten = true;
|
|
5949
5987
|
const strippedInit = stripBase(initPath);
|
|
5950
5988
|
const strippedEntry = stripBase(entrySrc);
|
|
@@ -9774,7 +9812,7 @@ function applyBuildTimeRuntimeDefines(define, options, { target, isAstro, defaul
|
|
|
9774
9812
|
}
|
|
9775
9813
|
function loadPluginDts(options) {
|
|
9776
9814
|
if (options.dts === false) return [];
|
|
9777
|
-
return [import("./pluginDts-
|
|
9815
|
+
return [import("./pluginDts-sJeW2nss.js").then(({ default: pluginDts }) => pluginDts(options))];
|
|
9778
9816
|
}
|
|
9779
9817
|
const INJECT_EXTERNAL_RUNTIME_CORE_PLUGIN = "@module-federation/vite/injectExternalRuntimeCorePlugin";
|
|
9780
9818
|
function isInjectExternalRuntimeCorePlugin(specifier) {
|
|
@@ -9885,6 +9923,11 @@ function federation(mfUserOptions) {
|
|
|
9885
9923
|
{
|
|
9886
9924
|
name: "vite:module-federation-virtual-modules",
|
|
9887
9925
|
enforce: "pre",
|
|
9926
|
+
configureServer(server) {
|
|
9927
|
+
server.watcher.on("change", invalidateSharedExportInspectionCache);
|
|
9928
|
+
server.watcher.on("add", invalidateSharedExportInspectionCache);
|
|
9929
|
+
server.watcher.on("unlink", invalidateSharedExportInspectionCache);
|
|
9930
|
+
},
|
|
9888
9931
|
resolveId(id) {
|
|
9889
9932
|
if (id === "@module-federation/vite/ssrEntryLoader") return resolveImportPath(id);
|
|
9890
9933
|
let virtualModule = VirtualModule.findById(id);
|
|
@@ -10155,6 +10198,10 @@ function federation(mfUserOptions) {
|
|
|
10155
10198
|
}
|
|
10156
10199
|
},
|
|
10157
10200
|
load(id, loadOptions) {
|
|
10201
|
+
if (id.includes("__loadShare__") && id.endsWith("?commonjs-proxy")) {
|
|
10202
|
+
const target = id.slice(id.startsWith("\0") ? 1 : 0, -15);
|
|
10203
|
+
return `export { __moduleExports as default } from ${JSON.stringify(target)};`;
|
|
10204
|
+
}
|
|
10158
10205
|
const loadVirtualModule = (importFalseExportUsage) => {
|
|
10159
10206
|
if (!id.includes("__loadShare__") && !id.includes("__loadRemote__")) return;
|
|
10160
10207
|
if (id.includes("__loadRemote__") && !refreshLoadRemoteModuleForEnvironment(id, this, loadOptions)) return;
|
|
@@ -2,6 +2,7 @@ import { n as normalizePathForImport } from "./buildPaths-BkaQHrd2.js";
|
|
|
2
2
|
import { _ as mfError, g as createModuleFederationError, l as hasPackageDependency, p as resolveImportPath } from "./dtsConstants-DyJrx8ah.js";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import * as path$1 from "node:path";
|
|
5
|
+
import os from "os";
|
|
5
6
|
import { normalizeOptions } from "@module-federation/sdk";
|
|
6
7
|
import { consumeTypesAPI, generateTypesAPI, isTSProject, normalizeConsumeTypesOptions, normalizeDtsOptions, normalizeGenerateTypesOptions } from "@module-federation/dts-plugin";
|
|
7
8
|
import { rpc } from "@module-federation/dts-plugin/core";
|
|
@@ -12,7 +13,26 @@ const DEFAULT_DEV_OPTIONS = {
|
|
|
12
13
|
disableDynamicRemoteTypeHints: false
|
|
13
14
|
};
|
|
14
15
|
const DYNAMIC_HINTS_PLUGIN = "@module-federation/dts-plugin/dynamic-remote-type-hints-plugin";
|
|
15
|
-
const
|
|
16
|
+
const localIpv4 = "127.0.0.1";
|
|
17
|
+
const getIpv4Interfaces = () => {
|
|
18
|
+
try {
|
|
19
|
+
const interfaces = os.networkInterfaces();
|
|
20
|
+
const ipv4Interfaces = [];
|
|
21
|
+
Object.values(interfaces).forEach((detail) => {
|
|
22
|
+
detail?.forEach((detail) => {
|
|
23
|
+
const familyV4Value = typeof detail.family === "string" ? "IPv4" : 4;
|
|
24
|
+
if (detail.family === familyV4Value && detail.address !== localIpv4) ipv4Interfaces.push(detail);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return ipv4Interfaces;
|
|
28
|
+
} catch (_err) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const getIPv4 = () => {
|
|
33
|
+
if (process.env["FEDERATION_IPV4"]) return process.env["FEDERATION_IPV4"];
|
|
34
|
+
return (getIpv4Interfaces()[0] || { address: localIpv4 }).address;
|
|
35
|
+
};
|
|
16
36
|
const DEV_TYPES_FOLDER = ".dev-server";
|
|
17
37
|
const forkDevWorkerPath = (() => {
|
|
18
38
|
return resolveImportPath("@module-federation/dts-plugin/dist/fork-dev-worker.js");
|