@@ -8,15 +8,13 @@ import { resolveBinPathSync } from '@socketsecurity/registry/lib/npm'
88import constants from '../constants.mts'
99import { safeStatsSync } from './fs.mts'
1010import {
11- filterGlobResultToSupportedFiles ,
11+ filterReportSupportedFiles ,
1212 globWithGitIgnore ,
1313 pathsToGlobPatterns ,
1414} from './glob.mts'
1515
1616import type { SocketYml } from '@socketsecurity/config'
17- import type { SocketSdkReturnType } from '@socketsecurity/sdk'
18-
19- const { NODE_MODULES , NPM , shadowBinPath } = constants
17+ import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
2018
2119export function findBinPathDetailsSync ( binName : string ) : {
2220 name : string
@@ -28,6 +26,8 @@ export function findBinPathDetailsSync(binName: string): {
2826 all : true ,
2927 nothrow : true ,
3028 } ) ?? [ ]
29+ // Lazily access constants.shadowBinPath.
30+ const { shadowBinPath } = constants
3131 let shadowIndex = - 1
3232 let theBinPath : string | undefined
3333 for ( let i = 0 , { length } = binPaths ; i < length ; i += 1 ) {
@@ -48,7 +48,7 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
4848 const { WIN32 } = constants
4949 let thePath = npmBinPath
5050 while ( true ) {
51- const libNmNpmPath = path . join ( thePath , 'lib' , NODE_MODULES , NPM )
51+ const libNmNpmPath = path . join ( thePath , 'lib/node_modules/npm' )
5252 // mise 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:
@@ -60,9 +60,9 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
6060 existsSync ( libNmNpmPath ) &&
6161 safeStatsSync ( libNmNpmPath ) ?. isDirectory ( )
6262 ) {
63- thePath = path . join ( libNmNpmPath , NPM )
63+ thePath = path . join ( libNmNpmPath , 'npm' )
6464 }
65- const nmPath = path . join ( thePath , NODE_MODULES )
65+ const nmPath = path . join ( thePath , 'node_modules' )
6666 if (
6767 // npm bin paths may look like:
6868 // /usr/local/share/npm/bin/npm
@@ -77,9 +77,9 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
7777 existsSync ( nmPath ) &&
7878 safeStatsSync ( nmPath ) ?. isDirectory ( ) &&
7979 // Optimistically look for the default location.
80- ( path . basename ( thePath ) === NPM ||
80+ ( path . basename ( thePath ) === 'npm' ||
8181 // Chocolatey installs npm bins in the same directory as node bins.
82- ( WIN32 && existsSync ( path . join ( thePath , ` ${ NPM } .cmd` ) ) ) )
82+ ( WIN32 && existsSync ( path . join ( thePath , 'npm .cmd' ) ) ) )
8383 ) {
8484 return thePath
8585 }
@@ -98,16 +98,16 @@ export type PackageFilesForScanOptions = {
9898
9999export async function getPackageFilesForScan (
100100 inputPaths : string [ ] ,
101- supportedFiles : SocketSdkReturnType < 'getReportSupportedFiles' > [ 'data' ] ,
101+ supportedFiles : SocketSdkSuccessResult < 'getReportSupportedFiles' > [ 'data' ] ,
102102 options ?: PackageFilesForScanOptions | undefined ,
103103) : Promise < string [ ] > {
104104 const { config : socketConfig , cwd = process . cwd ( ) } = {
105105 __proto__ : null ,
106106 ...options ,
107107 } as PackageFilesForScanOptions
108- const entries = await globWithGitIgnore ( pathsToGlobPatterns ( inputPaths ) , {
108+ const filepaths = await globWithGitIgnore ( pathsToGlobPatterns ( inputPaths ) , {
109109 cwd,
110110 socketConfig,
111111 } )
112- return await filterGlobResultToSupportedFiles ( entries , supportedFiles )
112+ return filterReportSupportedFiles ( filepaths , supportedFiles )
113113}
0 commit comments