Skip to content

Commit 2d5522b

Browse files
committed
fix: Add defensive check for whichBinSync return value
The published version of @socketsecurity/registry may return a string when only one result is found even with all: true. This defensive check handles both cases to ensure compatibility with the current published version and future versions that properly return an array.
1 parent b479788 commit 2d5522b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/utils/path-resolve.mts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { existsSync } from 'node:fs'
22
import path from 'node:path'
33

4-
import { resolveBinPathSync, whichBinSync } from '@socketsecurity/registry/lib/bin'
4+
import {
5+
resolveBinPathSync,
6+
whichBinSync,
7+
} from '@socketsecurity/registry/lib/bin'
58
import { isDirSync } from '@socketsecurity/registry/lib/fs'
69

710
import constants, { NODE_MODULES, NPM } from '../constants.mts'
@@ -19,11 +22,18 @@ export function findBinPathDetailsSync(binName: string): {
1922
path: string | undefined
2023
shadowed: boolean
2124
} {
22-
const binPaths =
25+
const rawBinPaths =
2326
whichBinSync(binName, {
2427
all: true,
2528
nothrow: true,
2629
}) ?? []
30+
// whichBinSync may return a string when only one result is found, even with all: true.
31+
// This handles both the current published version and future versions.
32+
const binPaths = Array.isArray(rawBinPaths)
33+
? rawBinPaths
34+
: typeof rawBinPaths === 'string'
35+
? [rawBinPaths]
36+
: []
2737
const { shadowBinPath } = constants
2838
let shadowIndex = -1
2939
let theBinPath: string | undefined

0 commit comments

Comments
 (0)