diff --git a/CHANGELOG.md b/CHANGELOG.md index 034f1b6daf..796d503738 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - Fix renaming fields (with @as) in inline records doesn't work when destructuring https://github.com/rescript-lang/rescript-compiler/pull/6456 - Fix `rc.4` regressions: - Don't show compilation time when calling `rescript build -help` command. https://github.com/rescript-lang/rescript-compiler/pull/6439 + - 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 #### :house: Internal diff --git a/rescript b/rescript index baee8efdf1..e3d2dbe0c2 100755 --- a/rescript +++ b/rescript @@ -158,9 +158,9 @@ function logStartCompiling() { /** * @param {Array} args - * @param {() => void} [maybeOnSuccess] + * @param {(code: number) => void} [maybeOnClose] */ -function delegateCommand(args, maybeOnSuccess) { +function delegateCommand(args, maybeOnClose) { /** * @type {child_process.ChildProcess} */ @@ -182,11 +182,12 @@ function delegateCommand(args, maybeOnSuccess) { // 'error' if the child failed to spawn. p.on("close", code => { releaseBuild(); - if (maybeOnSuccess && !code) { - maybeOnSuccess(); + const exitCode = code === null ? 1 : code; + if (maybeOnClose) { + maybeOnClose(exitCode); return; } - process.exit(code || 0); + process.exit(exitCode); }); } else { 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.`); } logStartCompiling(); - delegateCommand(delegatedArgs, () => { + delegateCommand(delegatedArgs, _ => { startWatchMode(withWebSocket); buildFinishedCallback(0); }); @@ -519,7 +520,10 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); if (isDefinitelyBuild) { logStartCompiling(); - delegateCommand(process_argv.slice(2), logFinishCompiling); + delegateCommand(process_argv.slice(2), exitCode => { + logFinishCompiling(exitCode); + process.exit(exitCode); + }); } else { switch (maybeSubcommand) { case "info":