Skip to content

Commit edb4f12

Browse files
authored
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.
1 parent 3f7ca15 commit edb4f12

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

build/lib/spawn.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { spawn } from 'child_process';
2+
3+
const spawns = new Set();
4+
5+
export function spawnAndCheck(cmd, args, options) {
6+
const s = spawn(cmd, args, options);
7+
spawns.add(s);
8+
s.on('close', (code) => {
9+
spawns.delete(s);
10+
if (code !== 0) {
11+
console.error(cmd, 'exited with code:', code);
12+
[...spawns].forEach((s) => s.kill());
13+
process.exit(code);
14+
}
15+
});
16+
}

build/tools/build.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { spawn } from 'child_process';
21
import { mkdirSync } from 'fs';
2+
import { spawnAndCheck } from '../lib/spawn.js';
33

44
mkdirSync('out', { recursive: true });
55

6-
spawn('node', ['build/tools/copy.js'], {
6+
spawnAndCheck('node', ['build/tools/copy.js'], {
77
shell: true,
88
stdio: 'inherit',
99
});
1010

11-
spawn('./node_modules/.bin/rollup', ['-c'], {
11+
spawnAndCheck('./node_modules/.bin/rollup', ['-c'], {
1212
shell: true,
1313
stdio: 'inherit',
1414
});

build/tools/serve.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
import { spawn } from 'child_process';
21
import { mkdirSync } from 'fs';
2+
import { spawnAndCheck } from '../lib/spawn.js';
33

44
mkdirSync('out', { recursive: true });
55

6-
const spawns = new Set();
7-
8-
function spawnAndCheck(cmd, args, options) {
9-
const s = spawn(cmd, args, options);
10-
spawns.add(s);
11-
s.on('close', (code) => {
12-
spawns.delete(s);
13-
if (code !== 0) {
14-
console.error(cmd, 'exited with code:', code);
15-
[...spawns].forEach((s) => s.kill());
16-
process.exit(code);
17-
}
18-
});
19-
}
20-
216
spawnAndCheck('npm', ['run', 'watch'], {
227
shell: true,
238
stdio: 'inherit',

0 commit comments

Comments
 (0)