@module-federation/vite 1.16.5 → 1.16.6

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.
@@ -1,7 +1,53 @@
1
1
  import { existsSync, readFileSync, readdirSync } from "fs";
2
2
  import { createRequire } from "module";
3
- import path from "pathe";
4
- import { fileURLToPath } from "url";
3
+ import * as path$1 from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "url";
5
+ //#region src/utils/buildPaths.ts
6
+ /**
7
+ * Rebase an import path for a bootstrap file that moved from root into `dir`.
8
+ *
9
+ * When entryFileNames places entries in a subdirectory (e.g. `static/js/`),
10
+ * the bootstrap file moves there too. Paths that resolved from the HTML root
11
+ * must resolve from the new directory instead.
12
+ *
13
+ * Cases: `/static/js/hostInit.js` → `./hostInit.js` (strip dir prefix)
14
+ * `./src/main.tsx` → `../../src/main.tsx` (climb back up for each dir level)
15
+ * `https://cdn.example.com` → unchanged (absolute URL)
16
+ */
17
+ function rebaseImport(importSrc, dir) {
18
+ if (!dir) return importSrc;
19
+ if (isAbsoluteUrl(importSrc)) return importSrc;
20
+ const normalizedDir = dir.replace(/^\/+|\/+$/g, "");
21
+ if (!normalizedDir) return importSrc;
22
+ const stripDirPrefix = (src, prefix) => {
23
+ if (src === prefix) return "";
24
+ if (src.startsWith(prefix + "/")) return src.slice(prefix.length);
25
+ };
26
+ const absoluteRemainder = stripDirPrefix(importSrc, "/" + normalizedDir);
27
+ if (absoluteRemainder !== void 0) {
28
+ const remainder = absoluteRemainder.replace(/^\/+/, "");
29
+ return remainder ? "./" + remainder : "./";
30
+ }
31
+ const relativeRemainder = stripDirPrefix(importSrc, normalizedDir);
32
+ if (relativeRemainder !== void 0) {
33
+ const remainder = relativeRemainder.replace(/^\/+/, "");
34
+ return remainder ? "./" + remainder : "./";
35
+ }
36
+ const upLevels = normalizedDir.split("/").filter(Boolean).length;
37
+ const prefix = upLevels > 0 ? "../".repeat(upLevels) : "./";
38
+ if (importSrc.startsWith("./")) return prefix + importSrc.slice(2);
39
+ if (importSrc.startsWith("/")) return prefix + importSrc.slice(1);
40
+ return prefix + importSrc;
41
+ }
42
+ function normalizePathForImport(path) {
43
+ return path.replace(/\\/g, "/");
44
+ }
45
+ const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i;
46
+ function isAbsoluteUrl(src) {
47
+ if (/^[a-z]:[\\/]/i.test(src)) return false;
48
+ return EXTERNAL_URL_RE.test(src);
49
+ }
50
+ //#endregion
5
51
  //#region src/utils/logger.ts
6
52
  const MODULE_FEDERATION_LOG_PREFIX = "[Module Federation]";
