Skip to content

Commit 36075a2

Browse files
committed
fix(security): use which from @socketsecurity/lib/bin
Imports were resolving to the external 'which' npm package which isn't a dep here, breaking 'pnpm run security'. Switch to socket-lib's which (already available via catalog).
1 parent 201f9fc commit 36075a2

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

scripts/security.mts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* downloads + verifies the pinned binary via the setup-security-tools
1515
* hook) and skips that scan rather than failing the entire run.
1616
*
17-
* Cross-platform: uses `which` from npm for binary discovery (handles
18-
* Windows .exe/.cmd resolution) and `spawn` from
17+
* Cross-platform: uses `which` from `@socketsecurity/lib/bin` for
18+
* binary discovery (handles Windows .exe/.cmd resolution; returns null
19+
* rather than throwing on miss) and `spawn` from
1920
* `@socketsecurity/lib/spawn` for proper async lifecycle.
2021
*
2122
* Wired in via `package.json`:
@@ -28,21 +29,17 @@
2829

2930
import process from 'node:process'
3031

31-
import which from 'which'
32-
32+
import { which } from '@socketsecurity/lib/bin'
3333
import { WIN32 } from '@socketsecurity/lib/constants/platform'
3434
import { getDefaultLogger } from '@socketsecurity/lib/logger'
3535
import { spawn } from '@socketsecurity/lib/spawn'
3636

3737
const logger = getDefaultLogger()
3838

3939
async function hasExecutable(name: string): Promise<boolean> {
40-
try {
41-
await which(name)
42-
return true
43-
} catch {
44-
return false
45-
}
40+
// socket-lib's `which` returns null when the binary isn't on PATH
41+
// (no throw), so a simple truthy check suffices.
42+
return Boolean(await which(name))
4643
}
4744

4845
async function runTool(command: string, args: string[]): Promise<number> {

0 commit comments

Comments
 (0)