(
file: string,
args: string[],
{
abortSignal,
timeout: finalTimeout = 10 * SECONDS_IN_MINUTE * MS_IN_SECOND,
preserveOutputOnError: finalPreserveOutput = true,
cwd: finalCwd,
env: finalEnv,
maxBuffer,
shell,
stdin: finalStdin,
input: finalInput,
}: ExecFileWithCwdOptions = {
timeout: 10 * SECONDS_IN_MINUTE * MS_IN_SECOND,
preserveOutputOnError: true,
maxBuffer: 1_000_000,
},
)
| 87 | * execFile, but always resolves (never throws) |
| 88 | */ |
| 89 | export function execFileNoThrowWithCwd( |
| 90 | file: string, |
| 91 | args: string[], |
| 92 | { |
| 93 | abortSignal, |
| 94 | timeout: finalTimeout = 10 * SECONDS_IN_MINUTE * MS_IN_SECOND, |
| 95 | preserveOutputOnError: finalPreserveOutput = true, |
| 96 | cwd: finalCwd, |
| 97 | env: finalEnv, |
| 98 | maxBuffer, |
| 99 | shell, |
| 100 | stdin: finalStdin, |
| 101 | input: finalInput, |
| 102 | }: ExecFileWithCwdOptions = { |
| 103 | timeout: 10 * SECONDS_IN_MINUTE * MS_IN_SECOND, |
| 104 | preserveOutputOnError: true, |
| 105 | maxBuffer: 1_000_000, |
| 106 | }, |
| 107 | ): Promise<{ stdout: string; stderr: string; code: number; error?: string }> { |
| 108 | return new Promise(resolve => { |
| 109 | // Use execa for cross-platform .bat/.cmd compatibility on Windows |
| 110 | execa(file, args, { |
| 111 | maxBuffer, |
| 112 | signal: abortSignal, |
| 113 | timeout: finalTimeout, |
| 114 | cwd: finalCwd, |
| 115 | env: finalEnv, |
| 116 | shell, |
| 117 | stdin: finalStdin, |
| 118 | input: finalInput, |
| 119 | reject: false, // Don't throw on non-zero exit codes |
| 120 | }) |
| 121 | .then(result => { |
| 122 | if (result.failed) { |
| 123 | if (finalPreserveOutput) { |
| 124 | const errorCode = result.exitCode ?? 1 |
| 125 | void resolve({ |
| 126 | stdout: result.stdout || '', |
| 127 | stderr: result.stderr || '', |
| 128 | code: errorCode, |
| 129 | error: getErrorMessage( |
| 130 | result as unknown as ExecaResultWithError, |
| 131 | errorCode, |
| 132 | ), |
| 133 | }) |
| 134 | } else { |
| 135 | void resolve({ stdout: '', stderr: '', code: result.exitCode ?? 1 }) |
| 136 | } |
| 137 | } else { |
| 138 | void resolve({ |
| 139 | stdout: result.stdout, |
| 140 | stderr: result.stderr, |
| 141 | code: 0, |
| 142 | }) |
| 143 | } |
| 144 | }) |
| 145 | .catch((error: ExecaError) => { |
| 146 | logError(error) |
no test coverage detected