Skip to content

Commit

Permalink
Make build use spawnAndCheck (#467)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greggman authored Oct 21, 2024
1 parent 3f7ca15 commit edb4f12
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
16 changes: 16 additions & 0 deletions build/lib/spawn.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
}
6 changes: 3 additions & 3 deletions build/tools/build.js
Original file line number Diff line number Diff line change
@@ -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',
});
17 changes: 1 addition & 16 deletions build/tools/serve.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down

0 comments on commit edb4f12

Please sign in to comment.