Skip to content

Commit 7952751

Browse files
authored
fix(cli): import local versions module via file URL (#2749)
## Summary Fix loading tool versions from the locally installed `vite-plus` package by converting the generated `dist/versions.js` filesystem path to a `file://` URL before passing it to dynamic `import()`. ## Why Dynamic `import()` expects a valid module specifier. Passing an absolute filesystem path directly is not portable, especially for Windows drive-letter paths such as `C:\...`, which may be interpreted incorrectly by Node's ESM loader. Using `pathToFileURL()` produces a valid file URL and allows the generated versions module to be imported consistently across platforms. ## Changes * Build the path to `dist/versions.js` with `path.join()` * Convert the filesystem path with `pathToFileURL()` * Import the generated versions module using the resulting `file://` URL 🤖 Generated with Codex
1 parent ed9cdb1 commit 7952751

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"devDependencies": {
3+
"vite-plus": "*"
4+
}
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[[case]]
2+
name = "command_version_local_tools"
3+
vp = "local"
4+
comment = "Resolve bundled tool versions from the local vite-plus package."
5+
steps = [
6+
["vp", "-V"],
7+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# command_version_local_tools
2+
3+
Resolve bundled tool versions from the local vite-plus package.
4+
5+
## `vp -V`
6+
7+
```
8+
VITE+ - The Unified Toolchain for the Web
9+
10+
vp <version>
11+
12+
Local vite-plus:
13+
vite-plus <version>
14+
15+
Tools:
16+
vite <version>
17+
rolldown <version>
18+
vitest <version>
19+
oxfmt <version>
20+
oxlint <version>
21+
oxlint-tsgolint <version>
22+
tsdown <version>
23+
```

packages/cli/src/version.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3+
import { pathToFileURL } from 'node:url';
34

45
import cliPkg from '../package.json' with { type: 'json' };
56
import { VITE_PLUS_NAME } from './utils/constants.ts';
@@ -66,7 +67,8 @@ function isVitePlusDeclaredInAncestors(cwd: string): boolean {
6667
*/
6768
async function resolveToolVersions(localPackagePath: string): Promise<Record<string, string>> {
6869
try {
69-
const mod = await import(`${localPackagePath}/dist/versions.js`);
70+
const file = path.join(localPackagePath, 'dist', 'versions.js');
71+
const mod = await import(pathToFileURL(file).href);
7072
if (mod.versions && typeof mod.versions === 'object') {
7173
return mod.versions as Record<string, string>;
7274
}

0 commit comments

Comments
 (0)