@@ -6,7 +6,7 @@ import which from 'which'
66import { resolveBinPathSync } from '@socketsecurity/registry/lib/npm'
77
88import constants from '../constants.mts'
9- import { safeStatsSync } from './fs.mts'
9+ import { isDirectorySync , safeStatsSync } from './fs.mts'
1010import {
1111 filterBySupportedScanFiles ,
1212 globWithGitIgnore ,
@@ -43,26 +43,24 @@ export function findBinPathDetailsSync(binName: string): {
4343 return { name : binName , path : theBinPath , shadowed : shadowIndex !== - 1 }
4444}
4545
46- export function findNpmPathSync ( npmBinPath : string ) : string | undefined {
46+ export function findNpmDirPathSync ( npmBinPath : string ) : string | undefined {
4747 // Lazily access constants.WIN32.
4848 const { WIN32 } = constants
4949 let thePath = npmBinPath
5050 while ( true ) {
5151 const libNmNpmPath = path . join ( thePath , 'lib/node_modules/npm' )
52- // mise puts its npm bin in a path like:
52+ // mise, which uses opaque binaries, puts its npm bin in a path like:
5353 // /Users/SomeUsername/.local/share/mise/installs/node/vX.X.X/bin/npm.
5454 // HOWEVER, the location of the npm install is:
5555 // /Users/SomeUsername/.local/share/mise/installs/node/vX.X.X/lib/node_modules/npm.
5656 if (
5757 // Use existsSync here because statsSync, even with { throwIfNoEntry: false },
5858 // will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
5959 // See https://github.com/nodejs/node/issues/56993.
60- existsSync ( libNmNpmPath ) &&
61- safeStatsSync ( libNmNpmPath ) ?. isDirectory ( )
60+ isDirectorySync ( libNmNpmPath )
6261 ) {
63- thePath = path . join ( libNmNpmPath , 'npm' )
62+ thePath = libNmNpmPath
6463 }
65- const nmPath = path . join ( thePath , 'node_modules' )
6664 if (
6765 // npm bin paths may look like:
6866 // /usr/local/share/npm/bin/npm
@@ -74,8 +72,9 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
7472 // In practically all cases the npm path contains a node_modules folder:
7573 // /usr/local/share/npm/bin/npm/node_modules
7674 // C:\Program Files\nodejs\node_modules
77- existsSync ( nmPath ) &&
78- safeStatsSync ( nmPath ) ?. isDirectory ( ) &&
75+ ( isDirectorySync ( path . join ( thePath , 'node_modules' ) ) ||
76+ // In some bespoke cases the node_modules folder is one level back.
77+ isDirectorySync ( path . join ( thePath , '../node_modules' ) ) ) &&
7978 // Optimistically look for the default location.
8079 ( path . basename ( thePath ) === 'npm' ||
8180 // Chocolatey installs npm bins in the same directory as node bins.
0 commit comments