mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 22:32:28 +00:00
15 lines
536 B
TypeScript
15 lines
536 B
TypeScript
import whichPkg from "which"
|
|
import path from "path"
|
|
import { Global } from "../global"
|
|
|
|
export function which(cmd: string, env?: NodeJS.ProcessEnv) {
|
|
const base = env?.PATH ?? env?.Path ?? process.env.PATH ?? process.env.Path ?? ""
|
|
const full = base ? base + path.delimiter + Global.Path.bin : Global.Path.bin
|
|
const result = whichPkg.sync(cmd, {
|
|
nothrow: true,
|
|
path: full,
|
|
pathExt: env?.PATHEXT ?? env?.PathExt ?? process.env.PATHEXT ?? process.env.PathExt,
|
|
})
|
|
return typeof result === "string" ? result : null
|
|
}
|