@module-federation/vite 1.23.0 → 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/lib/{dtsConstants-DEMpRfBz.js → dtsConstants-Bs4FukGL.js} +2 -32
- package/lib/index.js +66 -295
- package/lib/logger--uKHOVjR.js +366 -0
- package/lib/{pluginDts-VSLhAx6d.js → pluginDts-DxgS2FEd.js} +2 -2
- package/lib/{ssrEntryLoader-BvAkpCyi.js → ssrEntryLoader-DmqLXUmm.js} +206 -49
- package/lib/{ssrVmStrategy-CDbcwMnf.js → ssrVmStrategy-B_e3yqa2.js} +74 -5
- package/lib/utils/ssrEntryLoader.js +1 -1
- package/package.json +4 -4
- package/lib/buildPaths-BoaQTkxt.js +0 -66
|
@@ -1,40 +1,10 @@
|
|
|
1
1
|
import { d as getNodeModulesSuffix, r as getSharedRuntimeKey } from "./sharedKeyMatcher-Od_nYxJA.js";
|
|
2
|
+
import { r as mfWarn, t as createModuleFederationError } from "./logger--uKHOVjR.js";
|
|
2
3
|
import { existsSync, readFileSync, readdirSync, realpathSync } from "fs";
|
|
3
4
|
import { createRequire } from "module";
|
|
4
5
|
import * as path$1 from "node:path";
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
6
7
|
import { createHash } from "node:crypto";
|
|
7
|
-
//#region src/utils/logger.ts
|
|
8
|
-
const MODULE_FEDERATION_LOG_PREFIX = "[Module Federation]";
|
|
9
|
-
function formatModuleFederationMessage(message) {
|
|
10
|
-
return `${MODULE_FEDERATION_LOG_PREFIX} ${message}`;
|
|
11
|
-
}
|
|
12
|
-
function createModuleFederationError(message) {
|
|
13
|
-
return new Error(formatModuleFederationMessage(message));
|
|
14
|
-
}
|
|
15
|
-
function toConsoleArgs(message, rest = []) {
|
|
16
|
-
if (typeof message === "string") return [formatModuleFederationMessage(message), ...rest];
|
|
17
|
-
if (message === void 0) return [MODULE_FEDERATION_LOG_PREFIX, ...rest];
|
|
18
|
-
return [
|
|
19
|
-
MODULE_FEDERATION_LOG_PREFIX,
|
|
20
|
-
message,
|
|
21
|
-
...rest
|
|
22
|
-
];
|
|
23
|
-
}
|
|
24
|
-
const moduleFederationConsole = {
|
|
25
|
-
log(message, ...rest) {
|
|
26
|
-
console.log(...toConsoleArgs(message, rest));
|
|
27
|
-
},
|
|
28
|
-
warn(message, ...rest) {
|
|
29
|
-
console.warn(...toConsoleArgs(message, rest));
|
|
30
|
-
},
|
|
31
|
-
error(message, ...rest) {
|
|
32
|
-
console.error(...toConsoleArgs(message, rest));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const mfWarn = moduleFederationConsole.warn;
|
|
36
|
-
const mfError = moduleFederationConsole.error;
|
|
37
|
-
//#endregion
|
|
38
8
|
//#region src/utils/reactShares.ts
|
|
39
9
|
/** Property under which React 19 exposes its internals object. */
|
|
40
10
|
const REACT_CLIENT_INTERNALS_KEY = "__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE";
|
|
@@ -685,4 +655,4 @@ function hasPackageDependency(dependencyName, cwd = packageDetectionCwd || proce
|
|
|
685
655
|
//#region src/utils/dtsConstants.ts
|
|
686
656
|
const DEFAULT_PUBLIC_TYPES_FOLDER = "@mf-types";
|
|
687
657
|
//#endregion
|
|
688
|
-
export { isReactCoreShare as C,
|
|
658
|
+
export { isReactCoreShare as C, REACT_DOM_CLIENT_SHARE as S, resolveModulePath as _, getIsRolldown as a, supportsCodeSplittingGroupDebugName as b, getPackageNameFromNodeModulePath as c, isNuxtProjectRoot as d, isPackageExportAvailable as f, resolveImportPath as g, packageNameEncode as h, getInstalledPackageJson as i, getSharedCacheDescriptor as l, packageNameDecode as m, getDependencyNames as n, getPackageDetectionCwd as o, isPackageInstalled as p, getInstalledPackageEntry as r, getPackageName as s, DEFAULT_PUBLIC_TYPES_FOLDER as t, hasPackageDependency as u, setPackageDetectionCwd as v, REACT_CLIENT_INTERNALS_KEY as x, sharedCacheHelperCode as y };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as resolvePublicPath, a as matchesSharedSource, c as filterId, d as getNodeModulesSuffix, f as isAssetLikeImport, g as normalizeNodeModulePath, h as isViteOptimizableEntry, i as invalidateSharedKeyMatcher, l as getBasePath$1, m as isNuxtClientBase, n as getSharedRequest, p as isNodeModulePath, r as getSharedRuntimeKey, s as ensureTrailingSlash, t as findSharedKey, u as getCommonSharedSubpaths, v as stripQueryAndHash, y as stripViteFsPrefix } from "./sharedKeyMatcher-Od_nYxJA.js";
|
|
2
|
-
import {
|
|
3
|
-
import { C as isReactCoreShare,
|
|
2
|
+
import { a as CodeRewriter, c as normalizePathForImport, i as createCodePositionMap, l as rebaseImport, o as createSourceMap, r as mfWarn, t as createModuleFederationError, u as resolveHashPlaceholderFileName } from "./logger--uKHOVjR.js";
|
|
3
|
+
import { C as isReactCoreShare, S as REACT_DOM_CLIENT_SHARE, _ as resolveModulePath, a as getIsRolldown, b as supportsCodeSplittingGroupDebugName, c as getPackageNameFromNodeModulePath, d as isNuxtProjectRoot, f as isPackageExportAvailable, g as resolveImportPath, h as packageNameEncode, i as getInstalledPackageJson, l as getSharedCacheDescriptor, m as packageNameDecode, n as getDependencyNames, o as getPackageDetectionCwd, p as isPackageInstalled, r as getInstalledPackageEntry, s as getPackageName, u as hasPackageDependency, v as setPackageDetectionCwd, x as REACT_CLIENT_INTERNALS_KEY, y as sharedCacheHelperCode } from "./dtsConstants-Bs4FukGL.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import * as fs$2 from "fs";
|
|
6
6
|
import { existsSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "fs";
|
|
@@ -236,134 +236,6 @@ function findRemoteEntryFile(filename, bundle) {
|
|
|
236
236
|
return fallback;
|
|
237
237
|
}
|
|
238
238
|
//#endregion
|
|
239
|
-
//#region src/utils/codeRewriter.ts
|
|
240
|
-
const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
241
|
-
var CodeRewriter = class {
|
|
242
|
-
original;
|
|
243
|
-
replacements = [];
|
|
244
|
-
constructor(original) {
|
|
245
|
-
this.original = original;
|
|
246
|
-
}
|
|
247
|
-
overwrite(start, end, content) {
|
|
248
|
-
if (start < 0 || end < start || end > this.original.length) throw new Error(`Invalid overwrite range: ${start}-${end}`);
|
|
249
|
-
this.replacements.push({
|
|
250
|
-
start,
|
|
251
|
-
end,
|
|
252
|
-
content
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
toString() {
|
|
256
|
-
return applyReplacements(this.original, this.getSortedReplacements()).code;
|
|
257
|
-
}
|
|
258
|
-
generateMap(source = "") {
|
|
259
|
-
const { code, replacements } = applyReplacements(this.original, this.getSortedReplacements());
|
|
260
|
-
return {
|
|
261
|
-
version: 3,
|
|
262
|
-
sources: [source],
|
|
263
|
-
sourcesContent: [this.original],
|
|
264
|
-
names: [],
|
|
265
|
-
mappings: generateLineMappings(code, this.original, replacements)
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
getSortedReplacements() {
|
|
269
|
-
return [...this.replacements].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
function createSourceMap(code, source = "") {
|
|
273
|
-
return {
|
|
274
|
-
version: 3,
|
|
275
|
-
sources: [source],
|
|
276
|
-
sourcesContent: [code],
|
|
277
|
-
names: [],
|
|
278
|
-
mappings: generateLineMappings(code, code, [])
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function applyReplacements(original, replacements) {
|
|
282
|
-
let code = "";
|
|
283
|
-
let cursor = 0;
|
|
284
|
-
let delta = 0;
|
|
285
|
-
const applied = [];
|
|
286
|
-
for (const replacement of replacements) {
|
|
287
|
-
if (replacement.start < cursor) throw new Error("Overlapping overwrite ranges are not supported");
|
|
288
|
-
code += original.slice(cursor, replacement.start);
|
|
289
|
-
const generatedStart = replacement.start + delta;
|
|
290
|
-
code += replacement.content;
|
|
291
|
-
const generatedEnd = generatedStart + replacement.content.length;
|
|
292
|
-
applied.push({
|
|
293
|
-
...replacement,
|
|
294
|
-
generatedStart,
|
|
295
|
-
generatedEnd
|
|
296
|
-
});
|
|
297
|
-
cursor = replacement.end;
|
|
298
|
-
delta += replacement.content.length - (replacement.end - replacement.start);
|
|
299
|
-
}
|
|
300
|
-
code += original.slice(cursor);
|
|
301
|
-
return {
|
|
302
|
-
code,
|
|
303
|
-
replacements: applied
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
function generateLineMappings(generated, original, replacements) {
|
|
307
|
-
const generatedLineStarts = getLineStarts(generated);
|
|
308
|
-
const originalLineStarts = getLineStarts(original);
|
|
309
|
-
let previousOriginalLine = 0;
|
|
310
|
-
let previousOriginalColumn = 0;
|
|
311
|
-
let mappings = "";
|
|
312
|
-
generatedLineStarts.forEach((generatedOffset, lineIndex) => {
|
|
313
|
-
if (lineIndex > 0) mappings += ";";
|
|
314
|
-
const originalOffset = generatedOffsetToOriginalOffset(generatedOffset, replacements);
|
|
315
|
-
const originalLine = findLine(originalLineStarts, originalOffset);
|
|
316
|
-
const originalColumn = originalOffset - originalLineStarts[originalLine];
|
|
317
|
-
mappings += encodeSegment([
|
|
318
|
-
0,
|
|
319
|
-
0,
|
|
320
|
-
originalLine - previousOriginalLine,
|
|
321
|
-
originalColumn - previousOriginalColumn
|
|
322
|
-
]);
|
|
323
|
-
previousOriginalLine = originalLine;
|
|
324
|
-
previousOriginalColumn = originalColumn;
|
|
325
|
-
});
|
|
326
|
-
return mappings;
|
|
327
|
-
}
|
|
328
|
-
function generatedOffsetToOriginalOffset(offset, replacements) {
|
|
329
|
-
let delta = 0;
|
|
330
|
-
for (const replacement of replacements) {
|
|
331
|
-
if (offset < replacement.generatedStart) break;
|
|
332
|
-
if (offset < replacement.generatedEnd) return replacement.start;
|
|
333
|
-
delta += replacement.content.length - (replacement.end - replacement.start);
|
|
334
|
-
}
|
|
335
|
-
return offset - delta;
|
|
336
|
-
}
|
|
337
|
-
function getLineStarts(code) {
|
|
338
|
-
const starts = [0];
|
|
339
|
-
for (let i = 0; i < code.length; i++) if (code.charCodeAt(i) === 10) starts.push(i + 1);
|
|
340
|
-
return starts;
|
|
341
|
-
}
|
|
342
|
-
function findLine(lineStarts, offset) {
|
|
343
|
-
let low = 0;
|
|
344
|
-
let high = lineStarts.length - 1;
|
|
345
|
-
while (low <= high) {
|
|
346
|
-
const mid = low + high >> 1;
|
|
347
|
-
if (lineStarts[mid] <= offset) low = mid + 1;
|
|
348
|
-
else high = mid - 1;
|
|
349
|
-
}
|
|
350
|
-
return Math.max(0, high);
|
|
351
|
-
}
|
|
352
|
-
function encodeSegment(values) {
|
|
353
|
-
return values.map(encodeVlq).join("");
|
|
354
|
-
}
|
|
355
|
-
function encodeVlq(value) {
|
|
356
|
-
let vlq = value < 0 ? (-value << 1) + 1 : value << 1;
|
|
357
|
-
let encoded = "";
|
|
358
|
-
do {
|
|
359
|
-
let digit = vlq & 31;
|
|
360
|
-
vlq >>>= 5;
|
|
361
|
-
if (vlq > 0) digit |= 32;
|
|
362
|
-
encoded += BASE64_CHARS[digit];
|
|
363
|
-
} while (vlq > 0);
|
|
364
|
-
return encoded;
|
|
365
|
-
}
|
|
366
|
-
//#endregion
|
|
367
239
|
//#region src/utils/mapCodeToCodeWithSourcemap.ts
|
|
368
240
|
async function mapCodeToCodeWithSourcemap(code) {
|
|
369
241
|
const resolvedCode = await code;
|
|
@@ -416,147 +288,6 @@ function resolveRemoteConsumer(ctx, hasMultiEnvironment) {
|
|
|
416
288
|
return resolveEnvironmentConsumerTarget(ctx) ?? "client";
|
|
417
289
|
}
|
|
418
290
|
//#endregion
|
|
419
|
-
//#region src/utils/codePositionMap.ts
|
|
420
|
-
const REGEX_PREFIX_KEYWORDS = /* @__PURE__ */ new Set([
|
|
421
|
-
"await",
|
|
422
|
-
"case",
|
|
423
|
-
"delete",
|
|
424
|
-
"in",
|
|
425
|
-
"instanceof",
|
|
426
|
-
"new",
|
|
427
|
-
"return",
|
|
428
|
-
"throw",
|
|
429
|
-
"typeof",
|
|
430
|
-
"void",
|
|
431
|
-
"yield"
|
|
432
|
-
]);
|
|
433
|
-
function isJsxClosingTagSlash(code, slashIndex) {
|
|
434
|
-
if (code[slashIndex - 1] !== "<") return false;
|
|
435
|
-
let cursor = slashIndex + 1;
|
|
436
|
-
while (/\s/.test(code[cursor] || "")) cursor++;
|
|
437
|
-
if (code[cursor] === ">") return true;
|
|
438
|
-
const tagStart = cursor;
|
|
439
|
-
while (/[-:.$_\u200C\u200D\p{ID_Continue}]/u.test(code[cursor] || "")) cursor++;
|
|
440
|
-
if (cursor === tagStart) return false;
|
|
441
|
-
while (/\s/.test(code[cursor] || "")) cursor++;
|
|
442
|
-
return code[cursor] === ">";
|
|
443
|
-
}
|
|
444
|
-
/** Mark comments, string/template literals, and regular expressions as non-code. */
|
|
445
|
-
function createCodePositionMap(code, onComment) {
|
|
446
|
-
const positions = Array(code.length).fill(true);
|
|
447
|
-
const mask = (start, end) => {
|
|
448
|
-
for (let index = start; index < end; index++) positions[index] = false;
|
|
449
|
-
};
|
|
450
|
-
let canStartRegex = true;
|
|
451
|
-
for (let index = 0; index < code.length;) {
|
|
452
|
-
const char = code[index];
|
|
453
|
-
const next = code[index + 1];
|
|
454
|
-
if (/\s/.test(char)) {
|
|
455
|
-
index++;
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
if (char === "/" && next === "/") {
|
|
459
|
-
const start = index;
|
|
460
|
-
index += 2;
|
|
461
|
-
while (index < code.length && code[index] !== "\n" && code[index] !== "\r") index++;
|
|
462
|
-
mask(start, index);
|
|
463
|
-
onComment?.(start, index);
|
|
464
|
-
continue;
|
|
465
|
-
}
|
|
466
|
-
if (char === "/" && next === "*") {
|
|
467
|
-
const start = index;
|
|
468
|
-
index += 2;
|
|
469
|
-
while (index < code.length && !(code[index] === "*" && code[index + 1] === "/")) index++;
|
|
470
|
-
index = Math.min(code.length, index + 2);
|
|
471
|
-
mask(start, index);
|
|
472
|
-
onComment?.(start, index);
|
|
473
|
-
continue;
|
|
474
|
-
}
|
|
475
|
-
if (char === "\"" || char === "'" || char === "`") {
|
|
476
|
-
const quote = char;
|
|
477
|
-
const start = index++;
|
|
478
|
-
while (index < code.length) {
|
|
479
|
-
if (code[index] === "\\") {
|
|
480
|
-
index += 2;
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
483
|
-
if (code[index] === quote) {
|
|
484
|
-
index++;
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
index++;
|
|
488
|
-
}
|
|
489
|
-
mask(start, index);
|
|
490
|
-
canStartRegex = false;
|
|
491
|
-
continue;
|
|
492
|
-
}
|
|
493
|
-
const closesJsxTag = isJsxClosingTagSlash(code, index);
|
|
494
|
-
if (char === "/" && canStartRegex && !closesJsxTag) {
|
|
495
|
-
const start = index;
|
|
496
|
-
let cursor = index + 1;
|
|
497
|
-
let escaped = false;
|
|
498
|
-
let inCharacterClass = false;
|
|
499
|
-
let closed = false;
|
|
500
|
-
for (; cursor < code.length; cursor++) {
|
|
501
|
-
const regexChar = code[cursor];
|
|
502
|
-
if (regexChar === "\n" || regexChar === "\r") break;
|
|
503
|
-
if (escaped) {
|
|
504
|
-
escaped = false;
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
if (regexChar === "\\") {
|
|
508
|
-
escaped = true;
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
if (regexChar === "[") {
|
|
512
|
-
inCharacterClass = true;
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
if (regexChar === "]" && inCharacterClass) {
|
|
516
|
-
inCharacterClass = false;
|
|
517
|
-
continue;
|
|
518
|
-
}
|
|
519
|
-
if (regexChar === "/" && !inCharacterClass) {
|
|
520
|
-
cursor++;
|
|
521
|
-
while (/[$_\p{ID_Continue}]/u.test(code[cursor] || "")) cursor++;
|
|
522
|
-
closed = true;
|
|
523
|
-
break;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
if (closed) {
|
|
527
|
-
mask(start, cursor);
|
|
528
|
-
index = cursor;
|
|
529
|
-
canStartRegex = false;
|
|
530
|
-
continue;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
if (/[$_\p{ID_Start}]/u.test(char)) {
|
|
534
|
-
const start = index++;
|
|
535
|
-
while (/[$_\u200C\u200D\p{ID_Continue}]/u.test(code[index] || "")) index++;
|
|
536
|
-
canStartRegex = REGEX_PREFIX_KEYWORDS.has(code.slice(start, index));
|
|
537
|
-
continue;
|
|
538
|
-
}
|
|
539
|
-
if (/\d/.test(char)) {
|
|
540
|
-
index++;
|
|
541
|
-
while (/[\w.]/.test(code[index] || "")) index++;
|
|
542
|
-
canStartRegex = false;
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
if ((char === "+" || char === "-") && next === char) {
|
|
546
|
-
index += 2;
|
|
547
|
-
continue;
|
|
548
|
-
}
|
|
549
|
-
if (char === "!" && next !== "=") {
|
|
550
|
-
index++;
|
|
551
|
-
continue;
|
|
552
|
-
}
|
|
553
|
-
if (char === ")" || char === "]" || char === "}") canStartRegex = false;
|
|
554
|
-
else if (char !== ".") canStartRegex = true;
|
|
555
|
-
index++;
|
|
556
|
-
}
|
|
557
|
-
return positions;
|
|
558
|
-
}
|
|
559
|
-
//#endregion
|
|
560
291
|
//#region src/utils/htmlEntryUtils.ts
|
|
561
292
|
const IDENTIFIER = String.raw`[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*`;
|
|
562
293
|
const NAMED_SPECIFIERS = String.raw`\{[^{}]*\}`;
|
|
@@ -722,18 +453,18 @@ function normalizeExposes(exposes) {
|
|
|
722
453
|
});
|
|
723
454
|
return res;
|
|
724
455
|
}
|
|
725
|
-
function normalizeRemotes(remotes) {
|
|
456
|
+
function normalizeRemotes(remotes, defaultShareScope = "default") {
|
|
726
457
|
if (!remotes) return {};
|
|
727
458
|
const result = {};
|
|
728
459
|
if (typeof remotes === "object") Object.keys(remotes).forEach((key) => {
|
|
729
|
-
result[key] = normalizeRemoteItem(key, remotes[key]);
|
|
460
|
+
result[key] = normalizeRemoteItem(key, remotes[key], defaultShareScope);
|
|
730
461
|
});
|
|
731
462
|
return result;
|
|
732
463
|
}
|
|
733
464
|
function warnOmittedObjectRemoteType(remoteKey) {
|
|
734
465
|
mfWarn(`Remote "${remoteKey}" omits type and defaults to 'var'. Set type: 'module' for Vite ESM remotes, or type: 'var' explicitly to silence this warning.`);
|
|
735
466
|
}
|
|
736
|
-
function normalizeRemoteItem(key, remote) {
|
|
467
|
+
function normalizeRemoteItem(key, remote, defaultShareScope) {
|
|
737
468
|
warnOnReservedInternalNamePrefix(key, "remoteAlias");
|
|
738
469
|
if (typeof remote === "string") {
|
|
739
470
|
const separatorIndex = remote.startsWith("@") ? remote.indexOf("@", 1) : remote.indexOf("@");
|
|
@@ -752,7 +483,7 @@ function normalizeRemoteItem(key, remote) {
|
|
|
752
483
|
internalName: toInternalModuleFederationName(key),
|
|
753
484
|
entry,
|
|
754
485
|
entryGlobalName,
|
|
755
|
-
shareScope:
|
|
486
|
+
shareScope: defaultShareScope
|
|
756
487
|
};
|
|
757
488
|
}
|
|
758
489
|
const typeOmitted = remote.type === void 0 || remote.type === null || remote.type === "";
|
|
@@ -761,7 +492,7 @@ function normalizeRemoteItem(key, remote) {
|
|
|
761
492
|
type: "var",
|
|
762
493
|
name: key,
|
|
763
494
|
internalName: toInternalModuleFederationName(key),
|
|
764
|
-
shareScope:
|
|
495
|
+
shareScope: defaultShareScope,
|
|
765
496
|
entryGlobalName: key
|
|
766
497
|
}, {
|
|
767
498
|
...remote,
|
|
@@ -869,7 +600,7 @@ function resolveSharedVersions(shared, root) {
|
|
|
869
600
|
item.shareConfig.requiredVersion = requiredVersion;
|
|
870
601
|
}
|
|
871
602
|
}
|
|
872
|
-
function normalizeShareItem(key, shareItem) {
|
|
603
|
+
function normalizeShareItem(key, shareItem, defaultShareScope) {
|
|
873
604
|
const treeShaking = typeof shareItem === "object" ? shareItem.treeShaking : void 0;
|
|
874
605
|
if (treeShaking && treeShaking.mode !== "server-calc" && treeShaking.mode !== "runtime-infer") throw createModuleFederationError(`Invalid shared config for "${key}": treeShaking.mode must be either "server-calc" or "runtime-infer".`);
|
|
875
606
|
if (treeShaking && typeof shareItem === "object" && shareItem.eager) throw createModuleFederationError(`Invalid shared config for "${key}": cannot use both "eager: true" and "treeShaking.mode" simultaneously. Choose one strategy.`);
|
|
@@ -885,7 +616,7 @@ function normalizeShareItem(key, shareItem) {
|
|
|
885
616
|
const result = {
|
|
886
617
|
name: shareItem,
|
|
887
618
|
version,
|
|
888
|
-
scope:
|
|
619
|
+
scope: defaultShareScope,
|
|
889
620
|
from: "",
|
|
890
621
|
shareConfig: {
|
|
891
622
|
import: void 0,
|
|
@@ -901,7 +632,7 @@ function normalizeShareItem(key, shareItem) {
|
|
|
901
632
|
name: key,
|
|
902
633
|
from: "",
|
|
903
634
|
version,
|
|
904
|
-
scope: shareItem.shareScope ||
|
|
635
|
+
scope: shareItem.shareScope || defaultShareScope,
|
|
905
636
|
shareConfig: {
|
|
906
637
|
import: shareItem.import,
|
|
907
638
|
singleton: shareItem.singleton || false,
|
|
@@ -940,7 +671,7 @@ function normalizeSharedKey(key) {
|
|
|
940
671
|
if (baseKey === "react") return key;
|
|
941
672
|
return getCommonSharedSubpaths(baseKey).length > 0 ? baseKey : key;
|
|
942
673
|
}
|
|
943
|
-
function normalizeShared(shared) {
|
|
674
|
+
function normalizeShared(shared, defaultShareScope = "default") {
|
|
944
675
|
explicitSharedKeys = /* @__PURE__ */ new Set();
|
|
945
676
|
if (!shared) return {};
|
|
946
677
|
const result = {};
|
|
@@ -949,7 +680,7 @@ function normalizeShared(shared) {
|
|
|
949
680
|
if (isModuleFederationRuntimePackage(key)) return;
|
|
950
681
|
const normalizedKey = normalizeSharedKey(key);
|
|
951
682
|
const hadConfiguredPackageSubpath = (result[normalizedKey]?.shareConfig)?.__mfConfiguredPackageSubpath === true;
|
|
952
|
-
result[normalizedKey] = normalizeShareItem(normalizedKey, normalizedKey);
|
|
683
|
+
result[normalizedKey] = normalizeShareItem(normalizedKey, normalizedKey, defaultShareScope);
|
|
953
684
|
if (key.endsWith("/") || hadConfiguredPackageSubpath) result[normalizedKey].shareConfig.__mfConfiguredPackageSubpath = true;
|
|
954
685
|
explicitSharedKeys.add(normalizedKey);
|
|
955
686
|
sourceEntries.push([normalizedKey, normalizedKey]);
|
|
@@ -959,7 +690,7 @@ function normalizeShared(shared) {
|
|
|
959
690
|
const normalizedKey = normalizeSharedKey(key);
|
|
960
691
|
const value = shared[key];
|
|
961
692
|
const hadConfiguredPackageSubpath = (result[normalizedKey]?.shareConfig)?.__mfConfiguredPackageSubpath === true;
|
|
962
|
-
result[normalizedKey] = normalizeShareItem(normalizedKey, value);
|
|
693
|
+
result[normalizedKey] = normalizeShareItem(normalizedKey, value, defaultShareScope);
|
|
963
694
|
const requestIsPrefix = typeof value?.request === "string" && value.request.endsWith("/");
|
|
964
695
|
if (key.endsWith("/") || requestIsPrefix || hadConfiguredPackageSubpath) result[normalizedKey].shareConfig.__mfConfiguredPackageSubpath = true;
|
|
965
696
|
explicitSharedKeys.add(normalizedKey);
|
|
@@ -968,7 +699,7 @@ function normalizeShared(shared) {
|
|
|
968
699
|
sourceEntries.forEach(([key, value]) => {
|
|
969
700
|
for (const subpathShare of getLitExportSubpathShares(key)) {
|
|
970
701
|
if (result[subpathShare]) continue;
|
|
971
|
-
result[subpathShare] = normalizeShareItem(subpathShare, value);
|
|
702
|
+
result[subpathShare] = normalizeShareItem(subpathShare, value, defaultShareScope);
|
|
972
703
|
}
|
|
973
704
|
});
|
|
974
705
|
return result;
|
|
@@ -1048,6 +779,7 @@ function getNormalizeShareItem(key, options = getNormalizeModuleFederationOption
|
|
|
1048
779
|
function normalizeModuleFederationOptions(options) {
|
|
1049
780
|
warnOnReservedInternalNamePrefix(options.name, "containerName");
|
|
1050
781
|
if (options.virtualModuleDir && options.virtualModuleDir.includes("/")) throw createModuleFederationError(`Invalid virtualModuleDir: "${options.virtualModuleDir}". The virtualModuleDir option cannot contain slashes (/). Please use a single directory name like '__mf__virtual__your_app_name'.`);
|
|
782
|
+
const defaultShareScope = typeof options.shareScope === "string" ? options.shareScope : "default";
|
|
1051
783
|
const normalized = {
|
|
1052
784
|
exposes: normalizeExposes(options.exposes),
|
|
1053
785
|
filename: options.filename || "remoteEntry-[hash]",
|
|
@@ -1055,10 +787,10 @@ function normalizeModuleFederationOptions(options) {
|
|
|
1055
787
|
internalName: toInternalModuleFederationName(options.name),
|
|
1056
788
|
library: normalizeLibrary(options.library),
|
|
1057
789
|
name: options.name,
|
|
1058
|
-
remotes: normalizeRemotes(options.remotes),
|
|
790
|
+
remotes: normalizeRemotes(options.remotes, defaultShareScope),
|
|
1059
791
|
runtime: options.runtime,
|
|
1060
792
|
shareScope: options.shareScope || "default",
|
|
1061
|
-
shared: normalizeShared(options.shared),
|
|
793
|
+
shared: normalizeShared(options.shared, defaultShareScope),
|
|
1062
794
|
runtimePlugins: options.runtimePlugins || [],
|
|
1063
795
|
implementation: normalizePathForImport(options.implementation || resolveRuntimeImplementation()),
|
|
1064
796
|
manifest: normalizeManifest(options.manifest),
|
|
@@ -2671,6 +2403,11 @@ function resolveRelativeModule(filePath, specifier) {
|
|
|
2671
2403
|
const dir = path$1.dirname(filePath);
|
|
2672
2404
|
const exact = path$1.resolve(dir, specifier);
|
|
2673
2405
|
if (existsSync(exact) && !statSync(exact).isDirectory()) return exact;
|
|
2406
|
+
const sourceExtensions = specifier.endsWith(".mjs") ? [".mts"] : specifier.endsWith(".cjs") ? [".cts"] : /\.jsx?$/.test(specifier) ? [".ts", ".tsx"] : [];
|
|
2407
|
+
for (const ext of sourceExtensions) {
|
|
2408
|
+
const candidate = exact.replace(/\.[cm]?jsx?$/, ext);
|
|
2409
|
+
if (existsSync(candidate) && !statSync(candidate).isDirectory()) return candidate;
|
|
2410
|
+
}
|
|
2674
2411
|
const extensions = [
|
|
2675
2412
|
".ts",
|
|
2676
2413
|
".tsx",
|
|
@@ -4385,6 +4122,9 @@ const normalizeRuntimeShareCode = `const __mfNormalizeRuntimeShare = (mod) => {
|
|
|
4385
4122
|
for (let i = 0; i < 5; i++) {
|
|
4386
4123
|
const defaultExport = current?.default;
|
|
4387
4124
|
if (!defaultExport || typeof defaultExport !== "object" || Object.keys(defaultExport).length === 0) break;
|
|
4125
|
+
// Only unwrap plain CJS namespaces; spreading a class instance would drop its prototype.
|
|
4126
|
+
const proto = Object.getPrototypeOf(defaultExport);
|
|
4127
|
+
if (proto !== null && proto !== Object.prototype) break;
|
|
4388
4128
|
const namedValues = Object.keys(current).filter((key) => key !== "default").map((key) => current[key]);
|
|
4389
4129
|
if (namedValues.length > 0 && namedValues.some((value) => value !== undefined)) break;
|
|
4390
4130
|
current = defaultExport;
|
|
@@ -4645,8 +4385,9 @@ function generateRuntimeSharedCacheSeedCode(shareStrategy, options, command = "b
|
|
|
4645
4385
|
__mfNormalizeRuntimeShare(externalResolved),
|
|
4646
4386
|
externalProvider.from
|
|
4647
4387
|
);
|
|
4388
|
+
return;
|
|
4648
4389
|
}
|
|
4649
|
-
return;
|
|
4390
|
+
if (typeof isWebpackProvider === 'function' && isWebpackProvider(externalProvider)) return;
|
|
4650
4391
|
}
|
|
4651
4392
|
const providerKey = cacheDescriptor.canonical;
|
|
4652
4393
|
const resolved = await __mfInitializeProviderOnce(providerKey, async () => {
|
|
@@ -6967,6 +6708,19 @@ for (const __mfRemoteEntryPrefetchUrl of __mfRemoteEntryPrefetchUrls) {
|
|
|
6967
6708
|
apply: "serve",
|
|
6968
6709
|
config(_config, { command }) {
|
|
6969
6710
|
_command = command;
|
|
6711
|
+
const isRemoteEntry = entryName === "remoteEntry" && federationOptions !== void 0 && isRemoteContainer(federationOptions);
|
|
6712
|
+
if (command === "serve" && _config.experimental?.bundledDev && isRemoteEntry) {
|
|
6713
|
+
_config.experimental = {
|
|
6714
|
+
..._config.experimental,
|
|
6715
|
+
bundledDev: false
|
|
6716
|
+
};
|
|
6717
|
+
_config.environments ??= {};
|
|
6718
|
+
_config.environments.client ??= {};
|
|
6719
|
+
if (_config.environments.client.isBundled !== false) {
|
|
6720
|
+
_config.environments.client.isBundled = false;
|
|
6721
|
+
mfWarn("Vite bundledDev is disabled for the client environment of a Module Federation remote container so its remoteEntry keeps the standard init/get contract.");
|
|
6722
|
+
}
|
|
6723
|
+
}
|
|
6970
6724
|
},
|
|
6971
6725
|
configResolved(config) {
|
|
6972
6726
|
viteConfig = config;
|
|
@@ -8263,7 +8017,8 @@ function pluginLazyConsumeOnlyShares(options) {
|
|
|
8263
8017
|
const rewriter = new CodeRewriter(code);
|
|
8264
8018
|
let edited = false;
|
|
8265
8019
|
const importMapId = normalizeVirtualModuleId(getLocalSharedImportMapPath(options));
|
|
8266
|
-
|
|
8020
|
+
const isImportMapChunk = chunkModuleIds(renderedChunk).some((id) => normalizeVirtualModuleId(id) === importMapId);
|
|
8021
|
+
if (isImportMapChunk) for (const quote of QUOTES) {
|
|
8267
8022
|
const literal = `${quote}${LAZY_CONSUME_ONLY_SHARES_PLACEHOLDER}${quote}`;
|
|
8268
8023
|
const start = code.indexOf(literal);
|
|
8269
8024
|
if (start === -1) continue;
|
|
@@ -8274,7 +8029,7 @@ function pluginLazyConsumeOnlyShares(options) {
|
|
|
8274
8029
|
const chunkDir = path$1.posix.dirname(renderedChunk.fileName);
|
|
8275
8030
|
const codePositions = createCodePositionMap(code);
|
|
8276
8031
|
let usesHelper = false;
|
|
8277
|
-
for (const match of code.matchAll(DYNAMIC_IMPORT_REGEX)) {
|
|
8032
|
+
for (const match of isImportMapChunk ? [] : code.matchAll(DYNAMIC_IMPORT_REGEX)) {
|
|
8278
8033
|
const [expression, , specifier] = match;
|
|
8279
8034
|
const start = match.index;
|
|
8280
8035
|
if (!codePositions[start]) continue;
|
|
@@ -8303,7 +8058,7 @@ function ${helperName}(names) {
|
|
|
8303
8058
|
}
|
|
8304
8059
|
//#endregion
|
|
8305
8060
|
//#region package.json
|
|
8306
|
-
var version$1 = "1.23.
|
|
8061
|
+
var version$1 = "1.23.1";
|
|
8307
8062
|
//#endregion
|
|
8308
8063
|
//#region src/virtualModules/virtualExposesSSR.ts
|
|
8309
8064
|
/**
|
|
@@ -9239,7 +8994,12 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
|
|
|
9239
8994
|
if (!dynamic) dependencies.add(source);
|
|
9240
8995
|
continue;
|
|
9241
8996
|
}
|
|
9242
|
-
|
|
8997
|
+
let resolved;
|
|
8998
|
+
try {
|
|
8999
|
+
resolved = await ctx.resolve(source, id);
|
|
9000
|
+
} catch {
|
|
9001
|
+
continue;
|
|
9002
|
+
}
|
|
9243
9003
|
if (!resolved?.id || !shouldScanResolvedImport(resolved.id)) continue;
|
|
9244
9004
|
for (const dependency of await collectRemoteDependencies(ctx, resolved.id, seen)) dependencies.add(dependency);
|
|
9245
9005
|
}
|
|
@@ -11475,17 +11235,20 @@ function registerEntryImports(options, projectRoot, recordShared = true, entryFi
|
|
|
11475
11235
|
addUsedRemote(remoteKey, request, options);
|
|
11476
11236
|
markStaticRemote(request, options);
|
|
11477
11237
|
markPreloadRemote(request, options);
|
|
11478
|
-
} else if (sharedKey && recordShared)
|
|
11238
|
+
} else if (sharedKey && recordShared) materializeSharedRequest(options, request);
|
|
11479
11239
|
else if (request && !typeOnly) enqueue(request, file, preloadRemotes && isStatic);
|
|
11480
11240
|
}
|
|
11481
11241
|
}
|
|
11482
11242
|
return hasJsxSource;
|
|
11483
11243
|
}
|
|
11244
|
+
function materializeSharedRequest(options, request) {
|
|
11245
|
+
addUsedShares(request, options);
|
|
11246
|
+
const packageName = getPackageName(request);
|
|
11247
|
+
if (packageName !== request && findSharedKey(packageName, options.shared)) addUsedShares(packageName, options);
|
|
11248
|
+
}
|
|
11484
11249
|
function materializeAutomaticJsxRuntime(options, runtime) {
|
|
11485
11250
|
if (!findSharedKey(runtime, options.shared)) return false;
|
|
11486
|
-
|
|
11487
|
-
const packageName = getPackageName(runtime);
|
|
11488
|
-
if (packageName !== runtime && findSharedKey(packageName, options.shared)) addUsedShares(packageName, options);
|
|
11251
|
+
materializeSharedRequest(options, runtime);
|
|
11489
11252
|
return true;
|
|
11490
11253
|
}
|
|
11491
11254
|
/**
|
|
@@ -11753,7 +11516,7 @@ function applyBuildTimeRuntimeDefines(define, options, { target, isAstro, defaul
|
|
|
11753
11516
|
}
|
|
11754
11517
|
function loadPluginDts(options) {
|
|
11755
11518
|
if (options.dts === false) return [];
|
|
11756
|
-
return [import("./pluginDts-
|
|
11519
|
+
return [import("./pluginDts-DxgS2FEd.js").then(({ default: pluginDts }) => pluginDts(options))];
|
|
11757
11520
|
}
|
|
11758
11521
|
const INJECT_EXTERNAL_RUNTIME_CORE_PLUGIN = "@module-federation/vite/injectExternalRuntimeCorePlugin";
|
|
11759
11522
|
function isInjectExternalRuntimeCorePlugin(specifier) {
|
|
@@ -12267,6 +12030,14 @@ function federation(mfUserOptions) {
|
|
|
12267
12030
|
config.build ??= {};
|
|
12268
12031
|
config.build.target ??= "esnext";
|
|
12269
12032
|
}
|
|
12033
|
+
const isBundledDev = Boolean(config.experimental?.bundledDev);
|
|
12034
|
+
if (isRolldown && _command === "serve" && isBundledDev) {
|
|
12035
|
+
config.build.rolldownOptions ??= {};
|
|
12036
|
+
config.build.rolldownOptions.experimental ??= {};
|
|
12037
|
+
const devMode = config.build.rolldownOptions.experimental.devMode;
|
|
12038
|
+
if (typeof devMode === "object") devMode.lazy ??= false;
|
|
12039
|
+
else if (devMode === void 0) config.build.rolldownOptions.experimental.devMode = { lazy: false };
|
|
12040
|
+
}
|
|
12270
12041
|
const isAstro = hasPackageDependency("astro");
|
|
12271
12042
|
const resolvedTarget = options.target ?? (config.build?.ssr ? "node" : "web");
|
|
12272
12043
|
if (!config.define) config.define = {};
|