Skip to content

Commit 7197083

Browse files
committed
chore(cli): collapse redundant setNoLogMode reset+set pairs
Combine the `setNoLogMode(false)` followed by conditional `setNoLogMode(true)` into a single `setNoLogMode(!!…)` call — same effect, one line, and the intent reads directly. Trim near-duplicate comments at the two call sites to just the WHY (vitest worker state leak) that isn't obvious from the code.
1 parent ed83f91 commit 7197083

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

packages/cli/src/utils/cli/with-subcommands.mts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -525,16 +525,10 @@ export async function meowWithSubcommands(
525525
const compactMode = !!compactHeaderFlag || !!(getCI() && !VITEST)
526526
const noSpinner = spinnerFlag === false || isDebug()
527527

528-
// Reset first so prior test runs (module-level state is shared across
529-
// vitest cases in the same worker) can't leak their noLogMode setting
530-
// into this invocation. Then engage as early as possible so subsequent
531-
// informational output in this function and downstream commands knows
532-
// to stay on stderr. Keeps stdout clean for `--json | jq` style
533-
// pipelines.
534-
setNoLogMode(false)
535-
if (noLogFlag) {
536-
setNoLogMode(true)
537-
}
528+
// Reset unconditionally: module-level state is shared across vitest
529+
// cases in the same worker, so a prior run with --no-log could leak
530+
// into this invocation.
531+
setNoLogMode(!!noLogFlag)
538532

539533
// Use CI spinner style when --no-spinner is passed or debug mode is enabled.
540534
// This prevents the spinner from interfering with debug output.
@@ -934,11 +928,6 @@ export function meowOrExit(
934928
const command = `${parentName} ${cliConfig.commandName}`
935929
lastSeenCommand = command
936930

937-
// Reset no-log mode for each command invocation so state doesn't leak
938-
// across unit tests that exercise multiple commands in sequence. The
939-
// flag is re-engaged below if the parsed flags call for it.
940-
setNoLogMode(false)
941-
942931
// This exits if .printHelp() is called either by meow itself or by us.
943932
const cli = meow({
944933
argv,
@@ -976,12 +965,10 @@ export function meowOrExit(
976965
const compactMode = !!compactHeaderFlag || !!(getCI() && !VITEST)
977966
const noSpinner = spinnerFlag === false || isDebug()
978967

979-
// Engage no-log mode when the user asked for it directly, or when
980-
// `--json` / `--markdown` is in effect — in both cases stdout belongs
981-
// to the primary payload and informational output should go to stderr.
982-
if (noLogFlag || jsonFlag || markdownFlag) {
983-
setNoLogMode(true)
984-
}
968+
// --json / --markdown imply --no-log: their stdout belongs to the
969+
// primary payload, so informational output must go to stderr. Reset
970+
// unconditionally to clear any prior in-worker vitest state.
971+
setNoLogMode(!!(noLogFlag || jsonFlag || markdownFlag))
985972

986973
// Use CI spinner style when --no-spinner is passed.
987974
// This prevents the spinner from interfering with debug output.

0 commit comments

Comments
 (0)