2026-03-06 05:18:29 +00:00
|
|
|
import whichPkg from "which"
|
2026-03-20 01:21:55 +00:00
|
|
|
import path from "path"
|
2026-04-25 17:51:37 +00:00
|
|
|
import { Global } from "@opencode-ai/core/global"
|
2026-03-06 05:18:29 +00:00
|
|
|
|
|
|
|
|
export function which(cmd: string, env?: NodeJS.ProcessEnv) {
|
2026-03-20 01:21:55 +00:00
|
|
|
const base = env?.PATH ?? env?.Path ?? process.env.PATH ?? process.env.Path ?? ""
|
|
|
|
|
const full = base ? base + path.delimiter + Global.Path.bin : Global.Path.bin
|
2026-03-06 05:18:29 +00:00
|
|
|
const result = whichPkg.sync(cmd, {
|
|
|
|
|
nothrow: true,
|
2026-03-20 01:21:55 +00:00
|
|
|
path: full,
|
2026-03-07 05:42:14 +00:00
|
|
|
pathExt: env?.PATHEXT ?? env?.PathExt ?? process.env.PATHEXT ?? process.env.PathExt,
|
2026-03-06 05:18:29 +00:00
|
|
|
})
|
|
|
|
|
return typeof result === "string" ? result : null
|
|
|
|
|
}
|