Skip to content

Commit

Permalink
Fix watch exiting on error (#6460)
Browse files Browse the repository at this point in the history
* Fix watch exiting on error

* Update changelog
  • Loading branch information
DZakh authored Oct 31, 2023
1 parent 5b2c5bd commit e2da4ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 11 additions & 7 deletions rescript
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ function logStartCompiling() {

/**
* @param {Array<string>} args
* @param {() => void} [maybeOnSuccess]
* @param {(code: number) => void} [maybeOnClose]
*/
function delegateCommand(args, maybeOnSuccess) {
function delegateCommand(args, maybeOnClose) {
/**
* @type {child_process.ChildProcess}
*/
Expand All @@ -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}`);
Expand Down Expand Up @@ -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);
});
Expand All @@ -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":
Expand Down

0 comments on commit e2da4ef

Please sign in to comment.