@module-federation/vite 1.22.0 → 1.22.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 CHANGED
@@ -389,7 +389,7 @@ The `externalRuntime` rewrite applies to the browser remote graph; SSR remote en
389
389
 
390
390
  Do not set `build.rollupOptions.output.codeSplitting` or
391
391
  `build.rolldownOptions.output.codeSplitting` to `false` — it will be **ignored** (with a warning).
392
- Module Federation requires chunk splitting so `runtimeInitStatus` and deferred `loadShare` wrappers stay isolated for correct bootstrap order. Eager `loadShare` wrappers are coalesced into one `loadShare-eager` chunk on Vite 8+ to reduce startup requests.
392
+ Module Federation requires chunk splitting so `runtimeInitStatus` and deferred `loadShare` wrappers stay isolated for correct bootstrap order. Eager `loadShare` wrappers are coalesced into one `loadShare-eager` chunk to reduce startup requests, on both Rolldown (Vite 8+) and Rollup (Vite 5–7).
393
393
 
394
394
  ### `codeSplitting.groups` (Vite 8+ / Rolldown)
395
395
 
@@ -1,3 +1,4 @@
1
+ import { l as getNodeModulesSuffix } from "./sharedKeyMatcher-BRzBCbuR.js";
1
2
  import { existsSync, readFileSync, readdirSync } from "fs";
2
3
  import { createRequire } from "module";
3
4
  import * as path$1 from "node:path";
@@ -129,6 +130,20 @@ function getPackageExportsTarget(pkg, packageName, exportsField) {
129
130
  if (subpath !== ".") return matchExportsSubpath(record, subpath);
130
131
  return record["."] ?? (!Object.keys(record).some((key) => key.startsWith(".")) ? record : void 0);
131
132
  }
133
+ /** Whether `pkg` can be located from `opts.cwd` (or the detection cwd). Aliased or non-hoisted packages may still resolve through Vite. */
134
+ function isPackageInstalled(pkg, opts = {}) {
135
+ return getInstalledPackageJson(getPackageName(pkg), opts) !== void 0;
136
+ }
137
+ /**
138
+ * Whether the installed package's `exports` field permits `pkg`. Lenient when the package cannot
139
+ * be found or has no `exports`: callers that need a hard "is installed" gate use `isPackageInstalled`.
140
+ */
141
+ function isPackageExportAvailable(pkg, opts = {}) {
142
+ const packageName = getPackageName(pkg);
143
+ const installed = getInstalledPackageJson(packageName, opts);
144
+ if (installed?.packageJson.exports == null) return true;
145
+ return resolveExportsEntry(getPackageExportsTarget(pkg, packageName, installed.packageJson.exports), opts.conditions) !== void 0;
146
+ }
132
147
  /**
133
148
  * Escaping rules:
134
149
  * Convert using the format __${mapping}__, where _ and $ are not allowed in npm package names but can be used in variable names.
@@ -180,10 +195,9 @@ function getPackageName(packageString) {
180
195
  return match ? match[0] : packageString;
181
196
  }
182
197
  function getPackageNameFromNodeModulePath(source) {
183
- const normalized = source.replace(/\\/g, "/");
184
- const nodeModulesIndex = normalized.lastIndexOf("/node_modules/");
185
- if (nodeModulesIndex < 0) return;
186
- const parts = normalized.slice(nodeModulesIndex + 14).split("/");
198
+ const suffix = getNodeModulesSuffix(source);
199
+ if (!suffix) return;
200
+ const parts = suffix.split("/");
187
201
  if (!parts[0]) return;
188
202
  if (parts[0].startsWith("@")) return parts[1] ? `${parts[0]}/${parts[1]}` : void 0;
189
203
  return parts[0];
@@ -499,4 +513,4 @@ function hasPackageDependency(dependencyName, cwd = packageDetectionCwd || proce
499
513
  //#region src/utils/dtsConstants.ts
500
514
  const DEFAULT_PUBLIC_TYPES_FOLDER = "@mf-types";
501
515
  //#endregion
502
- export { mfError as _, getPackageDetectionCwd as a, getSharedCacheDescriptor as c, packageNameDecode as d, packageNameEncode as f, createModuleFederationError as g, sharedCacheHelperCode as h, getIsRolldown as i, hasPackageDependency as l, setPackageDetectionCwd as m, getInstalledPackageEntry as n, getPackageName as o, resolveImportPath as p, getInstalledPackageJson as r, getPackageNameFromNodeModulePath as s, DEFAULT_PUBLIC_TYPES_FOLDER as t, isNuxtProjectRoot as u, mfWarn as v };
516
+ export { sharedCacheHelperCode as _, getPackageDetectionCwd as a, mfWarn as b, getSharedCacheDescriptor as c, isPackageExportAvailable as d, isPackageInstalled as f, setPackageDetectionCwd as g, resolveImportPath as h, getIsRolldown as i, hasPackageDependency as l, packageNameEncode as m, getInstalledPackageEntry as n, getPackageName as o, packageNameDecode as p, getInstalledPackageJson as r, getPackageNameFromNodeModulePath as s, DEFAULT_PUBLIC_TYPES_FOLDER as t, isNuxtProjectRoot as u, createModuleFederationError as v, mfError as y };