From 95652aef88bf5c105f84bbac9f7e4acf7674c98c Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 1 May 2025 16:00:59 -0400 Subject: [PATCH] fix(core): prioritize --output-style flag over tui env vars (#30969) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/tasks-runner/is-tui-enabled.spec.ts | 26 +++++++++++++++++++ .../nx/src/tasks-runner/is-tui-enabled.ts | 25 +++++++++++------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/packages/nx/src/tasks-runner/is-tui-enabled.spec.ts b/packages/nx/src/tasks-runner/is-tui-enabled.spec.ts index b5ea019a50..2f62e19ed8 100644 --- a/packages/nx/src/tasks-runner/is-tui-enabled.spec.ts +++ b/packages/nx/src/tasks-runner/is-tui-enabled.spec.ts @@ -112,4 +112,30 @@ describe('shouldUseTui', () => { } ) ); + + describe('priority', () => { + it('should prioritize the CLI args over the env var', () => + withEnvironmentVariables( + { + NX_TUI: 'false', + CI: 'false', + }, + () => { + expect(shouldUseTui({}, { outputStyle: 'dynamic' }, true)).toBe(true); + } + )); + + it('should prioritize the env var over the nx.json config', () => + withEnvironmentVariables( + { + NX_TUI: 'false', + CI: 'false', + }, + () => { + expect(shouldUseTui({ tui: { enabled: true } }, {}, true)).toBe( + false + ); + } + )); + }); }); diff --git a/packages/nx/src/tasks-runner/is-tui-enabled.ts b/packages/nx/src/tasks-runner/is-tui-enabled.ts index 3c9a4107cc..ad0c66c16f 100644 --- a/packages/nx/src/tasks-runner/is-tui-enabled.ts +++ b/packages/nx/src/tasks-runner/is-tui-enabled.ts @@ -2,6 +2,7 @@ import type { NxJsonConfiguration } from '../config/nx-json'; import { IS_WASM } from '../native'; import { NxArgs } from '../utils/command-line-utils'; import { isCI } from '../utils/is-ci'; +import { logger } from '../utils/logger'; let tuiEnabled = undefined; @@ -36,16 +37,26 @@ export function shouldUseTui( return false; } - // The environment variable takes precedence over the nx.json config - if (typeof process.env.NX_TUI === 'string') { - return process.env.NX_TUI === 'true'; - } - if (['static', 'stream', 'dynamic-legacy'].includes(nxArgs.outputStyle)) { // If the user has specified a non-TUI output style, we disable the TUI return false; } + if (nxArgs.outputStyle === 'dynamic' || nxArgs.outputStyle === 'tui') { + return true; + } + + // The environment variable takes precedence over the nx.json config, but + // are lower priority than the CLI args as they are less likely to change + // between runs, whereas the CLI args are specified by the user for each run. + if (typeof process.env.NX_TUI === 'string') { + return process.env.NX_TUI === 'true'; + } + + // BELOW THIS LINE ARE "repo specific" checks, instead of "user specific" checks. + // "user specific" checks are specified by the current user rather than the repo + // settings which are applied for all users of the repo... so they are more specific + // and take priority. if ( // Interactive TUI doesn't make sense on CI isCI() || @@ -58,10 +69,6 @@ export function shouldUseTui( return false; } - if (nxArgs.outputStyle === 'dynamic' || nxArgs.outputStyle === 'tui') { - return true; - } - // Respect user config if (typeof nxJson.tui?.enabled === 'boolean') { return Boolean(nxJson.tui?.enabled);