Skip to content

Commit 6d770d9

Browse files
committed
feat(core): Add NX_DEFAULT_OUTPUT_STYLE env var
Allows setting a default output style instead of having to include it on every command Closes #27490
1 parent 2088eaa commit 6d770d9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

astro-docs/src/content/docs/reference/environment-variables.mdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following environment variables are ones that you can set to change the beha
1818
| `NX_CACHE_PROJECT_GRAPH` | boolean | If set to `false`, disables the project graph cache. Most useful when developing a plugin that modifies the project graph. |
1919
| `NX_DAEMON` | boolean | If set to `false`, disables the Nx daemon process. Disable the daemon to print `console.log` statements in plugin code you are developing. |
2020
| `NX_DEFAULT_PROJECT` | string | The default project used for commands which require a project. e.g. `nx build`, `nx g component`, etc. |
21+
| `NX_DEFAULT_OUTPUT_STYLE` | string | The default output style to use when running tasks. Can be overridden on the command line with `--outputStyle`. |
2122
| `NX_HEAD` | string | The default head branch to use when calculating the affected projects. Can be overridden on the command line with `--head`. |
2223
| `NX_PERF_LOGGING` | boolean | If set to `true`, will print debug information useful for profiling executors and Nx itself |
2324
| `NX_PROFILE` | string | Prepend `NX_PROFILE=profile.json` before running targets with Nx to generate a file that be [loaded in Chrome dev tools](/docs/troubleshooting/performance-profiling) to visualize the performance of Nx across multiple processes. |

packages/nx/src/command-line/yargs-utils/shared-options.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ describe('shared-options', () => {
100100
}
101101
));
102102

103+
it('should use NX_DEFAULT_OUTPUT_STYLE if not set', () =>
104+
withEnvironmentVariables(
105+
{
106+
NX_TUI: false,
107+
CI: 'false',
108+
NX_TUI_SKIP_CAPABILITY_CHECK: 'true',
109+
NX_DEFAULT_OUTPUT_STYLE: 'stream-without-prefixes',
110+
},
111+
() => {
112+
const command = withOutputStyleOption(argv);
113+
const result = command.parseSync([]);
114+
expect(result.outputStyle).toEqual('stream-without-prefixes');
115+
}
116+
)
117+
);
118+
103119
it('should set NX_TUI if using not set', () =>
104120
withEnvironmentVariables(
105121
{

packages/nx/src/command-line/yargs-utils/shared-options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ export function withOutputStyleOption<T>(
324324
choices,
325325
})
326326
.middleware([
327+
(args) => {
328+
if (
329+
!args.outputStyle &&
330+
process.env.NX_DEFAULT_OUTPUT_STYLE &&
331+
choices.includes(process.env.NX_DEFAULT_OUTPUT_STYLE as OutputStyle)) {
332+
args.outputStyle = process.env.NX_DEFAULT_OUTPUT_STYLE;
333+
}
334+
},
327335
(args) => {
328336
const useTui = shouldUseTui(readNxJson(), args as NxArgs);
329337
if (useTui) {

0 commit comments

Comments
 (0)