Merge pull request #1104 from heygen-com/05-28-fix_cli_update_notice_double_print

fix(cli): print the update-available notice once, not on every event-loop drain
This commit is contained in:
James Russo
2026-05-28 01:36:59 -04:00
committed by GitHub
+6 -2
View File
@@ -193,8 +193,12 @@ if (!isHelp && !hasJsonFlag && command !== "upgrade") {
const commandStart = Date.now();
let commandFailed = false;
// Async flush for normal exit (beforeExit fires when the event loop drains)
process.on("beforeExit", () => {
// Async flush for normal exit. `beforeExit` re-fires every time the
// event loop drains, and the async `_flush()` itself schedules new
// work — so a plain `on` listener would print the update notice (and
// re-flush) once per drain (the user-reported double-print). `once`
// detaches after first invocation, which is what we want for both.
process.once("beforeExit", () => {
_flush?.().catch(() => {});
if (!hasJsonFlag) _printUpdateNotice?.();
});