mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 12:54:29 +00:00
fix(cli): print the update-available notice once, not on every event-loop drain
`process.on("beforeExit", ...)` re-fires every time the event loop
drains, and the handler kicks off a fire-and-forget async telemetry
flush — so on a successful command the user sees the
"Update available: …" notice twice (once after the initial drain, again
after the flush settles). Using `process.once` detaches the listener
after first invocation, fixing the double-print and also preventing a
double-flush of telemetry.
Reported during local testing of `auth login`, but the bug affects every
command (any path where `_flush()` schedules work).
This commit is contained in:
@@ -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?.();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user