@module-federation/vite 1.23.7 → 1.23.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.
@@ -279,35 +279,17 @@ function getPackageNameFromNodeModulePath(source) {
279
279
  if (parts[0].startsWith("@")) return parts[1] ? `${parts[0]}/${parts[1]}` : void 0;
280
280
  return parts[0];
281
281
  }
282
- function getSharedCacheKeyParts(input) {
283
- const scope = (Array.isArray(input.scope) ? input.scope[0] : input.scope) || "default";
284
- const id = input.singleton || !input.version ? input.pkg : `${input.pkg}@${input.version}`;
285
- return {
286
- scope,
287
- id,
288
- key: `${scope}:${id}`
289
- };
282
+ function createSharedCacheDescriptor(pkg, singleton, version, scope) {
283
+ const scopeName = (Array.isArray(scope) ? scope[0] : scope) || "default";
284
+ const id = singleton || !version ? pkg : pkg + "@" + version;
285
+ const descriptor = { canonical: scopeName + ":" + id };
286
+ if (scopeName === "default") descriptor.aliases = [id];
287
+ return descriptor;
290
288
  }
291
289
  function getSharedCacheDescriptor(pkg, shareItem) {
292
- const parts = getSharedCacheKeyParts({
293
- pkg: shareItem.shareConfig.request !== void 0 || shareItem.shareConfig.shareKey !== void 0 ? getSharedRuntimeKey(pkg, shareItem) : pkg,
294
- singleton: shareItem.shareConfig.singleton,
295
- version: shareItem.version,
296
- scope: shareItem.scope
297
- });
298
- return {
299
- canonical: parts.key,
300
- ...parts.scope === "default" ? { aliases: [parts.id] } : {}
301
- };
290
+ return createSharedCacheDescriptor(shareItem.shareConfig.request !== void 0 || shareItem.shareConfig.shareKey !== void 0 ? getSharedRuntimeKey(pkg, shareItem) : pkg, shareItem.shareConfig.singleton, shareItem.version, shareItem.scope);
302
291
  }
303
- const sharedCacheHelperCode = `const __mfGetSharedCacheDescriptor = (pkg, singleton, version, scope) => {
304
- const normalizedScope = Array.isArray(scope) ? scope[0] : scope;
305
- const scopeName = normalizedScope || "default";
306
- const id = singleton || !version ? pkg : pkg + "@" + version;
307
- const descriptor = { canonical: scopeName + ":" + id };
308
- if (scopeName === "default") descriptor.aliases = [id];
309
- return descriptor;
310
- };
292
+ const sharedCacheHelperCode = `const __mfGetSharedCacheDescriptor = ${createSharedCacheDescriptor.toString()};
311
293
  const __mfReadSharedCache = (cache, descriptor) => {
312
294
  const value = cache[descriptor.canonical];
313
295
  if (value !== undefined) return value;
@@ -530,7 +512,7 @@ function resolveInstalledPackageJson(pkg, cwd, packageName, opts) {
530
512
  const directCandidate = tryReadPackageJson(path$1.join(dir, "node_modules", packageName, "package.json"), packageName);
531
513
  if (directCandidate) return directCandidate;
532
514
  }
533
- return findPackageInDependents(packageName, cwd) ?? findPackageInPnpmStore(packageName, cwd);
515
+ return findPackageInDependents(packageName, cwd)?.copy ?? findPackageInPnpmStore(packageName, cwd);
534
516
  }
535
517
  function readDirEntries(dir) {
536
518
  try {
@@ -605,12 +587,13 @@ function walkDependents(packageName, cwd, reachedNames) {
605
587
  for (const rootDependencies of rootDependencyGroups) {
606
588
  let level = rootDependencies.map((name) => ({
607
589
  name,
608
- fromDir: cwd
590
+ fromDir: cwd,
591
+ chain: [name]
609
592
  }));
610
593
  while (level.length) {
611
594
  const candidates = [];
612
595
  const nextLevel = [];
613
- for (const { name, fromDir } of level) {
596
+ for (const { name, fromDir, chain } of level) {
614
597
  if (name === packageName) continue;
615
598
  const dependent = findPackageFrom(name, fromDir);
616
599
  if (!dependent || visited.has(dependent.dir)) continue;
@@ -621,17 +604,20 @@ function walkDependents(packageName, cwd, reachedNames) {
621
604
  const copy = findPackageFrom(packageName, dependent.dir);
622
605
  if (copy) candidates.push({
623
606
  copy,
624
- via: name
607
+ via: name,
608
+ dependentDir: dependent.dir,
609
+ chain
625
610
  });
626
611
  }
627
612
  for (const dependency of dependencies) nextLevel.push({
628
613
  name: dependency,
629
- fromDir: dependent.dir
614
+ fromDir: dependent.dir,
615
+ chain: [...chain, dependency]
630
616
  });
631
617
  }
632
618
  if (candidates.length) {
633
619
  warnOnAmbiguousDependents(packageName, candidates);
634
- return candidates[0].copy;
620
+ return candidates[0];
635
621
  }
636
622
  level = nextLevel;
637
623
  }
@@ -804,4 +790,4 @@ function watchFileEvents(watcher, listener) {
804
790
  //#region src/utils/dtsConstants.ts
805
791
  const DEFAULT_PUBLIC_TYPES_FOLDER = "@mf-types";
806
792
  //#endregion
807
- export { supportsCodeSplittingGroupDebugName as C, isReactCoreShare as E, sharedCacheHelperCode as S, REACT_DOM_CLIENT_SHARE as T, packageNameDecode as _, getInstalledPackageEntry as a, resolveModulePath as b, getPackageDetectionCwd as c, getPackageNameFromNodeModulePath as d, getSharedCacheDescriptor as f, isPackageInstalled as g, isPackageExportAvailable as h, getDependencyNames as i, getPackageExportSpecifiersForFile as l, isNuxtProjectRoot as m, formatDevServerHostForOrigin as n, getInstalledPackageJson as o, hasPackageDependency as p, watchFileEvents as r, getIsRolldown as s, DEFAULT_PUBLIC_TYPES_FOLDER as t, getPackageName as u, packageNameEncode as v, REACT_CLIENT_INTERNALS_KEY as w, setPackageDetectionCwd as x, resolveImportPath as y };
793
+ export { sharedCacheHelperCode as C, isReactCoreShare as D, REACT_DOM_CLIENT_SHARE as E, setPackageDetectionCwd as S, REACT_CLIENT_INTERNALS_KEY as T, isPackageInstalled as _, getDependencyNames as a, resolveImportPath as b, getIsRolldown as c, getPackageName as d, getPackageNameFromNodeModulePath as f, isPackageExportAvailable as g, isNuxtProjectRoot as h, findPackageInDependents as i, getPackageDetectionCwd as l, hasPackageDependency as m, formatDevServerHostForOrigin as n, getInstalledPackageEntry as o, getSharedCacheDescriptor as p, watchFileEvents as r, getInstalledPackageJson as s, DEFAULT_PUBLIC_TYPES_FOLDER as t, getPackageExportSpecifiersForFile as u, packageNameDecode as v, supportsCodeSplittingGroupDebugName as w, resolveModulePath as x, packageNameEncode as y };
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as CodeRewriter, c as isAbsoluteUrl, d as rebaseImport, f as resolveHashPlaceholderFileName, i as createCodePositionMap, l as isHttpUrl, o as createSourceMap, r as mfWarn, t as createModuleFederationError, u as normalizePathForImport } from "./logger-D67aJYOe.js";
2
2
  import { _ as removeTrailingSlash, a as matchesSharedSource, b as stripViteFsPrefix, 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 resolvePublicPath, x as toRelativeImport, y as stripQueryAndHash } from "./sharedKeyMatcher-C04bVN1q.js";
3
- import { C as supportsCodeSplittingGroupDebugName, E as isReactCoreShare, S as sharedCacheHelperCode, T as REACT_DOM_CLIENT_SHARE, _ as packageNameDecode, a as getInstalledPackageEntry, b as resolveModulePath, c as getPackageDetectionCwd, d as getPackageNameFromNodeModulePath, f as getSharedCacheDescriptor, g as isPackageInstalled, h as isPackageExportAvailable, i as getDependencyNames, l as getPackageExportSpecifiersForFile, m as isNuxtProjectRoot, n as formatDevServerHostForOrigin, o as getInstalledPackageJson, p as hasPackageDependency, r as watchFileEvents, s as getIsRolldown, u as getPackageName, v as packageNameEncode, w as REACT_CLIENT_INTERNALS_KEY, x as setPackageDetectionCwd, y as resolveImportPath } from "./dtsConstants-CDuC8Bb7.js";
3
+ import { C as sharedCacheHelperCode, D as isReactCoreShare, E as REACT_DOM_CLIENT_SHARE, S as setPackageDetectionCwd, T as REACT_CLIENT_INTERNALS_KEY, _ as isPackageInstalled, a as getDependencyNames, b as resolveImportPath, c as getIsRolldown, d as getPackageName, f as getPackageNameFromNodeModulePath, g as isPackageExportAvailable, h as isNuxtProjectRoot, i as findPackageInDependents, l as getPackageDetectionCwd, m as hasPackageDependency, n as formatDevServerHostForOrigin, o as getInstalledPackageEntry, p as getSharedCacheDescriptor, r as watchFileEvents, s as getInstalledPackageJson, u as getPackageExportSpecifiersForFile, v as packageNameDecode, w as supportsCodeSplittingGroupDebugName, x as resolveModulePath, y as packageNameEncode } from "./dtsConstants-286VtFnC.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";
@@ -1669,10 +1669,13 @@ function getRuntimeRemoteAlias(alias, options) {
1669
1669
  return `${getFederationScopeKey(options)}__${alias}`;
1670
1670
  }
1671
1671
  function getSsrRuntimeRemotes(remotes, options) {
1672
- return Object.entries(remotes).map(([name, item]) => ({
1673
- name: getRuntimeRemoteAlias(name, options),
1672
+ return Object.entries(remotes).map(([alias, item]) => ({
1673
+ alias,
1674
+ entryGlobalName: item.entryGlobalName,
1675
+ name: getRuntimeRemoteAlias(alias, options),
1674
1676
  entry: item.entry,
1675
- type: item.type ?? "module"
1677
+ type: item.type ?? "module",
1678
+ shareScope: item.shareScope ?? "default"
1676
1679
  }));
1677
1680
  }
1678
1681
  function getRuntimeInitGlobalKey(ownerImportId) {
@@ -8372,7 +8375,7 @@ function ${helperName}(names) {
8372
8375
  }
8373
8376
  //#endregion
8374
8377
  //#region package.json
8375
- var version$1 = "1.23.7";
8378
+ var version$1 = "1.23.8";
8376
8379
  //#endregion
8377
8380
  //#region src/virtualModules/virtualExposesSSR.ts
8378
8381
  /**
@@ -10313,6 +10316,8 @@ function proxySharedModule(options) {
10313
10316
  let devServer;
10314
10317
  const materializedLoadShareSources = /* @__PURE__ */ new Set();
10315
10318
  const emittedTreeShakingProviders = /* @__PURE__ */ new Set();
10319
+ const concreteShareSources = /* @__PURE__ */ new Map();
10320
+ let concreteShareSourcesSize = -1;
10316
10321
  const hasAnalyzableShares = Object.values(shared).some((share) => shouldAnalyzeSharedExports(share));
10317
10322
  const getEnvironmentConfig = (context) => context.environment?.config;
10318
10323
  const getEnvironmentConditions = (context) => getEnvironmentConfig(context)?.resolve?.conditions;
@@ -10550,6 +10555,23 @@ function proxySharedModule(options) {
10550
10555
  name: "proxyPreBuildShared:resolve-prebuild",
10551
10556
  enforce: "pre",
10552
10557
  async resolveId(source, importer) {
10558
+ if (_command === "serve" && path$1.isAbsolute(source)) {
10559
+ const usedShares = getUsedShares(federationOptions);
10560
+ if (concreteShareSourcesSize !== usedShares.size) {
10561
+ concreteShareSourcesSize = usedShares.size;
10562
+ concreteShareSources.clear();
10563
+ for (const used of usedShares) {
10564
+ const concrete = getConcreteSharedImportSource(used);
10565
+ if (concrete) concreteShareSources.set(concrete.replaceAll("\\", "/"), used);
10566
+ }
10567
+ }
10568
+ const share = concreteShareSources.get(source.replaceAll("\\", "/"));
10569
+ if (!share) return;
10570
+ const dependent = findPackageInDependents(getPackageName(share), getPackageDetectionCwd());
10571
+ if (!dependent) return;
10572
+ const dependentPackageJson = path$1.join(dependent.dependentDir, "package.json");
10573
+ return resolveInternally(this, share, dependentPackageJson);
10574
+ }
10553
10575
  if (!source.includes("__prebuild__")) return;
10554
10576
  if (source.startsWith(".")) return;
10555
10577
  const pkgName = assertModuleFound(PREBUILD_TAG, source).name;
@@ -11455,6 +11477,7 @@ function pluginSsrRuntimeInit(options) {
11455
11477
  if (isOwnedHostAutoInitId(id, options)) {
11456
11478
  const pluginImports = options.runtimePlugins.map((plugin, index) => `import plugin${index} from ${toSafeJsLiteral(getRuntimePluginSpecifier(plugin))};`).join("\n");
11457
11479
  const plugins = options.runtimePlugins.map((plugin, index) => `plugin${index}(${Array.isArray(plugin) ? serializeRuntimeOptions(plugin[1]) : ""})`).join(",");
11480
+ const fallbackRemotes = toSafeJsLiteral(getSsrRuntimeRemotes(options.remotes, options));
11458
11481
  return {
11459
11482
  code: `
11460
11483
  import { init } from ${toSafeJsLiteral(options.implementation)};
@@ -11466,7 +11489,8 @@ function pluginSsrRuntimeInit(options) {
11466
11489
  // names aliased to their configured names, and the runtime resolves an id
11467
11490
  // against the first remote whose name or alias matches. Drop the alias once the
11468
11491
  // application registers a remote under that name or alias, so its entry wins.
11469
- const bootstrapRemoteNames = new Set(usedRemotes.map((remote) => remote.name));
11492
+ const bootstrapRemotes = Array.isArray(usedRemotes) ? usedRemotes : ${fallbackRemotes};
11493
+ const bootstrapRemoteNames = new Set(bootstrapRemotes.map((remote) => remote.name));
11470
11494
  const applicationRemotePlugin = {
11471
11495
  name: 'vite-ssr-application-remote-plugin',
11472
11496
  beforeRegisterRemote(args) {
@@ -11485,7 +11509,7 @@ function pluginSsrRuntimeInit(options) {
11485
11509
  };
11486
11510
  const runtime = init({
11487
11511
  name: ${toSafeJsLiteral(options.name)},
11488
- remotes: usedRemotes,
11512
+ remotes: bootstrapRemotes,
11489
11513
  shared: usedShared,
11490
11514
  plugins: [applicationRemotePlugin, ${plugins}],
11491
11515
  shareStrategy: ${toSafeJsLiteral(options.shareStrategy)},
@@ -12027,6 +12051,11 @@ function canResolveSharedSubpath(subpath, projectRoot) {
12027
12051
  return false;
12028
12052
  }
12029
12053
  }
12054
+ function getSharedIncludeEntry(subpath, projectRoot) {
12055
+ if (canResolveSharedSubpath(subpath, projectRoot)) return subpath;
12056
+ const dependent = findPackageInDependents(getPackageName(subpath), projectRoot);
12057
+ if (dependent && canResolveSharedSubpath(subpath, dependent.dependentDir)) return [...dependent.chain, subpath].join(" > ");
12058
+ }
12030
12059
  const VITE_DEV_IMPORT_CONDITIONS = /* @__PURE__ */ new Set([
12031
12060
  "browser",
12032
12061
  "development",
@@ -12373,7 +12402,8 @@ export default __mfShared.default ?? __mfShared;`
12373
12402
  optimizeDeps.exclude ??= [];
12374
12403
  for (const subpath of getCommonSharedSubpaths(request)) {
12375
12404
  writePreBuildLibPath(subpath, shareItem, options);
12376
- if (canResolveSharedSubpath(subpath, root)) optimizeDeps.include.push(subpath);
12405
+ const includeEntry = getSharedIncludeEntry(subpath, root);
12406
+ if (includeEntry) optimizeDeps.include.push(includeEntry);
12377
12407
  else optimizeDeps.exclude.push(subpath);
12378
12408
  }
12379
12409
  }
@@ -12391,18 +12421,18 @@ export default __mfShared.default ?? __mfShared;`
12391
12421
  const optimizeDeps = config.optimizeDeps ??= {};
12392
12422
  optimizeDeps.include ??= [];
12393
12423
  optimizeDeps.exclude ??= [];
12394
- const shouldBypassOptimizeDep = isLitShare(runtimeKey) || !canResolveSharedSubpath(runtimeKey, root);
12424
+ const includeEntry = isLitShare(runtimeKey) ? void 0 : getSharedIncludeEntry(runtimeKey, root);
12395
12425
  if (optimizeDeps.include.includes(runtimeKey)) optimizeDeps.exclude = optimizeDeps.exclude.filter((dep) => dep !== runtimeKey);
12396
- else if (shouldBypassOptimizeDep || optimizeDeps.exclude.includes(runtimeKey)) optimizeDeps.exclude.push(runtimeKey);
12397
- else optimizeDeps.include.push(runtimeKey);
12426
+ else if (!includeEntry || optimizeDeps.exclude.includes(runtimeKey)) optimizeDeps.exclude.push(runtimeKey);
12427
+ else optimizeDeps.include.push(includeEntry);
12398
12428
  const commonSubpaths = shareItem.shareConfig.request === void 0 && shareItem.shareConfig.shareKey === void 0 ? getCommonSharedSubpaths(runtimeKey) : [];
12399
12429
  for (const subpath of commonSubpaths) {
12400
- const canResolveSubpath = canResolveSharedSubpath(subpath, root);
12430
+ const subpathIncludeEntry = getSharedIncludeEntry(subpath, root);
12401
12431
  if ([
12402
12432
  "react/compiler-runtime",
12403
12433
  "react-dom/client",
12404
12434
  "react-dom/profiling"
12405
- ].includes(subpath) && !canResolveSubpath) {
12435
+ ].includes(subpath) && !subpathIncludeEntry) {
12406
12436
  optimizeDeps.exclude.push(subpath);
12407
12437
  continue;
12408
12438
  }
@@ -12410,9 +12440,9 @@ export default __mfShared.default ?? __mfShared;`
12410
12440
  writeLoadShareModule(subpath, shareItem, _command, options);
12411
12441
  writePreBuildLibPath(subpath, shareItem, options);
12412
12442
  addConfiguredShare(subpath, options);
12413
- if (canResolveSubpath) {
12414
- optimizeDeps.include.push(subpath);
12415
- if (runtimeKey === "react-dom") optimizeDeps.include.push(`${runtimeKey} > ${subpath}`);
12443
+ if (subpathIncludeEntry) {
12444
+ optimizeDeps.include.push(subpathIncludeEntry);
12445
+ if (runtimeKey === "react-dom" && includeEntry) optimizeDeps.include.push(`${includeEntry} > ${subpath}`);
12416
12446
  } else optimizeDeps.exclude.push(subpath);
12417
12447
  }
12418
12448
  }
@@ -12500,7 +12530,7 @@ function withoutDynamicRemoteTypeHints(options) {
12500
12530
  }
12501
12531
  function loadPluginDts(options) {
12502
12532
  if (options.dts === false) return [];
12503
- return [import("./pluginDts-rZMRTCTz.js").then(({ default: pluginDts }) => pluginDts(options))];
12533
+ return [import("./pluginDts-DvTJxjaE.js").then(({ default: pluginDts }) => pluginDts(options))];
12504
12534
  }
12505
12535
  const INJECT_EXTERNAL_RUNTIME_CORE_PLUGIN = "@module-federation/vite/injectExternalRuntimeCorePlugin";
12506
12536
  function isInjectExternalRuntimeCorePlugin(specifier) {
@@ -1,5 +1,5 @@
1
1
  import { l as isHttpUrl, n as mfError, t as createModuleFederationError, u as normalizePathForImport } from "./logger-D67aJYOe.js";
2
- import { p as hasPackageDependency, r as watchFileEvents, y as resolveImportPath } from "./dtsConstants-CDuC8Bb7.js";
2
+ import { b as resolveImportPath, m as hasPackageDependency, r as watchFileEvents } from "./dtsConstants-286VtFnC.js";
3
3
  import fs from "fs";
4
4
  import * as path$1 from "node:path";
5
5
  import { normalizeOptions } from "@module-federation/sdk";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.23.7",
3
+ "version": "1.23.8",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",