Skip to content

Commit

Permalink
fix(run), indicate when the app does not run anything in the backgrou…
Browse files Browse the repository at this point in the history
…nd (#9170)

currently, it simply exits the process, which is confusing.
  • Loading branch information
davidfirst authored Sep 3, 2024
1 parent 51cd3ea commit f7a705e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scopes/harmony/application/run.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,22 @@ export class RunCmd implements Command {
if (isOldApi) {
this.logger.console(`${appName} app is running on http://localhost:${port}`);
}

/**
* normally, when running "bit run <app-name>", the app is running in the background, which keeps the event loop busy.
* when the even loop is busy, the process doesn't exit, which is what we're looking for.
*
* however, if the app is not running in the background, the event loop is free, and the process exits. this is
* very confusing to the end user, because there is no error and no message indicating what's happening.
*
* this "beforeExit" event is a good place to catch this case and print a message to the user.
* it's better than using "exit" event, which can caused by the app itself running "process.exit".
* "beforeExit" is called when the event loop is empty and the process is about to exit.
*/
process.on('beforeExit', (code) => {
if (code === 0) {
this.logger.console('no app is running in the background, please check your app');
}
});
}
}

0 comments on commit f7a705e

Please sign in to comment.