From f7a705e32b6b357059711d93570037c7393194d6 Mon Sep 17 00:00:00 2001 From: David First Date: Tue, 3 Sep 2024 14:54:30 -0400 Subject: [PATCH] fix(run), indicate when the app does not run anything in the background (#9170) currently, it simply exits the process, which is confusing. --- scopes/harmony/application/run.cmd.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scopes/harmony/application/run.cmd.ts b/scopes/harmony/application/run.cmd.ts index 9ce53c02c08f..ea3341fb8327 100644 --- a/scopes/harmony/application/run.cmd.ts +++ b/scopes/harmony/application/run.cmd.ts @@ -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 ", 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'); + } + }); } }