@module-federation/vite 1.16.6 → 1.16.8

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 normalizePathForImport, a as getPackageName, c as hasPackageDependency, d as packageNameEncode, f as resolveImportPath, g as mfWarn, i as getPackageDetectionCwd, l as isNuxtProjectRoot, m as createModuleFederationError, n as getInstalledPackageJson, o as getPackageNameFromNodeModulePath, p as setPackageDetectionCwd, r as getIsRolldown, s as getSharedCacheKey, t as getInstalledPackageEntry, u as packageNameDecode, v as rebaseImport } from "./packageUtils-CYnJFfPP.js";
1
+ import { _ as mfWarn, a as getIsRolldown, c as getPackageNameFromNodeModulePath, d as isNuxtProjectRoot, f as packageNameDecode, g as createModuleFederationError, h as setPackageDetectionCwd, i as getInstalledPackageJson, l as getSharedCacheKey, m as resolveImportPath, o as getPackageDetectionCwd, p as packageNameEncode, r as getInstalledPackageEntry, s as getPackageName, u as hasPackageDependency, v as normalizePathForImport, y as rebaseImport } from "./pluginDts-Cpmdbbr0.js";
2
2
  import { createRequire } from "node:module";
3
3
  import * as fs$1 from "fs";
4
4
  import { existsSync, readFileSync, realpathSync, statSync, writeFileSync } from "fs";
@@ -419,6 +419,7 @@ function getSuffix(name) {
419
419
  }
420
420
  const patternMap = {};
421
421
  const cacheMap = {};
422
+ const idCacheMap = {};
422
423
  const VITE_ID_PREFIX = "/@id/";
423
424
  const VITE_ENCODED_NULL_BYTE_PREFIX = `${VITE_ID_PREFIX}__x00__`;
