Resolve a command path for a sanitized PATH that still works cross-platform.
(command: string)
| 41 | |
| 42 | /** Resolve a command path for a sanitized PATH that still works cross-platform. */ |
| 43 | function commandPath(command: string) { |
| 44 | const proc = Bun.spawnSync( |
| 45 | process.platform === "win32" ? ["where", command] : ["bash", "-lc", `command -v ${command}`], |
| 46 | { |
| 47 | stdin: "ignore", |
| 48 | stdout: "pipe", |
| 49 | stderr: "pipe", |
| 50 | env: process.env, |
| 51 | }, |
| 52 | ); |
| 53 | const resolved = Buffer.from(proc.stdout).toString("utf8").split(/\r?\n/, 1)[0]?.trim(); |
| 54 | if (proc.exitCode !== 0 || !resolved) { |
| 55 | throw new Error(`Could not resolve ${command} on PATH for the prebuilt install smoke test.`); |
| 56 | } |
| 57 | |
| 58 | return resolved; |
| 59 | } |
| 60 | |
| 61 | /** Resolve a command directory for a sanitized PATH that still works cross-platform. */ |
| 62 | function commandDirectory(command: string) { |
no outgoing calls
no test coverage detected