Skip to content

Commit 345c93c

Browse files
committed
make it fail early
1 parent 9b50125 commit 345c93c

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

biome.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"nursery": {
1414
"noCommonJs": "error"
1515
},
16+
"suspicious": {
17+
"noAssignInExpressions": "warn"
18+
},
1619
"correctness": {
1720
"useImportExtensions": "error",
1821
"noUndeclaredDependencies": "error",
@@ -59,7 +62,8 @@
5962
"lib/es6/**",
6063
"lib/js/**",
6164
"ninja/**",
62-
"playground/packages/**",
65+
"packages/**",
66+
"playground/**",
6367
"*.bs.js",
6468
"*.res.js",
6569
"*.res.mjs",

lib_dev/process.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,25 @@ const signals = {
1919
export const { exec, node, npx, mocha, bsc, rescript, execBuild, execClean } =
2020
setup();
2121

22+
/**
23+
* @typedef {{
24+
* throwOnExit?: boolean,
25+
* }} ExecOptions
26+
*/
27+
2228
/**
2329
* @param {string} [cwd]
2430
*/
2531
export function setup(cwd = process.cwd()) {
2632
/**
2733
* @param {string} command
2834
* @param {string[]} [args]
29-
* @param {child_process.SpawnOptions} [options]
35+
* @param {child_process.SpawnOptions & ExecOptions} [options]
3036
* @return {Promise<ExecResult>}
3137
*/
3238
async function exec(command, args = [], options = {}) {
39+
const { throwOnExit = true } = options;
40+
3341
const stdoutChunks = [];
3442
const stderrChunks = [];
3543

@@ -54,16 +62,24 @@ export function setup(cwd = process.cwd()) {
5462
});
5563

5664
subprocess.once("close", (exitCode, signal) => {
57-
const stdout = Buffer.concat(stdoutChunks).toString("utf8");
58-
const stderr = Buffer.concat(stderrChunks).toString("utf8");
65+
const stdout = stdoutChunks.length
66+
? Buffer.concat(stdoutChunks).toString("utf8")
67+
: null;
68+
const stderr = stdoutChunks.length
69+
? Buffer.concat(stderrChunks).toString("utf8")
70+
: null;
5971

6072
let code = exitCode ?? 1;
6173
if (signals[signal]) {
6274
// + 128 is standard POSIX practice, see also https://nodejs.org/api/process.html#exit-codes
6375
code = signals[signal] + 128;
6476
}
6577

66-
resolve({ status: code, stdout, stderr });
78+
if (throwOnExit && code !== 0) {
79+
reject({ status: code, stdout, stderr });
80+
} else {
81+
resolve({ status: code, stdout, stderr });
82+
}
6783
});
6884
});
6985
}

tests/build_tests/install/src/Foo.bs.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)