| 901 | * ourselves behaves identically on every platform. |
| 902 | */ |
| 903 | export function hasCommand(cmd: string): boolean { |
| 904 | const isWin = process.platform === 'win32'; |
| 905 | const dirs = (process.env.PATH || process.env.Path || '').split(path.delimiter).filter(Boolean); |
| 906 | const exts = isWin ? (process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM').split(';') : ['']; |
| 907 | for (const dir of dirs) { |
| 908 | for (const ext of exts) { |
| 909 | const candidate = path.join(dir, cmd + ext); |
| 910 | try { |
| 911 | if (!fs.statSync(candidate).isFile()) continue; |
| 912 | if (isWin) return true; |
| 913 | fs.accessSync(candidate, fs.constants.X_OK); |
| 914 | return true; |
| 915 | } catch { |
| 916 | /* not here / not executable — keep scanning */ |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | return false; |
| 921 | } |
| 922 | |
| 923 | export function defaultRun(cmd: string, args: string[], env?: NodeJS.ProcessEnv, cwd?: string): number { |
| 924 | const r = spawnSync(cmd, args, { stdio: 'inherit', env: env ?? process.env, windowsHide: true, cwd }); |