424
425
  function escapeRegExp$1(value) {
@@ -453,6 +454,8 @@ var VirtualModule = class VirtualModule {
453
454
  suffix;
454
455
  inited = false;
455
456
  code;
457
+ importId;
458
+ importIdKey;
456
459
  static findName(tag, str = "") {
457
460
  if (!patternMap[tag]) patternMap[tag] = new RegExp(`(.*${packageNameEncode(tag)}(.+?)${packageNameEncode(tag)}.*)`);
458
461
  const moduleName = (normalizeVirtualModuleId(str).match(patternMap[tag]) || [])[2];
@@ -464,7 +467,7 @@ var VirtualModule = class VirtualModule {
464
467
  }
465
468
  static findById(id) {
466
469
  const normalized = normalizeVirtualModuleId(id);
467
- for (const modules of Object.values(cacheMap)) for (const module of Object.values(modules)) if (module.getImportId() === normalized) return module;
470
+ return normalized.startsWith("virtual:mf:") ? idCacheMap[normalized] : void 0;
468
471
  }
469
472
  constructor(name, tag = "__mf_v__", suffix = "") {
470
473
  this.name = name;
@@ -475,7 +478,13 @@ var VirtualModule = class VirtualModule {
475
478
  }
476
479
  getImportId() {
477
480
  const { internalName: mfName } = getNormalizeModuleFederationOptions();
478
- return `virtual:mf:${packageNameEncode(`${mfName}${this.tag}${this.name}${this.tag}`)}${this.suffix}`;
481
+ const importIdKey = `${mfName}${this.tag}${this.name}${this.tag}`;
482
+ if (this.importId && this.importIdKey === importIdKey) return this.importId;
483
+ if (this.importId) delete idCacheMap[this.importId];
484
+ this.importIdKey = importIdKey;
485
+ this.importId = `virtual:mf:${packageNameEncode(importIdKey)}${this.suffix}`;
486
+ idCacheMap[this.importId] = this;
487
+ return this.importId;
479
488
  }
480
489
  getResolvedId() {
481
490
  return `\0${this.getImportId()}`;
@@ -1084,11 +1093,15 @@ function toViteOptimizedDepVirtualId(id) {
1084
1093
  return toViteEncodedId(id);
1085
1094
  }
1086
1095
  function getCachedLoadSharePkg(id) {
1096
+ if (!id.includes("__loadShare__")) return;
1087
1097
  const normalized = normalizeVirtualModuleId(id);
1088
1098
  if (!normalized.startsWith("virtual:mf:")) return;
1089
- const pkg = VirtualModule.findName(LOAD_SHARE_TAG, normalized);
1090
- if (!pkg) return;
1091
- return pkg;
1099
+ const start = normalized.indexOf(LOAD_SHARE_TAG);
1100
+ if (start === -1) return;
1101
+ const encodedPkgStart = start + 13;
1102
+ const end = normalized.indexOf(LOAD_SHARE_TAG, encodedPkgStart);
1103
+ if (end === -1) return;
1104
+ return packageNameDecode(normalized.slice(encodedPkgStart, end));
1092
1105
  }
1093
1106
  function materializeCachedLoadShareModule(options) {
1094
1107
  const pkg = getCachedLoadSharePkg(options.id);
@@ -1263,13 +1276,8 @@ let invalidateLocalSharedImportMap;
1263
1276
  function setLocalSharedImportMapInvalidator(invalidator) {
1264
1277
  invalidateLocalSharedImportMap = invalidator;
1265
1278
  }
1266
- let prevLocalSharedImportMapContent;
1267
1279
  function writeLocalSharedImportMap() {
1268
- const nextContent = generateLocalSharedImportMap();
1269
- if (prevLocalSharedImportMapContent !== nextContent) {
1270
- prevLocalSharedImportMapContent = nextContent;
1271
- invalidateLocalSharedImportMap?.();
1272
- }
1280
+ invalidateLocalSharedImportMap?.();
1273
1281
  }
1274
1282
  function shouldUseDirectReactImport() {
1275
1283
  const isVinext = hasPackageDependency("vinext");
@@ -1380,10 +1388,36 @@ function getOrderedUsedShares() {
1380
1388
  if (!pkg.endsWith("/")) shares.add(pkg);
1381
1389
  });
1382
1390
  } catch {}
1383
- return Array.from(shares).sort((a, b) => {
1391
+ return orderSharedDependenciesFirst(Array.from(shares).sort((a, b) => {
1384
1392
  const priority = (pkg) => pkg === "react" ? 0 : pkg === "react-dom" ? 1 : pkg.startsWith("react/") ? 2 : 3;
1385
1393
  return priority(a) - priority(b) || a.localeCompare(b);
1386
- });
1394
+ }));
1395
+ }
1396
+ function orderSharedDependenciesFirst(sharedPackages) {
1397
+ const sharedKeyByPackageName = new Map(sharedPackages.map((pkg) => [getPackageName(pkg), pkg]));
1398
+ const visiting = /* @__PURE__ */ new Set();
1399
+ const visited = /* @__PURE__ */ new Set();
1400
+ const ordered = [];
1401
+ const visit = (pkg) => {
1402
+ if (visited.has(pkg)) return;
1403
+ if (visiting.has(pkg)) return;
1404
+ visiting.add(pkg);
1405
+ const packageJson = getInstalledPackageJson(pkg)?.packageJson;
1406
+ const dependencies = {
1407
+ ...packageJson?.dependencies || {},
1408
+ ...packageJson?.peerDependencies || {},
1409
+ ...packageJson?.optionalDependencies || {}
1410
+ };
1411
+ Object.keys(dependencies).forEach((dependency) => {
1412
+ const sharedDependency = sharedKeyByPackageName.get(dependency);
1413
+ if (sharedDependency) visit(sharedDependency);
1414
+ });
1415
+ visiting.delete(pkg);
1416
+ visited.add(pkg);
1417
+ ordered.push(pkg);
1418
+ };
1419
+ sharedPackages.forEach(visit);
1420
+ return ordered;
1387
1421
  }
1388
1422
  function getShareItemForPreload(pkg) {
1389
1423
  const shared = getNormalizeModuleFederationOptions().shared;
@@ -1698,13 +1732,18 @@ function resolveRemoteInitMode(shareStrategy, consumer) {
1698
1732
  function shouldDeferRemoteLoad(initMode) {
1699
1733
  return initMode === "loaded-first-client" || initMode === "loaded-first-unified";
1700
1734
  }
1701
- /** Dev SSR only build/preview client graphs must keep deferred proxies for static imports. */
1702
- function clientNeedsRealRemoteForHydration(command, enableSsrInit) {
1735
+ /** Dev client wrappers can preload remotes while exposing stable proxies. */
1736
+ function shouldEagerLoadClientRemoteInDev(command, enableSsrInit) {
1703
1737
  return enableSsrInit && command === "serve";
1704
1738
  }
1705
- function shouldIncludeDeferredProxy(initMode, consumer, clientNeedsRealRemote, deferRemoteLoad) {
1706
- if (initMode === "eager") return consumer !== "server" && (consumer === "unified" || !clientNeedsRealRemote);
1707
- if (consumer === "client" && clientNeedsRealRemote) return false;
1739
+ function getEagerDeferredClientInit() {
1740
+ return `__mfRemotePending = __mfStartRemoteLoad().then(__mfAssignRemoteModule);
1741
+ exportModule = __mfCreateDeferredRemoteProxy();`;
1742
+ }
1743
+ function shouldIncludeDeferredProxy(initMode, consumer, eagerLoadClientRemote, deferRemoteLoad) {
1744
+ if (eagerLoadClientRemote && consumer !== "server") return true;
1745
+ if (initMode === "eager") return consumer !== "server" && (consumer === "unified" || !eagerLoadClientRemote);
1746
+ if (consumer === "client" && eagerLoadClientRemote) return false;
1708
1747
  return deferRemoteLoad || consumer !== "server";
1709
1748
  }
1710
1749
  /** Codegen shared by every remote virtual module (no top-level await). */
@@ -1883,16 +1922,16 @@ function generateRemotes(id, command, enableSsrInit = false, consumer = "unified
1883
1922
  }`;
1884
1923
  const realRemoteInit = `__mfRemotePending = __mfStartRemoteLoad().then(__mfAssignRemoteModule);`;
1885
1924
  const deferredClientInit = `exportModule = __mfCreateDeferredRemoteProxy();`;
1886
- const clientNeedsRealRemote = clientNeedsRealRemoteForHydration(command, enableSsrInit);
1887
- const eagerClientInit = clientNeedsRealRemote ? realRemoteInit : deferredClientInit;
1888
- const loadedFirstClientInit = clientNeedsRealRemote ? realRemoteInit : deferredClientInit;
1925
+ const eagerLoadClientRemote = shouldEagerLoadClientRemoteInDev(command, enableSsrInit);
1926
+ const eagerClientInit = eagerLoadClientRemote ? getEagerDeferredClientInit() : deferredClientInit;
1927
+ const loadedFirstClientInit = eagerLoadClientRemote ? getEagerDeferredClientInit() : deferredClientInit;
1889
1928
  const environmentSplitInit = (clientInit, serverInit) => consumer === "client" ? clientInit : consumer === "server" ? serverInit : `if (typeof window === "undefined") {
1890
1929
  ${serverInit}
1891
1930
  } else {
1892
1931
  ${clientInit}
1893
1932
  }`;
1894
1933
  const initExportModule = initMode === "eager" ? environmentSplitInit(eagerClientInit, realRemoteInit) : environmentSplitInit(loadedFirstClientInit, realRemoteInit);
1895
- const includeProxyHelper = shouldIncludeDeferredProxy(initMode, consumer, clientNeedsRealRemote, deferRemoteLoad);
1934
+ const includeProxyHelper = shouldIncludeDeferredProxy(initMode, consumer, eagerLoadClientRemote, deferRemoteLoad);
1896
1935
  const deferredProxyCode = getDeferredProxyHelper(id);
1897
1936
  return `
1898
1937
  ${importLine}
@@ -1909,6 +1948,36 @@ function generateRemotes(id, command, enableSsrInit = false, consumer = "unified
1909
1948
  }
1910
1949
  //#endregion
1911
1950
  //#region src/plugins/pluginAddEntry.ts
1951
+ const HOST_INIT_PRELOAD_CHUNKS = [
1952
+ (name) => name === "hostInit",
1953
+ (name) => name === "remoteEntry",
1954
+ (name) => name.startsWith("_virtual_mf"),
1955
+ (name) => name === "index"
1956
+ ];
1957
+ function escapeHtmlAttr(value) {
1958
+ return value.replace(/&/g, "&").replace(/"/g, """);
1959
+ }
1960
+ function getExistingHrefSet(html) {
1961
+ return new Set(Array.from(html.matchAll(/\bhref\s*=\s*["']([^"']+)["']/gi), (match) => match[1]));
1962
+ }
1963
+ function injectHostInitPreloads(html, bundle, resolvePath) {
1964
+ const existingHrefs = getExistingHrefSet(html);
1965
+ const seenFiles = /* @__PURE__ */ new Set();
1966
+ const hrefs = [];
1967
+ for (const chunk of Object.values(bundle)) {
1968
+ if (chunk.type !== "chunk") continue;
1969
+ if (!HOST_INIT_PRELOAD_CHUNKS.some((match) => match(chunk.name))) continue;
1970
+ if (seenFiles.has(chunk.fileName)) continue;
1971
+ seenFiles.add(chunk.fileName);
1972
+ const href = resolvePath(chunk.fileName);
1973
+ if (existingHrefs.has(href)) continue;
1974
+ existingHrefs.add(href);
1975
+ hrefs.push(href);
1976
+ }
1977
+ if (hrefs.length === 0) return html;
1978
+ const tags = hrefs.map((href) => `<link rel="modulepreload" crossorigin href="${escapeHtmlAttr(href)}">`).join("");
1979
+ return html.includes("</head>") ? html.replace("</head>", `${tags}</head>`) : `${tags}${html}`;
1980
+ }
1912
1981
  function getFirstHtmlEntryFile(entryFiles) {
1913
1982
  return entryFiles.find((file) => file.endsWith(".html"));
1914
1983
  }
@@ -2047,7 +2116,9 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2047
2116
  await Promise.allSettled(__mfRemotePreloads);` : `await initHost();`;
2048
2117
  const importCode = `
2049
2118
  (async () => {
2050
- const { initHost } = await ${importExpression(initSrc)};
2119
+ const __mfHostInit = await ${importExpression(initSrc)};
2120
+ await __mfHostInit.__tla;
2121
+ const { initHost } = __mfHostInit;
2051
2122
  ${preloadBlock}
2052
2123
  })().then(() => ${importExpression(entrySrc)});
2053
2124
  `;
@@ -2215,9 +2286,9 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2215
2286
  emittedFileName = file;
2216
2287
  const lastSlash = file.lastIndexOf("/");
2217
2288
  bootstrapDir = lastSlash !== -1 ? file.slice(0, lastSlash + 1) : "";
2218
- const resolvePath = (htmlFileName) => {
2219
- if (!viteConfig.experimental?.renderBuiltUrl) return viteConfig.base + file;
2220
- const result = viteConfig.experimental.renderBuiltUrl(file, {
2289
+ const resolvePath = (builtFileName, htmlFileName) => {
2290
+ if (!viteConfig.experimental?.renderBuiltUrl) return viteConfig.base + builtFileName;
2291
+ const result = viteConfig.experimental.renderBuiltUrl(builtFileName, {
2221
2292
  hostId: htmlFileName,
2222
2293
  hostType: "html",
2223
2294
  type: "asset",
@@ -2227,11 +2298,11 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2227
2298
  if (result && typeof result === "object") {
2228
2299
  if ("runtime" in result) {
2229
2300
  mfWarn("renderBuiltUrl returned runtime code for HTML injection. Runtime code cannot be used in <script src=\"\">. Falling back to base path.");
2230
- return viteConfig.base + file;
2301
+ return viteConfig.base + builtFileName;
2231
2302
  }
2232
- if (result.relative) return file;
2303
+ if (result.relative) return builtFileName;
2233
2304
  }
2234
- return viteConfig.base + file;
2305
+ return viteConfig.base + builtFileName;
2235
2306
  };
2236
2307
  const basePrefix = viteConfig.base?.replace(/\/$/, "") ?? "";
2237
2308
  const stripBase = (p) => basePrefix && p.startsWith(basePrefix + "/") ? p.slice(basePrefix.length) : p;
@@ -2240,7 +2311,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2240
2311
  let htmlAsset = bundle[fileName];
2241
2312
  if (htmlAsset.type === "chunk") return;
2242
2313
  let htmlContent = htmlAsset.source.toString() || "";
2243
- const initPath = resolvePath(fileName);
2314
+ const initPath = resolvePath(file, fileName);
2244
2315
  const scriptRegex = /<script\b(?=[^>]*\btype=["']module["'])(?=[^>]*\bsrc=["']([^"']+)["'])[^>]*>\s*<\/script>/gi;
2245
2316
  let rewritten = false;
2246
2317
  htmlContent = htmlContent.replace(scriptRegex, (scriptTag, entrySrc) => {
@@ -2260,15 +2331,15 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2260
2331
  });
2261
2332
  if (!rewritten) {
2262
2333
  const svelteKitHtml = rewriteSvelteKitInlineStart(htmlContent, initPath);
2263
- if (svelteKitHtml !== htmlContent) {
2264
- htmlAsset.source = svelteKitHtml;
2265
- continue;
2266
- }
2267
- const scriptContent = `
2334
+ if (svelteKitHtml !== htmlContent) htmlContent = svelteKitHtml;
2335
+ else {
2336
+ const scriptContent = `
2268
2337
  <script type="module" src="${initPath}"><\/script>
2269
2338
  `;
2270
- htmlContent = htmlContent.replace("<head>", `<head>${scriptContent}`);
2339
+ htmlContent = htmlContent.replace("<head>", `<head>${scriptContent}`);
2340
+ }
2271
2341
  }
2342
+ if (waitsForInit) htmlContent = injectHostInitPreloads(htmlContent, bundle, (builtFileName) => resolvePath(builtFileName, fileName));
2272
2343
  htmlAsset.source = htmlContent;
2273
2344
  }
2274
2345
  },
@@ -2408,7 +2479,7 @@ const REACT_REFRESH_PROXY_MODULE = [
2408
2479
  ].join("\n");
2409
2480
  const reactAdapter = {
2410
2481
  name: "react",
2411
- pluginNames: ["vite:react-refresh", "vite:react-swc:refresh"],
2482
+ pluginNames: ["vite:react-refresh", "vite:react-swc"],
2412
2483
  remote: { configureServer({ server }) {
2413
2484
  let reactRefreshRuntime;
2414
2485
  server.middlewares.use((req, res, next) => {
@@ -3372,6 +3443,34 @@ function generateRemoteEntrySSR(options) {
3372
3443
  function getBuildVersion() {
3373
3444
  return process.env["MF_BUILD_VERSION"] ?? "1.0.0";
3374
3445
  }
3446
+ /**
3447
+ * Builds the manifest `metaData.types` entry.
3448
+ *
3449
+ * When type generation is enabled, the dts plugin serves the type archive
3450
+ * (`<typesFolder>.zip`) and api file (`<typesFolder>.d.ts`). Consumers using
3451
+ * `@module-federation/dts-plugin` read `metaData.types.zip` to download those
3452
+ * types and throw `Can not get <remote>'s types archive url!` when it is absent.
3453
+ * Advertising the relative paths here (resolved against `publicPath` by the
3454
+ * consumer) mirrors the webpack/rspack (`@module-federation/enhanced`) plugins.
3455
+ */
3456
+ function resolveTypesMeta(dts) {
3457
+ if (dts === false) return {
3458
+ path: "",
3459
+ name: ""
3460
+ };
3461
+ const generateTypes = typeof dts === "object" && dts ? dts.generateTypes : void 0;
3462
+ if (generateTypes === false) return {
3463
+ path: "",
3464
+ name: ""
3465
+ };
3466
+ const typesFolder = typeof generateTypes === "object" && generateTypes?.typesFolder || "@mf-types";
3467
+ return {
3468
+ path: "",
3469
+ name: "",
3470
+ zip: `${typesFolder}.zip`,
3471
+ api: `${typesFolder}.d.ts`
3472
+ };
3473
+ }
3375
3474
  const Manifest = () => {
3376
3475
  const mfOptions = getNormalizeModuleFederationOptions();
3377
3476
  const { name, filename, getPublicPath, manifest: manifestOptions, varFilename } = mfOptions;
@@ -3435,10 +3534,7 @@ const Manifest = () => {
3435
3534
  path: "",
3436
3535
  type: "var"
3437
3536
  } : void 0,
3438
- types: {
3439
- path: "",
3440
- name: ""
3441
- },
3537
+ types: resolveTypesMeta(mfOptions.dts),
3442
3538
  globalName: name,
3443
3539
  pluginVersion: "0.2.5",
3444
3540
  publicPath
@@ -3589,10 +3685,7 @@ const Manifest = () => {
3589
3685
  remoteEntry,
3590
3686
  ssrRemoteEntry,
3591
3687
  varRemoteEntry,
3592
- types: {
3593
- path: "",
3594
- name: ""
3595
- },
3688
+ types: resolveTypesMeta(options.dts),
3596
3689
  globalName: name,
3597
3690
  pluginVersion: "0.2.5",
3598
3691
  ...!!getPublicPath ? { getPublicPath } : { publicPath }
@@ -3676,7 +3769,7 @@ function resetIdleTimeout(timeout) {
3676
3769
  }, timeout * 1e3);
3677
3770
  }
3678
3771
  function pluginModuleParseEnd_default(excludeFn, options) {
3679
- const idleTimeout = options.moduleParseIdleTimeout;
3772
+ const idleTimeout = options.moduleParseIdleTimeout ?? options.moduleParseTimeout;
3680
3773
  return [
3681
3774
  {
3682
3775
  name: "_",
@@ -3711,6 +3804,9 @@ function pluginModuleParseEnd_default(excludeFn, options) {
3711
3804
  if (excludeFn(id)) return;
3712
3805
  parseEndSet.add(id);
3713
3806
  if (parseStartSet.size === parseEndSet.size && (!expectsExposesParseEnd || exposesParseEnd)) _resolve?.(1);
3807
+ },
3808
+ buildEnd() {
3809
+ _resolve?.(1);
3714
3810
  }
3715
3811
  }
3716
3812
  ];
@@ -3973,8 +4069,42 @@ function matchesSharedSource(source, key) {
3973
4069
  return source === keyBase;
3974
4070
  }
3975
4071
  function findSharedKey(source, shared) {
3976
- const keys = Object.keys(shared || {});
3977
- return keys.find((key) => source === key) ?? keys.find((key) => matchesSharedSource(source, key));
4072
+ return getSharedKeyMatcher(shared).find(source);
4073
+ }
4074
+ const emptySharedKeyMatcher = { find: () => void 0 };
4075
+ const sharedKeyMatcherCache = /* @__PURE__ */ new WeakMap();
4076
+ function getSharedKeyMatcher(shared) {
4077
+ if (!shared) return emptySharedKeyMatcher;
4078
+ const cached = sharedKeyMatcherCache.get(shared);
4079
+ if (cached) return cached;
4080
+ const keys = Object.keys(shared);
4081
+ const exactKeys = new Set(keys);
4082
+ const commonSubpathKeys = /* @__PURE__ */ new Map();
4083
+ const wildcardKeys = [];
4084
+ let vueKey;
4085
+ for (const key of keys) {
4086
+ const keyBase = key.endsWith("/") ? key.slice(0, -1) : key;
4087
+ if (!vueKey && keyBase === "vue") vueKey = key;
4088
+ if (key.endsWith("/")) wildcardKeys.push({
4089
+ key,
4090
+ base: keyBase
4091
+ });
4092
+ for (const subpath of getCommonSharedSubpaths(keyBase)) if (!commonSubpathKeys.has(subpath)) commonSubpathKeys.set(subpath, key);
4093
+ }
4094
+ const sourceCache = /* @__PURE__ */ new Map();
4095
+ const matcher = { find(source) {
4096
+ if (sourceCache.has(source)) return sourceCache.get(source);
4097
+ let result = exactKeys.has(source) ? source : void 0;
4098
+ if (!result && vueKey) {
4099
+ if (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js") result = vueKey;
4100
+ }
4101
+ if (!result) result = commonSubpathKeys.get(source);
4102
+ if (!result) result = wildcardKeys.find(({ base }) => source === base || source.startsWith(`${base}/`))?.key;
4103
+ sourceCache.set(source, result);
4104
+ return result;
4105
+ } };
4106
+ sharedKeyMatcherCache.set(shared, matcher);
4107
+ return matcher;
3978
4108
  }
3979
4109
  function findSharedKeyForSource(source, shared) {
3980
4110
  const key = findSharedKey(source, shared);
@@ -5036,7 +5166,9 @@ export default __mfShared.default ?? __mfShared;`
5036
5166
  const optimizeDeps = config.optimizeDeps ??= {};
5037
5167
  optimizeDeps.include ??= [];
5038
5168
  optimizeDeps.exclude ??= [];
5039
- if (isLitShare(key) || key === "react" && hasPackageDependency("react-redux", root)) optimizeDeps.exclude.push(key);
5169
+ const shouldBypassOptimizeDep = isLitShare(key) || key === "react" && hasPackageDependency("react-redux", root);
5170
+ if (optimizeDeps.include.includes(key)) optimizeDeps.exclude = optimizeDeps.exclude.filter((dep) => dep !== key);
5171
+ else if (shouldBypassOptimizeDep) optimizeDeps.exclude.push(key);
5040
5172
  else optimizeDeps.include.push(key);
5041
5173
  for (const subpath of getCommonSharedSubpaths(key)) {
5042
5174
  getLoadShareModulePath(subpath, isRolldown);
@@ -5089,7 +5221,7 @@ export default __mfShared.default ?? __mfShared;`
5089
5221
  const SSR_ONLY_PLUGINS = new Set(["@module-federation/vite/ssrEntryLoader"]);
5090
5222
  function loadPluginDts(options) {
5091
5223
  if (options.dts === false) return [];
5092
- return [import("./pluginDts-BaVhdR6i.js").then(({ default: pluginDts }) => pluginDts(options))];
5224
+ return [import("./pluginDts-Cpmdbbr0.js").then((n) => n.n).then(({ default: pluginDts }) => pluginDts(options))];
5093
5225
  }
5094
5226
  function federation(mfUserOptions) {
5095
5227
  if (isTestEnv()) return [];
@@ -5200,7 +5332,7 @@ function federation(mfUserOptions) {
5200
5332
  pluginProxyRemotes_default(options),
5201
5333
  pluginRemoteNamedExports(options),
5202
5334
  ...pluginModuleParseEnd_default((id) => {
5203
- return id.includes(getHostAutoInitImportId()) || id.includes(remoteEntryId) || id.includes(virtualExposesId) || id.includes(getLocalSharedImportMapPath());
5335
+ return id.includes(getHostAutoInitImportId()) || id.includes(remoteEntryId) || id.includes(virtualExposesId) || id.includes(getLocalSharedImportMapPath()) || id.includes("__loadShare__") || id.includes("__prebuild__");
5204
5336
  }, {
5205
5337
  moduleParseTimeout: options.moduleParseTimeout,
5206
5338
  moduleParseIdleTimeout: options.moduleParseIdleTimeout,
@@ -5482,12 +5614,12 @@ function federation(mfUserOptions) {
5482
5614
  const prefixToRoot = chunkDir === "." ? "" : `${normalizePathForImport(path$1.relative(chunkDir, "."))}/`;
5483
5615
  const replacementExpr = prefixToRoot ? `${escapeUnsafeJsSourceChars(JSON.stringify(prefixToRoot))}+$1` : "$1";
5484
5616
  const replacement = `=function($1){return new URL(${replacementExpr},import.meta.url).href}`;
5485
- const replaced = chunk.code.replace(/=\(?(\w+)(?:,\w+)?\)?\s*=>\s*[`"'][./][^`"']*[`"']\s*\+\s*\1/, replacement);
5617
+ const replaced = chunk.code.replace(/=\s*\(?(\w+)(?:,\w+)?\)?\s*=>\s*[`"'][./][^`"']*[`"']\s*\+\s*\1/, replacement);
5486
5618
  if (replaced !== chunk.code) {
5487
5619
  chunk.code = replaced;
5488
5620
  continue;
5489
5621
  }
5490
- chunk.code = chunk.code.replace(/=function\((\w+)(?:,\w+)?\)\{return\s*[`"'][./][^`"']*[`"']\s*\+\s*\1\s*\}/, replacement);
5622
+ chunk.code = chunk.code.replace(/=\s*function\((\w+)(?:,\w+)?\)\s*\{\s*return\s*[`"'][./][^`"']*[`"']\s*\+\s*\1;?\s*\}/, replacement);
5491
5623
  chunk.code = chunk.code.replace(/=function\((\w+)(?:,\w+)?\)\{return new URL\("\.\.\/"\+\1,import\.meta\.url\)\.href\}/, replacement);
5492
5624
  chunk.code = chunk.code.replace(/new URL\("\.\.\/"\+(\w+),import\.meta\.url\)\.href/g, `new URL(${replacementExpr},import.meta.url).href`);
5493
5625
  }