From 0452abf5ec2bac55caba2e13c23ae5939b959677 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Tue, 31 Oct 2023 13:21:36 +0400 Subject: [PATCH 1/2] Fix watch exiting on error --- rescript | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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": From 9b545187e1599ea6dbd345c8c0a70444d53db597 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Tue, 31 Oct 2023 14:57:29 +0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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