7
53
  function formatModuleFederationMessage(message) {
@@ -142,7 +188,7 @@ function getInstalledPackageJson(pkg, opts) {
142
188
  try {
143
189
  return {
144
190
  path: packageJsonPath,
145
- dir: path.dirname(packageJsonPath),
191
+ dir: path$1.dirname(packageJsonPath),
146
192
  packageJson: JSON.parse(readFileSync(packageJsonPath, "utf-8"))
147
193
  };
148
194
  } catch {
@@ -151,22 +197,22 @@ function getInstalledPackageJson(pkg, opts) {
151
197
  };
152
198
  const findPackageInPnpmStore = (startDir) => {
153
199
  let currentDir = startDir;
154
- const rootDir = path.parse(currentDir).root;
200
+ const rootDir = path$1.parse(currentDir).root;
155
201
  while (true) {
156
- const pnpmStoreDir = path.join(currentDir, "node_modules", ".pnpm");
202
+ const pnpmStoreDir = path$1.join(currentDir, "node_modules", ".pnpm");
157
203
  if (existsSync(pnpmStoreDir)) try {
158
204
  for (const entry of readdirSync(pnpmStoreDir, { withFileTypes: true })) {
159
205
  if (!entry.isDirectory()) continue;
160
- const candidate = tryReadPackageJson(path.join(pnpmStoreDir, entry.name, "node_modules", packageName, "package.json"));
206
+ const candidate = tryReadPackageJson(path$1.join(pnpmStoreDir, entry.name, "node_modules", packageName, "package.json"));
161
207
  if (candidate?.packageJson.name === packageName) return candidate;
162
208
  }
163
209
  } catch {}
164
210
  if (currentDir === rootDir) break;
165
- currentDir = path.dirname(currentDir);
211
+ currentDir = path$1.dirname(currentDir);
166
212
  }
167
213
  };
168
214
  try {
169
- const projectRequire = createRequire(new URL(`file://${path.join(cwd, "package.json")}`));
215
+ const projectRequire = createRequire(pathToFileURL(path$1.join(cwd, "package.json")));
170
216
  let resolvedPath;
171
217
  if (opts?.fromResolvedEntry) resolvedPath = opts.fromResolvedEntry;
172
218
  else try {
@@ -174,10 +220,10 @@ function getInstalledPackageJson(pkg, opts) {
174
220
  } catch {
175
221
  resolvedPath = projectRequire.resolve(packageName);
176
222
  }
177
- let currentDir = path.dirname(resolvedPath);
178
- const rootDir = path.parse(currentDir).root;
223
+ let currentDir = path$1.dirname(resolvedPath);
224
+ const rootDir = path$1.parse(currentDir).root;
179
225
  while (true) {
180
- const packageJsonPath = path.join(currentDir, "package.json");
226
+ const packageJsonPath = path$1.join(currentDir, "package.json");
181
227
  if (existsSync(packageJsonPath)) {
182
228
  const packageJsonContent = readFileSync(packageJsonPath, "utf-8");
183
229
  try {
@@ -192,16 +238,16 @@ function getInstalledPackageJson(pkg, opts) {
192
238
  }
193
239
  }
194
240
  if (currentDir === rootDir) break;
195
- currentDir = path.dirname(currentDir);
241
+ currentDir = path$1.dirname(currentDir);
196
242
  }
197
243
  } catch {
198
244
  let currentDir = cwd;
199
- const rootDir = path.parse(currentDir).root;
245
+ const rootDir = path$1.parse(currentDir).root;
200
246
  while (true) {
201
- const directCandidate = tryReadPackageJson(path.join(currentDir, "node_modules", packageName, "package.json"));
247
+ const directCandidate = tryReadPackageJson(path$1.join(currentDir, "node_modules", packageName, "package.json"));
202
248
  if (directCandidate?.packageJson.name === packageName) return directCandidate;
203
249
  if (currentDir === rootDir) break;
204
- currentDir = path.dirname(currentDir);
250
+ currentDir = path$1.dirname(currentDir);
205
251
  }
206
252
  return findPackageInPnpmStore(cwd);
207
253
  }
@@ -212,11 +258,11 @@ function getInstalledPackageEntry(pkg, opts) {
212
258
  const cwd = opts?.cwd || getPackageDetectionCwd();
213
259
  const packageName = opts?.packageName || getPackageName(pkg);
214
260
  if (pkg !== packageName && opts?.resolveSubpathWithRequire !== false) try {
215
- return createRequire(new URL(`file://${path.join(cwd, "package.json")}`)).resolve(pkg);
261
+ return createRequire(pathToFileURL(path$1.join(cwd, "package.json"))).resolve(pkg);
216
262
  } catch {}
217
263
  const packageJson = installed.packageJson;
218
264
  const explicitEntry = resolveExportsEntry(getPackageExportsTarget(pkg, packageName, packageJson.exports), opts?.conditions) || (typeof packageJson.module === "string" ? packageJson.module : void 0) || (typeof packageJson.main === "string" ? packageJson.main : void 0) || "index.js";
219
- return path.join(installed.dir, explicitEntry);
265
+ return path$1.join(installed.dir, explicitEntry);
220
266
  }
221
267
  /**
222
268
  * Detect whether the current runtime is Vite 8+ by checking for a Vite version flag
@@ -232,7 +278,7 @@ function isNuxtProjectRoot(root) {
232
278
  let dir = root;
233
279
  for (let i = 0; i < 8; i++) {
234
280
  if (hasPackageDependency("nuxt", dir) || hasPackageDependency("nuxt-nightly", dir)) return true;
235
- const parent = path.dirname(dir);
281
+ const parent = path$1.dirname(dir);
236
282
  if (parent === dir) break;
237
283
  dir = parent;
238
284
  }
@@ -243,7 +289,7 @@ function hasPackageDependency(dependencyName, cwd = packageDetectionCwd || proce
243
289
  const cached = dependencyPresenceCache.get(cacheKey);
244
290
  if (cached !== void 0) return cached;
245
291
  try {
246
- const packageJson = JSON.parse(readFileSync(path.join(cwd, "package.json"), "utf8"));
292
+ const packageJson = JSON.parse(readFileSync(path$1.join(cwd, "package.json"), "utf8"));
247
293
  const hasDependency = [
248
294
  packageJson.dependencies,
249
295
  packageJson.devDependencies,
@@ -258,4 +304,4 @@ function hasPackageDependency(dependencyName, cwd = packageDetectionCwd || proce
258
304
  }
259
305
  }
260
306
  //#endregion
261
- export { getPackageName as a, hasPackageDependency as c, packageNameEncode as d, resolveImportPath as f, mfWarn as g, mfError as h, getPackageDetectionCwd as i, isNuxtProjectRoot as l, createModuleFederationError as m, getInstalledPackageJson as n, getPackageNameFromNodeModulePath as o, setPackageDetectionCwd as p, getIsRolldown as r, getSharedCacheKey as s, getInstalledPackageEntry as t, packageNameDecode as u };
307
+ export { normalizePathForImport as _, getPackageName as a, hasPackageDependency as c, packageNameEncode as d, resolveImportPath as f, mfWarn as g, mfError as h, getPackageDetectionCwd as i, isNuxtProjectRoot as l, createModuleFederationError as m, getInstalledPackageJson as n, getPackageNameFromNodeModulePath as o, setPackageDetectionCwd as p, getIsRolldown as r, getSharedCacheKey as s, getInstalledPackageEntry as t, packageNameDecode as u, rebaseImport as v };
@@ -1,6 +1,6 @@
1
- import { c as hasPackageDependency, f as resolveImportPath, h as mfError, m as createModuleFederationError } from "./packageUtils-CxYRnFwy.js";
1
+ import { _ as normalizePathForImport, c as hasPackageDependency, f as resolveImportPath, h as mfError, m as createModuleFederationError } from "./packageUtils-CYnJFfPP.js";
2
2
  import fs from "fs";
3
- import * as path$1 from "pathe";
3
+ import * as path$1 from "node:path";
4
4
  import { normalizeOptions } from "@module-federation/sdk";
5
5
  import { consumeTypesAPI, generateTypesAPI, isTSProject, normalizeConsumeTypesOptions, normalizeDtsOptions, normalizeGenerateTypesOptions } from "@module-federation/dts-plugin";
6
6
  import { rpc } from "@module-federation/dts-plugin/core";
@@ -57,7 +57,7 @@ const buildDtsModuleFederationConfig = (options) => {
57
57
  };
58
58
  const resolveOutputDir = (config) => {
59
59
  const { outDir } = config.build;
60
- if (path$1.isAbsolute(outDir)) return path$1.relative(config.root, outDir);
60
+ if (path$1.isAbsolute(outDir)) return normalizePathForImport(path$1.relative(config.root, outDir));
61
61
  return outDir;
62
62
  };
63
63
  const ensureRuntimePlugin = (options, pluginId) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.16.5",
3
+ "version": "1.16.6",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -72,15 +72,13 @@
72
72
  "dependencies": {
73
73
  "@module-federation/dts-plugin": "2.5.1",
74
74
  "@module-federation/runtime": "2.5.1",
75
- "@module-federation/sdk": "2.5.1",
76
- "es-module-lexer": "2.1.0",
77
- "estree-walker": "3.0.3",
78
- "pathe": "2.0.3"
75
+ "@module-federation/sdk": "2.5.1"
79
76
  },
80
77
  "devDependencies": {
81
78
  "@playwright/test": "1.58.2",
82
79
  "@types/node": "25.3.3",
83
80
  "husky": "9.1.7",
81
+ "mock-shared-dep": "workspace:*",
84
82
  "oxfmt": "0.36.0",
85
83
  "rollup": "4.47.1",
86
84
  "tsdown": "0.21.0",