From edb4f12062b51bc9e74b3cd502b8e060b1830e2c Mon Sep 17 00:00:00 2001 From: Greggman Date: Tue, 22 Oct 2024 03:27:50 +0900 Subject: [PATCH] Make build use spawnAndCheck (#467) I think this is the reason I didn't notice it fail. The build was using just spawn and so when rollup failed it didn't pass the exit status back out to the action so the action though the build succeeded. --- build/lib/spawn.js | 16 ++++++++++++++++ build/tools/build.js | 6 +++--- build/tools/serve.js | 17 +---------------- 3 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 build/lib/spawn.js diff --git a/build/lib/spawn.js b/build/lib/spawn.js new file mode 100644 index 00000000..e0483a5d --- /dev/null +++ b/build/lib/spawn.js @@ -0,0 +1,16 @@ +import { spawn } from 'child_process'; + +const spawns = new Set(); + +export function spawnAndCheck(cmd, args, options) { + const s = spawn(cmd, args, options); + spawns.add(s); + s.on('close', (code) => { + spawns.delete(s); + if (code !== 0) { + console.error(cmd, 'exited with code:', code); + [...spawns].forEach((s) => s.kill()); + process.exit(code); + } + }); +} diff --git a/build/tools/build.js b/build/tools/build.js index 2996824e..a8cd4813 100644 --- a/build/tools/build.js +++ b/build/tools/build.js @@ -1,14 +1,14 @@ -import { spawn } from 'child_process'; import { mkdirSync } from 'fs'; +import { spawnAndCheck } from '../lib/spawn.js'; mkdirSync('out', { recursive: true }); -spawn('node', ['build/tools/copy.js'], { +spawnAndCheck('node', ['build/tools/copy.js'], { shell: true, stdio: 'inherit', }); -spawn('./node_modules/.bin/rollup', ['-c'], { +spawnAndCheck('./node_modules/.bin/rollup', ['-c'], { shell: true, stdio: 'inherit', }); diff --git a/build/tools/serve.js b/build/tools/serve.js index 0e7d1a53..1db73bee 100644 --- a/build/tools/serve.js +++ b/build/tools/serve.js @@ -1,23 +1,8 @@ -import { spawn } from 'child_process'; import { mkdirSync } from 'fs'; +import { spawnAndCheck } from '../lib/spawn.js'; mkdirSync('out', { recursive: true }); -const spawns = new Set(); - -function spawnAndCheck(cmd, args, options) { - const s = spawn(cmd, args, options); - spawns.add(s); - s.on('close', (code) => { - spawns.delete(s); - if (code !== 0) { - console.error(cmd, 'exited with code:', code); - [...spawns].forEach((s) => s.kill()); - process.exit(code); - } - }); -} - spawnAndCheck('npm', ['run', 'watch'], { shell: true, stdio: 'inherit',