1- import { existsSync , promises as fs , realpathSync , statSync } from 'node:fs'
1+ import { existsSync , promises as fs , statSync } from 'node:fs'
22import path from 'node:path'
33import process from 'node:process'
44
@@ -8,6 +8,7 @@ import { glob as tinyGlob } from 'tinyglobby'
88import which from 'which'
99
1010import { debugLog } from '@socketsecurity/registry/lib/debug'
11+ import { resolveBinPath } from '@socketsecurity/registry/lib/npm'
1112
1213import { directoryPatterns } from './ignore-by-default'
1314import constants from '../constants'
@@ -179,27 +180,29 @@ export function findBinPathDetailsSync(binName: string): {
179180 path : string | undefined
180181 shadowed : boolean
181182} {
182- let shadowIndex = - 1
183- const bins =
183+ const binPaths =
184184 which . sync ( binName , {
185185 all : true ,
186186 nothrow : true
187187 } ) ?? [ ]
188- let binPath : string | undefined
189- for ( let i = 0 , { length } = bins ; i < length ; i += 1 ) {
190- const bin = realpathSync . native ( bins [ i ] ! )
188+ let shadowIndex = - 1
189+ let theBinPath : string | undefined
190+ for ( let i = 0 , { length } = binPaths ; i < length ; i += 1 ) {
191+ const binPath = binPaths [ i ] !
191192 // Skip our bin directory if it's in the front.
192- if ( path . dirname ( bin ) === shadowBinPath ) {
193+ if ( path . dirname ( binPath ) === shadowBinPath ) {
193194 shadowIndex = i
194195 } else {
195- binPath = bin
196+ theBinPath = resolveBinPath ( binPath )
196197 break
197198 }
198199 }
199- return { name : binName , path : binPath , shadowed : shadowIndex !== - 1 }
200+ return { name : binName , path : theBinPath , shadowed : shadowIndex !== - 1 }
200201}
201202
202203export function findNpmPathSync ( npmBinPath : string ) : string | undefined {
204+ // Lazily access constants.WIN32.
205+ const { WIN32 } = constants
203206 let thePath = npmBinPath
204207 while ( true ) {
205208 const nmPath = path . join ( thePath , NODE_MODULES )
@@ -223,8 +226,7 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
223226 // Optimistically look for the default location.
224227 ( path . basename ( thePath ) === NPM ||
225228 // Chocolatey installs npm bins in the same directory as node bins.
226- // Lazily access constants.WIN32.
227- ( constants . WIN32 && existsSync ( path . join ( thePath , `${ NPM } .cmd` ) ) ) )
229+ ( WIN32 && existsSync ( path . join ( thePath , `${ NPM } .cmd` ) ) ) )
228230 ) {
229231 return thePath
230232 }
0 commit comments