@module-federation/vite 1.22.0 → 1.23.0
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 +20 -1
- package/lib/{dtsConstants-BEGrtvcw.js → dtsConstants-DEMpRfBz.js} +248 -62
- package/lib/index.d.ts +14 -1
- package/lib/index.js +1689 -721
- package/lib/{pluginDts-D7Faa4NJ.js → pluginDts-VSLhAx6d.js} +1 -1
- package/lib/{sharedKeyMatcher-DiUzRVH1.js → sharedKeyMatcher-Od_nYxJA.js} +57 -34
- package/lib/{ssrEntryLoader-CMVCDSsG.js → ssrEntryLoader-BvAkpCyi.js} +1 -1
- package/lib/{ssrVmStrategy-Cx9WlTsx.js → ssrVmStrategy-CDbcwMnf.js} +2 -2
- package/lib/utils/ssrEntryLoader.js +1 -1
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as normalizePathForImport } from "./buildPaths-BoaQTkxt.js";
|
|
2
|
-
import {
|
|
2
|
+
import { T as mfError, g as resolveImportPath, u as hasPackageDependency, w as createModuleFederationError } from "./dtsConstants-DEMpRfBz.js";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import * as path$1 from "node:path";
|
|
5
5
|
import os from "os";
|
|
@@ -82,9 +82,25 @@ function getBasePath(base) {
|
|
|
82
82
|
function isNuxtClientBase(base) {
|
|
83
83
|
return getBasePath(base).endsWith("/_nuxt");
|
|
84
84
|
}
|
|
85
|
+
const VITE_FS_PREFIX = "/@fs/";
|
|
86
|
+
function stripQueryAndHash(id) {
|
|
87
|
+
const queryIndex = id.indexOf("?");
|
|
88
|
+
const hashIndex = id.indexOf("#");
|
|
89
|
+
const endIndex = queryIndex === -1 ? hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
90
|
+
return endIndex === -1 ? id : id.slice(0, endIndex);
|
|
91
|
+
}
|
|
92
|
+
function stripViteFsPrefix(id) {
|
|
93
|
+
if (!id.startsWith("/@fs/")) return id;
|
|
94
|
+
const file = id.slice(5);
|
|
95
|
+
return file.startsWith("/") || /^[a-z]:\//i.test(file) ? file : `/${file}`;
|
|
96
|
+
}
|
|
85
97
|
function normalizeNodeModulePath(source) {
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
return stripQueryAndHash(source).replace(/\\/g, "/");
|
|
99
|
+
}
|
|
100
|
+
function getNodeModulesSuffix(source) {
|
|
101
|
+
const normalized = normalizeNodeModulePath(source);
|
|
102
|
+
const index = normalized.lastIndexOf("/node_modules/");
|
|
103
|
+
return index === -1 ? void 0 : normalized.slice(index + 14);
|
|
88
104
|
}
|
|
89
105
|
function isNodeModulePath(source) {
|
|
90
106
|
return source.includes("/node_modules/") || source.includes("\\node_modules\\");
|
|
@@ -92,31 +108,9 @@ function isNodeModulePath(source) {
|
|
|
92
108
|
function filterId(id) {
|
|
93
109
|
return typeof id === "string" && !id.includes("\0");
|
|
94
110
|
}
|
|
95
|
-
const NODE_MODULE_FILE_EXT_RE = /^\.[cm]?[jt]sx?$/i;
|
|
96
|
-
function matchesNodeModuleCandidate(normalized, candidate) {
|
|
97
|
-
const marker = `/node_modules/${candidate}`;
|
|
98
|
-
let from = 0;
|
|
99
|
-
while (from < normalized.length) {
|
|
100
|
-
const index = normalized.indexOf(marker, from);
|
|
101
|
-
if (index === -1) return false;
|
|
102
|
-
const after = normalized.slice(index + marker.length);
|
|
103
|
-
const boundary = after.search(/[?#]/);
|
|
104
|
-
const afterPath = boundary === -1 ? after : after.slice(0, boundary);
|
|
105
|
-
if (afterPath === "" || afterPath.startsWith("/") || NODE_MODULE_FILE_EXT_RE.test(afterPath)) return true;
|
|
106
|
-
from = index + 1;
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
function getMatchingNodeModuleSubpath(source, candidates) {
|
|
111
|
-
const normalized = normalizeNodeModulePath(source);
|
|
112
|
-
return [...candidates].sort((a, b) => b.length - a.length).find((candidate) => matchesNodeModuleCandidate(normalized, candidate));
|
|
113
|
-
}
|
|
114
111
|
function getCommonSharedSubpaths(sharedKey) {
|
|
115
112
|
return COMMON_SHARED_SUBPATHS[removeTrailingSlash(sharedKey)] || [];
|
|
116
113
|
}
|
|
117
|
-
function getCommonSharedSubpathFromNodeModulePath(source, sharedKey) {
|
|
118
|
-
return getMatchingNodeModuleSubpath(source, getCommonSharedSubpaths(removeTrailingSlash(sharedKey)));
|
|
119
|
-
}
|
|
120
114
|
/**
|
|
121
115
|
* Resolves the public path for remote entries
|
|
122
116
|
* @param options - Module Federation options
|
|
@@ -135,11 +129,38 @@ function resolvePublicPath(options, viteBase, originalBase) {
|
|
|
135
129
|
}
|
|
136
130
|
//#endregion
|
|
137
131
|
//#region src/utils/sharedKeyMatcher.ts
|
|
138
|
-
function
|
|
139
|
-
const
|
|
132
|
+
function getSharedRequest(key, shareItem) {
|
|
133
|
+
const request = shareItem?.shareConfig?.request;
|
|
134
|
+
return typeof request === "string" ? request : key;
|
|
135
|
+
}
|
|
136
|
+
/** `prefix` ends with `/` and `source` is its base or a subpath under it. */
|
|
137
|
+
function isUnderPrefix(prefix, source) {
|
|
138
|
+
return prefix.endsWith("/") && (source === prefix.slice(0, -1) || source.startsWith(prefix));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Resolve the runtime share-scope key for a concrete request. The configured
|
|
142
|
+
* property name is the default runtime key; `shareKey` only changes it when
|
|
143
|
+
* explicitly provided. Prefix requests carry their concrete suffix to the
|
|
144
|
+
* runtime key as required by the Module Federation shared contract.
|
|
145
|
+
*/
|
|
146
|
+
function getSharedRuntimeKey(source, shareItem) {
|
|
147
|
+
const name = typeof shareItem?.name === "string" ? shareItem.name : void 0;
|
|
148
|
+
const request = getSharedRequest(name ?? source, shareItem);
|
|
149
|
+
const configuredShareKey = shareItem?.shareConfig?.shareKey;
|
|
150
|
+
const sourceMatchesRequest = source === request || isUnderPrefix(request, source);
|
|
151
|
+
const shareKey = typeof configuredShareKey === "string" ? configuredShareKey : name !== void 0 && sourceMatchesRequest ? name : source;
|
|
152
|
+
if (!request.endsWith("/")) return shareKey;
|
|
153
|
+
const requestBase = request.slice(0, -1);
|
|
154
|
+
if (source === requestBase) return shareKey.endsWith("/") ? shareKey.slice(0, -1) : shareKey;
|
|
155
|
+
if (source.startsWith(`${requestBase}/`)) return shareKey + source.slice(request.length);
|
|
156
|
+
return isUnderPrefix(shareKey, source) ? source : shareKey;
|
|
157
|
+
}
|
|
158
|
+
function matchesSharedSource(source, key, shareItem) {
|
|
159
|
+
const request = getSharedRequest(key, shareItem);
|
|
160
|
+
const keyBase = request.endsWith("/") ? request.slice(0, -1) : request;
|
|
140
161
|
if (keyBase === "vue" && (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js")) return true;
|
|
141
|
-
if (
|
|
142
|
-
if (getCommonSharedSubpaths(keyBase).includes(source)) return true;
|
|
162
|
+
if (request.endsWith("/")) return source === keyBase || source.startsWith(`${keyBase}/`);
|
|
163
|
+
if (shareItem?.shareConfig?.request === void 0 && shareItem?.shareConfig?.shareKey === void 0 && getCommonSharedSubpaths(keyBase).includes(source)) return true;
|
|
143
164
|
return source === keyBase;
|
|
144
165
|
}
|
|
145
166
|
const emptySharedKeyMatcher = { find: () => void 0 };
|
|
@@ -163,26 +184,28 @@ function getSharedKeyMatcher(shared) {
|
|
|
163
184
|
const cached = sharedKeyMatcherCache.get(shared);
|
|
164
185
|
if (cached) return cached;
|
|
165
186
|
const keys = Object.keys(shared);
|
|
166
|
-
const exactKeys = new
|
|
187
|
+
const exactKeys = /* @__PURE__ */ new Map();
|
|
167
188
|
const commonSubpathKeys = /* @__PURE__ */ new Map();
|
|
168
189
|
const wildcardKeys = [];
|
|
169
190
|
let vueKey;
|
|
170
191
|
for (const key of keys) {
|
|
171
|
-
const keyBase = key.endsWith("/") ? key.slice(0, -1) : key;
|
|
172
192
|
const shareItem = shared[key];
|
|
193
|
+
const request = getSharedRequest(key, shareItem);
|
|
194
|
+
const keyBase = request.endsWith("/") ? request.slice(0, -1) : request;
|
|
195
|
+
if (!exactKeys.has(request) || request === key) exactKeys.set(request, key);
|
|
173
196
|
if (!vueKey && keyBase === "vue") vueKey = key;
|
|
174
|
-
if (
|
|
197
|
+
if (request.endsWith("/")) wildcardKeys.push({
|
|
175
198
|
key,
|
|
176
199
|
base: keyBase
|
|
177
200
|
});
|
|
178
|
-
if (shareItem?.shareConfig?.import !== false) {
|
|
201
|
+
if (shareItem?.shareConfig?.import !== false && shareItem?.shareConfig?.request === void 0 && shareItem?.shareConfig?.shareKey === void 0) {
|
|
179
202
|
for (const subpath of getCommonSharedSubpaths(keyBase)) if (!commonSubpathKeys.has(subpath)) commonSubpathKeys.set(subpath, key);
|
|
180
203
|
}
|
|
181
204
|
}
|
|
182
205
|
const sourceCache = /* @__PURE__ */ new Map();
|
|
183
206
|
const matcher = { find(source) {
|
|
184
207
|
if (sourceCache.has(source)) return sourceCache.get(source);
|
|
185
|
-
let result = exactKeys.
|
|
208
|
+
let result = exactKeys.get(source);
|
|
186
209
|
if (!result && vueKey) {
|
|
187
210
|
if (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js") result = vueKey;
|
|
188
211
|
}
|
|
@@ -195,4 +218,4 @@ function getSharedKeyMatcher(shared) {
|
|
|
195
218
|
return matcher;
|
|
196
219
|
}
|
|
197
220
|
//#endregion
|
|
198
|
-
export {
|
|
221
|
+
export { resolvePublicPath as _, matchesSharedSource as a, 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, stripQueryAndHash as v, stripViteFsPrefix as y };
|
|
@@ -666,7 +666,7 @@ async function importTempModule(filePath, versionKey) {
|
|
|
666
666
|
}
|
|
667
667
|
let warnedVmUnavailable = false;
|
|
668
668
|
async function tryVmStrategy(ssrEntry, options) {
|
|
669
|
-
const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-
|
|
669
|
+
const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-CDbcwMnf.js");
|
|
670
670
|
if (!await isVmStrategyAvailable()) {
|
|
671
671
|
if (!warnedVmUnavailable) {
|
|
672
672
|
warnedVmUnavailable = true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as findSharedKey } from "./sharedKeyMatcher-
|
|
2
|
-
import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-
|
|
1
|
+
import { t as findSharedKey } from "./sharedKeyMatcher-Od_nYxJA.js";
|
|
2
|
+
import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-BvAkpCyi.js";
|
|
3
3
|
//#region src/utils/ssrVmStrategy.ts
|
|
4
4
|
/**
|
|
5
5
|
* vm.SourceTextModule strategy for loading remote SSR entries.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-
|
|
1
|
+
import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-BvAkpCyi.js";
|
|
2
2
|
export { SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/vite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Vite plugin for Module Federation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -77,9 +77,9 @@
|
|
|
77
77
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@module-federation/dts-plugin": "2.9.
|
|
81
|
-
"@module-federation/runtime": "2.9.
|
|
82
|
-
"@module-federation/sdk": "2.9.
|
|
80
|
+
"@module-federation/dts-plugin": "2.9.1",
|
|
81
|
+
"@module-federation/runtime": "2.9.1",
|
|
82
|
+
"@module-federation/sdk": "2.9.1"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@playwright/test": "1.62.0",
|