@@ -61,6 +61,12 @@ export function findNpmDirPathSync(npmBinPath: string): string | undefined {
61
61
) {
62
62
thePath = libNmNpmPath
63
63
}
64
+ const hasSameLevelNmPath = isDirectorySync (
65
+ path . join ( thePath , 'node_modules' ) ,
66
+ )
67
+ const hasOneBackNmPath =
68
+ ! hasSameLevelNmPath &&
69
+ isDirectorySync ( path . join ( thePath , '../node_modules' ) )
64
70
if (
65
71
// npm bin paths may look like:
66
72
// /usr/local/share/npm/bin/npm
@@ -72,15 +78,15 @@ export function findNpmDirPathSync(npmBinPath: string): string | undefined {
72
78
// In practically all cases the npm path contains a node_modules folder:
73
79
// /usr/local/share/npm/bin/npm/node_modules
74
80
// C:\Program Files\nodejs\node_modules
75
- ( isDirectorySync ( path . join ( thePath , 'node_modules' ) ) ||
81
+ ( hasSameLevelNmPath ||
76
82
// In some bespoke cases the node_modules folder is one level back.
77
- isDirectorySync ( path . join ( thePath , '../node_modules' ) ) ) &&
83
+ hasOneBackNmPath ) &&
78
84
// Optimistically look for the default location.
79
85
( path . basename ( thePath ) === 'npm' ||
80
86
// Chocolatey installs npm bins in the same directory as node bins.
81
87
( WIN32 && existsSync ( path . join ( thePath , 'npm.cmd' ) ) ) )
82
88
) {
83
- return thePath
89
+ return hasOneBackNmPath ? path . dirname ( thePath ) : thePath
84
90
}
85
91
const parent = path . dirname ( thePath )
86
92
if ( parent === thePath ) {
0 commit comments