Skip to content

Commit

Permalink
Ensure npm scripts (via Gulp) emit errors
Browse files Browse the repository at this point in the history
Whilst we suppress non-zero exit codes for `gulp dev` we should still exit if anything writes to `stderr`
  • Loading branch information
colinrotherham committed Nov 23, 2022
1 parent 83f8806 commit cd6f256
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tasks/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ export async function npmScript (name, args = []) {
return new Promise((resolve, reject) => {
const script = spawn(command, ['run', name, '--silent', ...args])

// Send output to console
script.stdout.on('data', (data) => console.log(data.toString()))
script.stderr.on('data', (data) => console.error(data.toString()))

// Emit errors to error listener
script.stderr.on('data', (data) => {
script.emit('error', new Error(data.toString()))
})

// Reject on actual script errors to exit `gulp dev`
script.on('error', reject)
Expand Down

0 comments on commit cd6f256

Please sign in to comment.