Skip to content

Commit e2da4ef

Browse files
authored
Fix watch exiting on error (#6460)
* Fix watch exiting on error * Update changelog
1 parent 5b2c5bd commit e2da4ef

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- Fix renaming fields (with @as) in inline records doesn't work when destructuring https://github.com/rescript-lang/rescript-compiler/pull/6456
3131
- Fix `rc.4` regressions:
3232
- Don't show compilation time when calling `rescript build -help` command. https://github.com/rescript-lang/rescript-compiler/pull/6439
33+
- Running `rescript build -w` with a compilation error doesn't exit with an error code and continues waiting for changes. https://github.com/rescript-lang/rescript-compiler/pull/6460
3334

3435
#### :house: Internal
3536

rescript

+11-7
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ function logStartCompiling() {
158158

159159
/**
160160
* @param {Array<string>} args
161-
* @param {() => void} [maybeOnSuccess]
161+
* @param {(code: number) => void} [maybeOnClose]
162162
*/
163-
function delegateCommand(args, maybeOnSuccess) {
163+
function delegateCommand(args, maybeOnClose) {
164164
/**
165165
* @type {child_process.ChildProcess}
166166
*/
@@ -182,11 +182,12 @@ function delegateCommand(args, maybeOnSuccess) {
182182
// 'error' if the child failed to spawn.
183183
p.on("close", code => {
184184
releaseBuild();
185-
if (maybeOnSuccess && !code) {
186-
maybeOnSuccess();
185+
const exitCode = code === null ? 1 : code;
186+
if (maybeOnClose) {
187+
maybeOnClose(exitCode);
187188
return;
188189
}
189-
process.exit(code || 0);
190+
process.exit(exitCode);
190191
});
191192
} else {
192193
console.warn(`Another build detected or stale lockfile ${lockFileName}`);
@@ -504,7 +505,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`);
504505
}
505506

506507
logStartCompiling();
507-
delegateCommand(delegatedArgs, () => {
508+
delegateCommand(delegatedArgs, _ => {
508509
startWatchMode(withWebSocket);
509510
buildFinishedCallback(0);
510511
});
@@ -519,7 +520,10 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`);
519520

520521
if (isDefinitelyBuild) {
521522
logStartCompiling();
522-
delegateCommand(process_argv.slice(2), logFinishCompiling);
523+
delegateCommand(process_argv.slice(2), exitCode => {
524+
logFinishCompiling(exitCode);
525+
process.exit(exitCode);
526+
});
523527
} else {
524528
switch (maybeSubcommand) {
525529
case "info":

0 commit comments

Comments
 (0)