From 9c9ddb571efc738f3525d2b629d4dc4310cbb775 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 16 Apr 2025 17:21:11 -0400 Subject: [PATCH] fix(core): disable tui when CI=true (#30754) ## Current Behavior When `CI=true`, the TUI is still enabled by default. ## Expected Behavior When `CI=true`, the TUI is disabled unless it is explicitly enabled with `NX_TUI=true`. ## Related Issue(s) Fixes # --- .../src/tasks-runner/is-tui-enabled.spec.ts | 60 +++++++++++++++++++ .../nx/src/tasks-runner/is-tui-enabled.ts | 24 ++++++-- 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 packages/nx/src/tasks-runner/is-tui-enabled.spec.ts diff --git a/packages/nx/src/tasks-runner/is-tui-enabled.spec.ts b/packages/nx/src/tasks-runner/is-tui-enabled.spec.ts new file mode 100644 index 0000000000..e278f973ba --- /dev/null +++ b/packages/nx/src/tasks-runner/is-tui-enabled.spec.ts @@ -0,0 +1,60 @@ +describe('isTuiEnabled', () => { + let originalTuiEnv: string | undefined; + let originalCIEnv: string | undefined; + let isTuiEnabled: typeof import('./is-tui-enabled').isTuiEnabled; + beforeEach(async () => { + jest.resetModules(); + isTuiEnabled = await import('./is-tui-enabled').then((m) => m.isTuiEnabled); + originalTuiEnv = process.env.NX_TUI; + originalCIEnv = process.env.CI; + process.env.CI = 'false'; + delete process.env.NX_TUI; + }); + + afterEach(() => { + if (originalTuiEnv) { + process.env.NX_TUI = originalTuiEnv; + } else { + delete process.env.NX_TUI; + } + if (originalCIEnv) { + process.env.CI = originalCIEnv; + } else { + delete process.env.CI; + } + }); + + it('should return true by default', () => { + // default is false in nx.json + expect(isTuiEnabled({}, true)).toBe(true); + }); + + it('should return true if the TUI is enabled', () => { + process.env.NX_TUI = 'true'; + expect(isTuiEnabled({}, true)).toBe(true); + }); + + it('should return false if the TUI is disabled', () => { + process.env.NX_TUI = 'false'; + expect(isTuiEnabled({}, true)).toBe(false); + }); + + it('should return false in CI', () => { + process.env.CI = 'true'; + expect(isTuiEnabled({}, true)).toBe(false); + }); + + it('should return true if TUI is enabled in CI', () => { + process.env.NX_TUI = 'true'; + process.env.CI = 'true'; + expect(isTuiEnabled({}, true)).toBe(true); + }); + + it('should return true if the TUI is enabled in nx.json', () => { + expect(isTuiEnabled({ tui: { enabled: true } }, true)).toBe(true); + }); + + it('should return false if the TUI is disabled in nx.json', () => { + expect(isTuiEnabled({ tui: { enabled: false } }, 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 6d1ebf518d..b9c020511c 100644 --- a/packages/nx/src/tasks-runner/is-tui-enabled.ts +++ b/packages/nx/src/tasks-runner/is-tui-enabled.ts @@ -1,19 +1,23 @@ import type { NxJsonConfiguration } from '../config/nx-json'; import { readNxJsonFromDisk } from '../devkit-internals'; +import { isCI } from '../utils/is-ci'; let tuiEnabled = undefined; -export function isTuiEnabled(nxJson?: NxJsonConfiguration) { +export function isTuiEnabled( + nxJson?: NxJsonConfiguration, + skipCapableCheck = false +) { if (tuiEnabled !== undefined) { return tuiEnabled; } // If the current terminal/environment is not capable of displaying the TUI, we don't run it const isWindows = process.platform === 'win32'; - const isCapable = process.stderr.isTTY && isUnicodeSupported(); - // Windows is not working well right now, temporarily disable it on Windows even if it has been specified as enabled - // TODO(@JamesHenry): Remove this check once Windows issues are fixed. - if (!isCapable || isWindows) { + const isCapable = + skipCapableCheck || (process.stderr.isTTY && isUnicodeSupported()); + + if (!isCapable) { tuiEnabled = false; process.env.NX_TUI = 'false'; return tuiEnabled; @@ -21,7 +25,15 @@ export function isTuiEnabled(nxJson?: NxJsonConfiguration) { // The environment variable takes precedence over the nx.json config if (typeof process.env.NX_TUI === 'string') { - tuiEnabled = process.env.NX_TUI === 'true' ? true : false; + tuiEnabled = process.env.NX_TUI === 'true'; + return tuiEnabled; + } + + // Windows is not working well right now, temporarily disable it on Windows even if it has been specified as enabled + // TODO(@JamesHenry): Remove this check once Windows issues are fixed. + if (isCI() || isWindows) { + tuiEnabled = false; + process.env.NX_TUI = 'false'; return tuiEnabled; }