@module-federation/vite 1.22.1 → 1.23.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/README.md +19 -0
- package/lib/{dtsConstants-dDsHZFC1.js → dtsConstants-Bs4FukGL.js} +231 -89
- package/lib/index.d.ts +14 -1
- package/lib/index.js +1145 -664
- package/lib/logger--uKHOVjR.js +366 -0
- package/lib/{pluginDts-CQ088qGF.js → pluginDts-DxgS2FEd.js} +2 -2
- package/lib/{sharedKeyMatcher-BRzBCbuR.js → sharedKeyMatcher-Od_nYxJA.js} +39 -10
- package/lib/{ssrEntryLoader-BUXUQi0P.js → ssrEntryLoader-DmqLXUmm.js} +206 -49
- package/lib/{ssrVmStrategy-Ud06y3Xf.js → ssrVmStrategy-B_e3yqa2.js} +75 -6
- package/lib/utils/ssrEntryLoader.js +1 -1
- package/package.json +4 -4
- package/lib/buildPaths-BoaQTkxt.js +0 -66
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
//#region src/utils/buildPaths.ts
|
|
2
|
+
/**
|
|
3
|
+
* Rebase an import path for a bootstrap file that moved from root into `dir`.
|
|
4
|
+
*
|
|
5
|
+
* When entryFileNames places entries in a subdirectory (e.g. `static/js/`),
|
|
6
|
+
* the bootstrap file moves there too. Paths that resolved from the HTML root
|
|
7
|
+
* must resolve from the new directory instead.
|
|
8
|
+
*
|
|
9
|
+
* Cases: `/static/js/hostInit.js` → `./hostInit.js` (strip dir prefix)
|
|
10
|
+
* `./src/main.tsx` → `../../src/main.tsx` (climb back up for each dir level)
|
|
11
|
+
* `https://cdn.example.com` → unchanged (absolute URL)
|
|
12
|
+
*/
|
|
13
|
+
function rebaseImport(importSrc, dir) {
|
|
14
|
+
if (!dir) return importSrc;
|
|
15
|
+
if (isAbsoluteUrl(importSrc)) return importSrc;
|
|
16
|
+
const normalizedDir = dir.replace(/^\/+|\/+$/g, "");
|
|
17
|
+
if (!normalizedDir) return importSrc;
|
|
18
|
+
const stripDirPrefix = (src, prefix) => {
|
|
19
|
+
if (src === prefix) return "";
|
|
20
|
+
if (src.startsWith(prefix + "/")) return src.slice(prefix.length);
|
|
21
|
+
};
|
|
22
|
+
const absoluteRemainder = stripDirPrefix(importSrc, "/" + normalizedDir);
|
|
23
|
+
if (absoluteRemainder !== void 0) {
|
|
24
|
+
const remainder = absoluteRemainder.replace(/^\/+/, "");
|
|
25
|
+
return remainder ? "./" + remainder : "./";
|
|
26
|
+
}
|
|
27
|
+
const relativeRemainder = stripDirPrefix(importSrc, normalizedDir);
|
|
28
|
+
if (relativeRemainder !== void 0) {
|
|
29
|
+
const remainder = relativeRemainder.replace(/^\/+/, "");
|
|
30
|
+
return remainder ? "./" + remainder : "./";
|
|
31
|
+
}
|
|
32
|
+
const upLevels = normalizedDir.split("/").filter(Boolean).length;
|
|
33
|
+
const prefix = upLevels > 0 ? "../".repeat(upLevels) : "./";
|
|
34
|
+
if (importSrc.startsWith("./")) return prefix + importSrc.slice(2);
|
|
35
|
+
if (importSrc.startsWith("/")) return prefix + importSrc.slice(1);
|
|
36
|
+
return prefix + importSrc;
|
|
37
|
+
}
|
|
38
|
+
function normalizePathForImport(path) {
|
|
39
|
+
return path.replace(/\\/g, "/");
|
|
40
|
+
}
|
|
41
|
+
const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i;
|
|
42
|
+
function isAbsoluteUrl(src) {
|
|
43
|
+
if (/^[a-z]:[\\/]/i.test(src)) return false;
|
|
44
|
+
return EXTERNAL_URL_RE.test(src);
|
|
45
|
+
}
|
|
46
|
+
const HASH_PLACEHOLDER_RE = /(?:[._-]?\[hash(?::\d+)?\])/g;
|
|
47
|
+
function hasFileExtension(fileName) {
|
|
48
|
+
return fileName.slice(Math.max(fileName.lastIndexOf("/"), fileName.lastIndexOf("\\")) + 1).lastIndexOf(".") > 0;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolve a bundler `filename` template that still contains `[hash]` placeholders
|
|
52
|
+
* into the concrete, stable file name Module Federation serves.
|
|
53
|
+
*
|
|
54
|
+
* The federation entries are emitted by us rather than hashed by the bundler, so
|
|
55
|
+
* the placeholder is dropped instead of being substituted. When stripping it also
|
|
56
|
+
* removes the extension (`mf-[hash:8]` → `mf`), `.js` is appended so the result
|
|
57
|
+
* stays a loadable module. The extension check deliberately looks at the basename
|
|
58
|
+
* only — a dotted directory (`assets/v1.2/entry`) must not be mistaken for one.
|
|
59
|
+
*/
|
|
60
|
+
function resolveHashPlaceholderFileName(fileName) {
|
|
61
|
+
if (!fileName.includes("[hash")) return fileName;
|
|
62
|
+
const normalized = fileName.replace(HASH_PLACEHOLDER_RE, "");
|
|
63
|
+
return hasFileExtension(normalized) ? normalized : `${normalized}.js`;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/utils/codeRewriter.ts
|
|
67
|
+
const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
68
|
+
var CodeRewriter = class {
|
|
69
|
+
original;
|
|
70
|
+
replacements = [];
|
|
71
|
+
constructor(original) {
|
|
72
|
+
this.original = original;
|
|
73
|
+
}
|
|
74
|
+
overwrite(start, end, content) {
|
|
75
|
+
if (start < 0 || end < start || end > this.original.length) throw new Error(`Invalid overwrite range: ${start}-${end}`);
|
|
76
|
+
this.replacements.push({
|
|
77
|
+
start,
|
|
78
|
+
end,
|
|
79
|
+
content
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
toString() {
|
|
83
|
+
return applyReplacements(this.original, this.getSortedReplacements()).code;
|
|
84
|
+
}
|
|
85
|
+
generateMap(source = "") {
|
|
86
|
+
const { code, replacements } = applyReplacements(this.original, this.getSortedReplacements());
|
|
87
|
+
return {
|
|
88
|
+
version: 3,
|
|
89
|
+
sources: [source],
|
|
90
|
+
sourcesContent: [this.original],
|
|
91
|
+
names: [],
|
|
92
|
+
mappings: generateLineMappings(code, this.original, replacements)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
getSortedReplacements() {
|
|
96
|
+
return [...this.replacements].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function createSourceMap(code, source = "") {
|
|
100
|
+
return {
|
|
101
|
+
version: 3,
|
|
102
|
+
sources: [source],
|
|
103
|
+
sourcesContent: [code],
|
|
104
|
+
names: [],
|
|
105
|
+
mappings: generateLineMappings(code, code, [])
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function applyReplacements(original, replacements) {
|
|
109
|
+
let code = "";
|
|
110
|
+
let cursor = 0;
|
|
111
|
+
let delta = 0;
|
|
112
|
+
const applied = [];
|
|
113
|
+
for (const replacement of replacements) {
|
|
114
|
+
if (replacement.start < cursor) throw new Error("Overlapping overwrite ranges are not supported");
|
|
115
|
+
code += original.slice(cursor, replacement.start);
|
|
116
|
+
const generatedStart = replacement.start + delta;
|
|
117
|
+
code += replacement.content;
|
|
118
|
+
const generatedEnd = generatedStart + replacement.content.length;
|
|
119
|
+
applied.push({
|
|
120
|
+
...replacement,
|
|
121
|
+
generatedStart,
|
|
122
|
+
generatedEnd
|
|
123
|
+
});
|
|
124
|
+
cursor = replacement.end;
|
|
125
|
+
delta += replacement.content.length - (replacement.end - replacement.start);
|
|
126
|
+
}
|
|
127
|
+
code += original.slice(cursor);
|
|
128
|
+
return {
|
|
129
|
+
code,
|
|
130
|
+
replacements: applied
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function generateLineMappings(generated, original, replacements) {
|
|
134
|
+
const generatedLineStarts = getLineStarts(generated);
|
|
135
|
+
const originalLineStarts = getLineStarts(original);
|
|
136
|
+
let previousOriginalLine = 0;
|
|
137
|
+
let previousOriginalColumn = 0;
|
|
138
|
+
let mappings = "";
|
|
139
|
+
generatedLineStarts.forEach((generatedOffset, lineIndex) => {
|
|
140
|
+
if (lineIndex > 0) mappings += ";";
|
|
141
|
+
const originalOffset = generatedOffsetToOriginalOffset(generatedOffset, replacements);
|
|
142
|
+
const originalLine = findLine(originalLineStarts, originalOffset);
|
|
143
|
+
const originalColumn = originalOffset - originalLineStarts[originalLine];
|
|
144
|
+
mappings += encodeSegment([
|
|
145
|
+
0,
|
|
146
|
+
0,
|
|
147
|
+
originalLine - previousOriginalLine,
|
|
148
|
+
originalColumn - previousOriginalColumn
|
|
149
|
+
]);
|
|
150
|
+
previousOriginalLine = originalLine;
|
|
151
|
+
previousOriginalColumn = originalColumn;
|
|
152
|
+
});
|
|
153
|
+
return mappings;
|
|
154
|
+
}
|
|
155
|
+
function generatedOffsetToOriginalOffset(offset, replacements) {
|
|
156
|
+
let delta = 0;
|
|
157
|
+
for (const replacement of replacements) {
|
|
158
|
+
if (offset < replacement.generatedStart) break;
|
|
159
|
+
if (offset < replacement.generatedEnd) return replacement.start;
|
|
160
|
+
delta += replacement.content.length - (replacement.end - replacement.start);
|
|
161
|
+
}
|
|
162
|
+
return offset - delta;
|
|
163
|
+
}
|
|
164
|
+
function getLineStarts(code) {
|
|
165
|
+
const starts = [0];
|
|
166
|
+
for (let i = 0; i < code.length; i++) if (code.charCodeAt(i) === 10) starts.push(i + 1);
|
|
167
|
+
return starts;
|
|
168
|
+
}
|
|
169
|
+
function findLine(lineStarts, offset) {
|
|
170
|
+
let low = 0;
|
|
171
|
+
let high = lineStarts.length - 1;
|
|
172
|
+
while (low <= high) {
|
|
173
|
+
const mid = low + high >> 1;
|
|
174
|
+
if (lineStarts[mid] <= offset) low = mid + 1;
|
|
175
|
+
else high = mid - 1;
|
|
176
|
+
}
|
|
177
|
+
return Math.max(0, high);
|
|
178
|
+
}
|
|
179
|
+
function encodeSegment(values) {
|
|
180
|
+
return values.map(encodeVlq).join("");
|
|
181
|
+
}
|
|
182
|
+
function encodeVlq(value) {
|
|
183
|
+
let vlq = value < 0 ? (-value << 1) + 1 : value << 1;
|
|
184
|
+
let encoded = "";
|
|
185
|
+
do {
|
|
186
|
+
let digit = vlq & 31;
|
|
187
|
+
vlq >>>= 5;
|
|
188
|
+
if (vlq > 0) digit |= 32;
|
|
189
|
+
encoded += BASE64_CHARS[digit];
|
|
190
|
+
} while (vlq > 0);
|
|
191
|
+
return encoded;
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/utils/codePositionMap.ts
|
|
195
|
+
const REGEX_PREFIX_KEYWORDS = /* @__PURE__ */ new Set([
|
|
196
|
+
"await",
|
|
197
|
+
"case",
|
|
198
|
+
"delete",
|
|
199
|
+
"in",
|
|
200
|
+
"instanceof",
|
|
201
|
+
"new",
|
|
202
|
+
"return",
|
|
203
|
+
"throw",
|
|
204
|
+
"typeof",
|
|
205
|
+
"void",
|
|
206
|
+
"yield"
|
|
207
|
+
]);
|
|
208
|
+
function isJsxClosingTagSlash(code, slashIndex) {
|
|
209
|
+
if (code[slashIndex - 1] !== "<") return false;
|
|
210
|
+
let cursor = slashIndex + 1;
|
|
211
|
+
while (/\s/.test(code[cursor] || "")) cursor++;
|
|
212
|
+
if (code[cursor] === ">") return true;
|
|
213
|
+
const tagStart = cursor;
|
|
214
|
+
while (/[-:.$_\u200C\u200D\p{ID_Continue}]/u.test(code[cursor] || "")) cursor++;
|
|
215
|
+
if (cursor === tagStart) return false;
|
|
216
|
+
while (/\s/.test(code[cursor] || "")) cursor++;
|
|
217
|
+
return code[cursor] === ">";
|
|
218
|
+
}
|
|
219
|
+
/** Mark comments, string/template literals, and regular expressions as non-code. */
|
|
220
|
+
function createCodePositionMap(code, onComment) {
|
|
221
|
+
const positions = Array(code.length).fill(true);
|
|
222
|
+
const mask = (start, end) => {
|
|
223
|
+
for (let index = start; index < end; index++) positions[index] = false;
|
|
224
|
+
};
|
|
225
|
+
let canStartRegex = true;
|
|
226
|
+
for (let index = 0; index < code.length;) {
|
|
227
|
+
const char = code[index];
|
|
228
|
+
const next = code[index + 1];
|
|
229
|
+
if (/\s/.test(char)) {
|
|
230
|
+
index++;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (char === "/" && next === "/") {
|
|
234
|
+
const start = index;
|
|
235
|
+
index += 2;
|
|
236
|
+
while (index < code.length && code[index] !== "\n" && code[index] !== "\r") index++;
|
|
237
|
+
mask(start, index);
|
|
238
|
+
onComment?.(start, index);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (char === "/" && next === "*") {
|
|
242
|
+
const start = index;
|
|
243
|
+
index += 2;
|
|
244
|
+
while (index < code.length && !(code[index] === "*" && code[index + 1] === "/")) index++;
|
|
245
|
+
index = Math.min(code.length, index + 2);
|
|
246
|
+
mask(start, index);
|
|
247
|
+
onComment?.(start, index);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (char === "\"" || char === "'" || char === "`") {
|
|
251
|
+
const quote = char;
|
|
252
|
+
const start = index++;
|
|
253
|
+
while (index < code.length) {
|
|
254
|
+
if (code[index] === "\\") {
|
|
255
|
+
index += 2;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (code[index] === quote) {
|
|
259
|
+
index++;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
index++;
|
|
263
|
+
}
|
|
264
|
+
mask(start, index);
|
|
265
|
+
canStartRegex = false;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const closesJsxTag = isJsxClosingTagSlash(code, index);
|
|
269
|
+
if (char === "/" && canStartRegex && !closesJsxTag) {
|
|
270
|
+
const start = index;
|
|
271
|
+
let cursor = index + 1;
|
|
272
|
+
let escaped = false;
|
|
273
|
+
let inCharacterClass = false;
|
|
274
|
+
let closed = false;
|
|
275
|
+
for (; cursor < code.length; cursor++) {
|
|
276
|
+
const regexChar = code[cursor];
|
|
277
|
+
if (regexChar === "\n" || regexChar === "\r") break;
|
|
278
|
+
if (escaped) {
|
|
279
|
+
escaped = false;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (regexChar === "\\") {
|
|
283
|
+
escaped = true;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (regexChar === "[") {
|
|
287
|
+
inCharacterClass = true;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (regexChar === "]" && inCharacterClass) {
|
|
291
|
+
inCharacterClass = false;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (regexChar === "/" && !inCharacterClass) {
|
|
295
|
+
cursor++;
|
|
296
|
+
while (/[$_\p{ID_Continue}]/u.test(code[cursor] || "")) cursor++;
|
|
297
|
+
closed = true;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (closed) {
|
|
302
|
+
mask(start, cursor);
|
|
303
|
+
index = cursor;
|
|
304
|
+
canStartRegex = false;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (/[$_\p{ID_Start}]/u.test(char)) {
|
|
309
|
+
const start = index++;
|
|
310
|
+
while (/[$_\u200C\u200D\p{ID_Continue}]/u.test(code[index] || "")) index++;
|
|
311
|
+
canStartRegex = REGEX_PREFIX_KEYWORDS.has(code.slice(start, index));
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (/\d/.test(char)) {
|
|
315
|
+
index++;
|
|
316
|
+
while (/[\w.]/.test(code[index] || "")) index++;
|
|
317
|
+
canStartRegex = false;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if ((char === "+" || char === "-") && next === char) {
|
|
321
|
+
index += 2;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (char === "!" && next !== "=") {
|
|
325
|
+
index++;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (char === ")" || char === "]" || char === "}") canStartRegex = false;
|
|
329
|
+
else if (char !== ".") canStartRegex = true;
|
|
330
|
+
index++;
|
|
331
|
+
}
|
|
332
|
+
return positions;
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/utils/logger.ts
|
|
336
|
+
const MODULE_FEDERATION_LOG_PREFIX = "[Module Federation]";
|
|
337
|
+
function formatModuleFederationMessage(message) {
|
|
338
|
+
return `${MODULE_FEDERATION_LOG_PREFIX} ${message}`;
|
|
339
|
+
}
|
|
340
|
+
function createModuleFederationError(message) {
|
|
341
|
+
return new Error(formatModuleFederationMessage(message));
|
|
342
|
+
}
|
|
343
|
+
function toConsoleArgs(message, rest = []) {
|
|
344
|
+
if (typeof message === "string") return [formatModuleFederationMessage(message), ...rest];
|
|
345
|
+
if (message === void 0) return [MODULE_FEDERATION_LOG_PREFIX, ...rest];
|
|
346
|
+
return [
|
|
347
|
+
MODULE_FEDERATION_LOG_PREFIX,
|
|
348
|
+
message,
|
|
349
|
+
...rest
|
|
350
|
+
];
|
|
351
|
+
}
|
|
352
|
+
const moduleFederationConsole = {
|
|
353
|
+
log(message, ...rest) {
|
|
354
|
+
console.log(...toConsoleArgs(message, rest));
|
|
355
|
+
},
|
|
356
|
+
warn(message, ...rest) {
|
|
357
|
+
console.warn(...toConsoleArgs(message, rest));
|
|
358
|
+
},
|
|
359
|
+
error(message, ...rest) {
|
|
360
|
+
console.error(...toConsoleArgs(message, rest));
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
const mfWarn = moduleFederationConsole.warn;
|
|
364
|
+
const mfError = moduleFederationConsole.error;
|
|
365
|
+
//#endregion
|
|
366
|
+
export { CodeRewriter as a, normalizePathForImport as c, createCodePositionMap as i, rebaseImport as l, mfError as n, createSourceMap as o, mfWarn as r, EXTERNAL_URL_RE as s, createModuleFederationError as t, resolveHashPlaceholderFileName as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as normalizePathForImport, n as mfError, t as createModuleFederationError } from "./logger--uKHOVjR.js";
|
|
2
|
+
import { g as resolveImportPath, u as hasPackageDependency } from "./dtsConstants-Bs4FukGL.js";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import * as path$1 from "node:path";
|
|
5
5
|
import os from "os";
|
|
@@ -129,11 +129,38 @@ function resolvePublicPath(options, viteBase, originalBase) {
|
|
|
129
129
|
}
|
|
130
130
|
//#endregion
|
|
131
131
|
//#region src/utils/sharedKeyMatcher.ts
|
|
132
|
-
function
|
|
133
|
-
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;
|
|
134
161
|
if (keyBase === "vue" && (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js")) return true;
|
|
135
|
-
if (
|
|
136
|
-
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;
|
|
137
164
|
return source === keyBase;
|
|
138
165
|
}
|
|
139
166
|
const emptySharedKeyMatcher = { find: () => void 0 };
|
|
@@ -157,26 +184,28 @@ function getSharedKeyMatcher(shared) {
|
|
|
157
184
|
const cached = sharedKeyMatcherCache.get(shared);
|
|
158
185
|
if (cached) return cached;
|
|
159
186
|
const keys = Object.keys(shared);
|
|
160
|
-
const exactKeys = new
|
|
187
|
+
const exactKeys = /* @__PURE__ */ new Map();
|
|
161
188
|
const commonSubpathKeys = /* @__PURE__ */ new Map();
|
|
162
189
|
const wildcardKeys = [];
|
|
163
190
|
let vueKey;
|
|
164
191
|
for (const key of keys) {
|
|
165
|
-
const keyBase = key.endsWith("/") ? key.slice(0, -1) : key;
|
|
166
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);
|
|
167
196
|
if (!vueKey && keyBase === "vue") vueKey = key;
|
|
168
|
-
if (
|
|
197
|
+
if (request.endsWith("/")) wildcardKeys.push({
|
|
169
198
|
key,
|
|
170
199
|
base: keyBase
|
|
171
200
|
});
|
|
172
|
-
if (shareItem?.shareConfig?.import !== false) {
|
|
201
|
+
if (shareItem?.shareConfig?.import !== false && shareItem?.shareConfig?.request === void 0 && shareItem?.shareConfig?.shareKey === void 0) {
|
|
173
202
|
for (const subpath of getCommonSharedSubpaths(keyBase)) if (!commonSubpathKeys.has(subpath)) commonSubpathKeys.set(subpath, key);
|
|
174
203
|
}
|
|
175
204
|
}
|
|
176
205
|
const sourceCache = /* @__PURE__ */ new Map();
|
|
177
206
|
const matcher = { find(source) {
|
|
178
207
|
if (sourceCache.has(source)) return sourceCache.get(source);
|
|
179
|
-
let result = exactKeys.
|
|
208
|
+
let result = exactKeys.get(source);
|
|
180
209
|
if (!result && vueKey) {
|
|
181
210
|
if (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js") result = vueKey;
|
|
182
211
|
}
|
|
@@ -189,4 +218,4 @@ function getSharedKeyMatcher(shared) {
|
|
|
189
218
|
return matcher;
|
|
190
219
|
}
|
|
191
220
|
//#endregion
|
|
192
|
-
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 };
|