1
- import fs from 'node:fs/promises '
1
+ import { promises as fs , realpathSync } from 'node:fs'
2
2
import path from 'node:path'
3
3
4
4
import ignore from 'ignore'
5
5
import micromatch from 'micromatch'
6
6
import { glob as tinyGlob } from 'tinyglobby'
7
+ import which from 'which'
7
8
9
+ import constants from '../constants'
8
10
import { directoryPatterns } from './ignore-by-default'
9
11
10
12
import type { SocketYml } from '@socketsecurity/config'
@@ -15,6 +17,8 @@ type GlobWithGitIgnoreOptions = GlobOptions & {
15
17
socketConfig ?: SocketYml | undefined
16
18
}
17
19
20
+ const { shadowBinPath } = constants
21
+
18
22
async function filterGlobResultToSupportedFiles (
19
23
entries : string [ ] ,
20
24
supportedFiles : SocketSdkReturnType < 'getReportSupportedFiles' > [ 'data' ]
@@ -177,6 +181,28 @@ export function findRoot(filepath: string): string | undefined {
177
181
}
178
182
}
179
183
184
+ export async function findBinPathDetails ( binName : string ) : Promise < {
185
+ name : string
186
+ path : string | undefined
187
+ shadowed : boolean
188
+ } > {
189
+ let shadowIndex = - 1
190
+ const bins =
191
+ ( await which ( binName , {
192
+ all : true ,
193
+ nothrow : true
194
+ } ) ) ?? [ ]
195
+ const binPath = bins . find ( ( binPath , i ) => {
196
+ // Skip our bin directory if it's in the front.
197
+ if ( realpathSync ( path . dirname ( binPath ) ) === shadowBinPath ) {
198
+ shadowIndex = i
199
+ return false
200
+ }
201
+ return true
202
+ } )
203
+ return { name : binName , path : binPath , shadowed : shadowIndex !== - 1 }
204
+ }
205
+
180
206
export async function getPackageFiles (
181
207
cwd : string ,
182
208
inputPaths : string [ ] ,
0 commit comments