fix(core): prioritize --output-style flag over tui env vars (#30969)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Craigory Coppola 2025-05-01 16:00:59 -04:00 committed by GitHub
parent e5dc244e66
commit 95652aef88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 9 deletions

View File

@ -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
);
}
));
});
}); });

View File

@ -2,6 +2,7 @@ import type { NxJsonConfiguration } from '../config/nx-json';
import { IS_WASM } from '../native'; import { IS_WASM } from '../native';
import { NxArgs } from '../utils/command-line-utils'; import { NxArgs } from '../utils/command-line-utils';
import { isCI } from '../utils/is-ci'; import { isCI } from '../utils/is-ci';
import { logger } from '../utils/logger';
let tuiEnabled = undefined; let tuiEnabled = undefined;
@ -36,16 +37,26 @@ export function shouldUseTui(
return false; 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 (['static', 'stream', 'dynamic-legacy'].includes(nxArgs.outputStyle)) {
// If the user has specified a non-TUI output style, we disable the TUI // If the user has specified a non-TUI output style, we disable the TUI
return false; 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 ( if (
// Interactive TUI doesn't make sense on CI // Interactive TUI doesn't make sense on CI
isCI() || isCI() ||
@ -58,10 +69,6 @@ export function shouldUseTui(
return false; return false;
} }
if (nxArgs.outputStyle === 'dynamic' || nxArgs.outputStyle === 'tui') {
return true;
}
// Respect user config // Respect user config
if (typeof nxJson.tui?.enabled === 'boolean') { if (typeof nxJson.tui?.enabled === 'boolean') {
return Boolean(nxJson.tui?.enabled); return Boolean(nxJson.tui?.enabled);