fix(core): disable tui when CI=true (#30754)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> When `CI=true`, the TUI is still enabled by default. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> When `CI=true`, the TUI is disabled unless it is explicitly enabled with `NX_TUI=true`. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
8dc057519f
commit
9c9ddb571e
60
packages/nx/src/tasks-runner/is-tui-enabled.spec.ts
Normal file
60
packages/nx/src/tasks-runner/is-tui-enabled.spec.ts
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,19 +1,23 @@
|
|||||||
import type { NxJsonConfiguration } from '../config/nx-json';
|
import type { NxJsonConfiguration } from '../config/nx-json';
|
||||||
import { readNxJsonFromDisk } from '../devkit-internals';
|
import { readNxJsonFromDisk } from '../devkit-internals';
|
||||||
|
import { isCI } from '../utils/is-ci';
|
||||||
|
|
||||||
let tuiEnabled = undefined;
|
let tuiEnabled = undefined;
|
||||||
|
|
||||||
export function isTuiEnabled(nxJson?: NxJsonConfiguration) {
|
export function isTuiEnabled(
|
||||||
|
nxJson?: NxJsonConfiguration,
|
||||||
|
skipCapableCheck = false
|
||||||
|
) {
|
||||||
if (tuiEnabled !== undefined) {
|
if (tuiEnabled !== undefined) {
|
||||||
return tuiEnabled;
|
return tuiEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the current terminal/environment is not capable of displaying the TUI, we don't run it
|
// If the current terminal/environment is not capable of displaying the TUI, we don't run it
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32';
|
||||||
const isCapable = process.stderr.isTTY && isUnicodeSupported();
|
const isCapable =
|
||||||
// Windows is not working well right now, temporarily disable it on Windows even if it has been specified as enabled
|
skipCapableCheck || (process.stderr.isTTY && isUnicodeSupported());
|
||||||
// TODO(@JamesHenry): Remove this check once Windows issues are fixed.
|
|
||||||
if (!isCapable || isWindows) {
|
if (!isCapable) {
|
||||||
tuiEnabled = false;
|
tuiEnabled = false;
|
||||||
process.env.NX_TUI = 'false';
|
process.env.NX_TUI = 'false';
|
||||||
return tuiEnabled;
|
return tuiEnabled;
|
||||||
@ -21,7 +25,15 @@ export function isTuiEnabled(nxJson?: NxJsonConfiguration) {
|
|||||||
|
|
||||||
// The environment variable takes precedence over the nx.json config
|
// The environment variable takes precedence over the nx.json config
|
||||||
if (typeof process.env.NX_TUI === 'string') {
|
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;
|
return tuiEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user