open source is social v-it.org
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2026 sol pbc
3
4import { execFileSync } from 'node:child_process';
5
6/**
7 * Find the full path of an executable (cross-runtime replacement for Bun.which).
8 * Returns the path string or null if not found.
9 */
10export function which(cmd) {
11 try {
12 const bin = process.platform === 'win32' ? 'where' : 'which';
13 return execFileSync(bin, [cmd], {
14 encoding: 'utf-8',
15 stdio: ['pipe', 'pipe', 'pipe'],
16 }).trim().split('\n')[0];
17 } catch {
18 return null;
19 }
20}