(
file: string,
args: readonly string[],
options: ExecOptions = {},
)
| 19 | |
| 20 | |
| 21 | export function execFileUtf8( |
| 22 | file: string, |
| 23 | args: readonly string[], |
| 24 | options: ExecOptions = {}, |
| 25 | ): Promise<ExecResult> { |
| 26 | return new Promise((resolve) => { |
| 27 | execFile( |
| 28 | file, |
| 29 | [...args], |
| 30 | { |
| 31 | encoding: 'utf8', |
| 32 | windowsHide: options.windowsHide === true, |
| 33 | ...(options.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}), |
| 34 | env: options.env ?? process.env, |
| 35 | }, |
| 36 | (err, stdout, stderr) => { |
| 37 | if (err === null) { |
| 38 | resolve({ stdout, stderr, code: 0 }); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | |
| 43 | const code = typeof (err as { code?: unknown }).code === 'number' ? (err as { code: number }).code : -1; |
| 44 | const message = err instanceof Error ? err.message : JSON.stringify(err); |
| 45 | resolve({ |
| 46 | stdout: typeof stdout === 'string' ? stdout : '', |
| 47 | stderr: typeof stderr === 'string' && stderr.length > 0 ? stderr : message, |
| 48 | code, |
| 49 | }); |
| 50 | }, |
| 51 | ); |
| 52 | }); |
| 53 | } |
no test coverage detected