Skip to content

Commit 10eb00b

Browse files
committed
fix(path): add Windows validation for Unix-style paths in findNpmDirPathSync
On Windows, Unix-style paths starting with / are not valid and will fail path operations. Add early return to prevent attempting to resolve these invalid paths. This defensive check aligns with the test expectations where Unix paths return undefined on Windows platforms. Also updated path examples in comments to use environment variables instead of hardcoded usernames.
1 parent 96df945 commit 10eb00b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/cli/src/utils/fs/path-resolve.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export function findBinPathDetailsSync(binName: string): {
5050
}
5151

5252
export function findNpmDirPathSync(npmBinPath: string): string | undefined {
53+
// On Windows, Unix-style paths (starting with /) are not valid.
54+
if (WIN32 && npmBinPath.startsWith('/')) {
55+
return undefined
56+
}
5357
const MAX_ITERATIONS = 100
5458
let thePath = npmBinPath
5559
let iterations = 0
@@ -79,8 +83,8 @@ export function findNpmDirPathSync(npmBinPath: string): string | undefined {
7983
if (
8084
// npm bin paths may look like:
8185
// /usr/local/share/npm/bin/npm
82-
// /Users/SomeUsername/.nvm/versions/node/vX.X.X/bin/npm
83-
// C:\Users\SomeUsername\AppData\Roaming\npm\bin\npm.cmd
86+
// ~/.nvm/versions/node/vX.X.X/bin/npm
87+
// %USERPROFILE%\AppData\Roaming\npm\bin\npm.cmd
8488
// OR
8589
// C:\Program Files\nodejs\npm.cmd
8690
//

0 commit comments

Comments
 (0)