Skip to content

Commit

Permalink
refactor: wait all promises
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Dec 20, 2023
1 parent ea1c0c9 commit a36161e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/exec.js
Expand Up @@ -26,14 +26,15 @@ export const exec = async (file, args, options) => {

const program = spawn(file, args, { cwd: options?.cwd })

pipeline(program.stdout, pipeToBuffer)
pipeline(program.stderr, pipeToBuffer)

const [exitCode] = await once(program, 'exit')
await Promise.allSettled([
pipeline(program.stdout, pipeToBuffer),
pipeline(program.stderr, pipeToBuffer),
once(program, 'exit'),
])

const output = buffer.reduce((result, chunk) => result + chunk, '').replace(/\n$/, '')

if (exitCode !== 0) {
if (program.exitCode !== 0) {
throw new Error(output)
}

Expand Down

0 comments on commit a36161e

Please sign in to comment.