(
command: string,
options?: { cwd?: string; env?: NodeJS.ProcessEnv; shell?: string },
)
| 10 | const execAsyncBase = util.promisify(exec); |
| 11 | |
| 12 | export const execAsync = async ( |
| 13 | command: string, |
| 14 | options?: { cwd?: string; env?: NodeJS.ProcessEnv; shell?: string }, |
| 15 | ): Promise<{ stdout: string; stderr: string }> => { |
| 16 | try { |
| 17 | const result = await execAsyncBase(command, options); |
| 18 | return { |
| 19 | stdout: result.stdout.toString(), |
| 20 | stderr: result.stderr.toString(), |
| 21 | }; |
| 22 | } catch (error) { |
| 23 | if (error instanceof Error) { |
| 24 | // @ts-ignore - exec error has these properties |
| 25 | const exitCode = error.code; |
| 26 | // @ts-ignore |
| 27 | const stdout = error.stdout?.toString() || ""; |
| 28 | // @ts-ignore |
| 29 | const stderr = error.stderr?.toString() || ""; |
| 30 | |
| 31 | throw new ExecError(`Command execution failed: ${error.message}`, { |
| 32 | command, |
| 33 | stdout, |
| 34 | stderr, |
| 35 | exitCode, |
| 36 | originalError: error, |
| 37 | }); |
| 38 | } |
| 39 | throw error; |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | interface ExecOptions { |
| 44 | cwd?: string; |
no outgoing calls