|
1 | | -import { exec as execNonPromise, ExecOptions } from 'node:child_process' |
| 1 | +import { execFile as execFileNonPromise, ExecFileOptions } from 'node:child_process' |
2 | 2 | import * as fs from 'node:fs/promises' |
3 | 3 | import * as process from 'node:process' |
4 | 4 | import * as path from 'node:path' |
@@ -251,24 +251,29 @@ export abstract class BuildAgentBase implements IBuildAgent { |
251 | 251 | } |
252 | 252 |
|
253 | 253 | async exec(cmd: string, args: string[]): Promise<ExecResult> { |
254 | | - const exec = util.promisify(execNonPromise) |
| 254 | + const execFile = util.promisify(execFileNonPromise) |
255 | 255 |
|
256 | 256 | try { |
257 | | - const commandOptions: ExecOptions = { maxBuffer: 1024 * 1024 * 10 } // 10MB |
258 | | - const { stdout, stderr } = await exec(`${cmd} ${args.join(' ')}`, commandOptions) |
| 257 | + const commandOptions: ExecFileOptions = { maxBuffer: 1024 * 1024 * 10 } // 10MB |
| 258 | + const { stdout, stderr } = await execFile(cmd, args, commandOptions) |
| 259 | + const normalizedStdout = typeof stdout === 'string' ? stdout : stdout?.toString() |
| 260 | + const normalizedStderr = typeof stderr === 'string' ? stderr : stderr?.toString() |
259 | 261 | return { |
260 | 262 | code: 0, |
261 | 263 | error: null, |
262 | | - stderr, |
263 | | - stdout |
| 264 | + stderr: normalizedStderr, |
| 265 | + stdout: normalizedStdout |
264 | 266 | } |
265 | 267 | } catch (e) { |
266 | | - const error = e as Error & { code: number; stderr: string; stdout: string } |
| 268 | + const error = e as Error & { code?: number | string; stderr?: string | Buffer; stdout?: string | Buffer } |
| 269 | + const normalizedStdout = typeof error.stdout === 'string' ? error.stdout : error.stdout?.toString() |
| 270 | + const normalizedStderr = typeof error.stderr === 'string' ? error.stderr : (error.stderr?.toString() ?? error.message) |
| 271 | + const exitCode = typeof error.code === 'number' ? error.code : -1 |
267 | 272 | return { |
268 | | - code: error.code, |
| 273 | + code: exitCode, |
269 | 274 | error, |
270 | | - stderr: error.stderr, |
271 | | - stdout: error.stdout |
| 275 | + stderr: normalizedStderr, |
| 276 | + stdout: normalizedStdout |
272 | 277 | } |
273 | 278 | } |
274 | 279 | } |
|
0 commit comments