MCPcopy Create free account
hub / github.com/freecodexyz/free-code / whichNodeAsync

Function whichNodeAsync

src/utils/which.ts:4–31  ·  view source on GitHub ↗
(command: string)

Source from the content-addressed store, hash-verified

2import { execSync_DEPRECATED } from './execSyncWrapper.js'
3
4async function whichNodeAsync(command: string): Promise<string | null> {
5 if (process.platform === 'win32') {
6 // On Windows, use where.exe and return the first result
7 const result = await execa(`where.exe ${command}`, {
8 shell: true,
9 stderr: 'ignore',
10 reject: false,
11 })
12 if (result.exitCode !== 0 || !result.stdout) {
13 return null
14 }
15 // where.exe returns multiple paths separated by newlines, return the first
16 return result.stdout.trim().split(/\r?\n/)[0] || null
17 }
18
19 // On POSIX systems (macOS, Linux, WSL), use which
20 // Cross-platform safe: Windows is handled above
21 // eslint-disable-next-line custom-rules/no-cross-platform-process-issues
22 const result = await execa(`which ${command}`, {
23 shell: true,
24 stderr: 'ignore',
25 reject: false,
26 })
27 if (result.exitCode !== 0 || !result.stdout) {
28 return null
29 }
30 return result.stdout.trim()
31}
32
33function whichNodeSync(command: string): string | null {
34 if (process.platform === 'win32') {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected