feat(core): make task runner selection configurable through env variable (#14529)

This commit is contained in:
Richard Versteeg 2023-03-16 19:12:46 +01:00 committed by GitHub
parent 7812f41994
commit c95b27d80a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -13,6 +13,7 @@ The following environment variables are ones that you can set to change the beha
| NX_PROFILE | string | Prepend `NX_PROFILE=profile.json` before running targets with Nx to generate a file that be [loaded in Chrome dev tools](/recipes/other/performance-profiling) to visualize the performance of Nx across multiple processes. |
| NX_PROJECT_GRAPH_CACHE_DIRECTORY | string | The project graph cache is stored in `node_modules/.cache/nx` by default. Set this variable to use a different directory. |
| NX_PROJECT_GRAPH_MAX_WORKERS | number | The number of workers to use when calculating the project graph. |
| NX_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. |
| NX_SKIP_NX_CACHE | boolean | Rerun the tasks even when the results are available in the cache |
| NX_TASKS_RUNNER_DYNAMIC_OUTPUT | boolean | If set to `false`, will use non-dynamic terminal output strategy (what you see in CI), even when you terminal can support the dynamic version |
| NX_VERBOSE_LOGGING | boolean | If set to `true`, will print debug information useful for troubleshooting |

View File

@ -240,6 +240,39 @@ describe('splitArgs', () => {
process.env.NX_HEAD = originalNxHead;
});
it('should set runner based on environment variables, if it is not provided directly on the command', () => {
const originalRunner = process.env.NX_RUNNER;
process.env.NX_RUNNER = 'some-env-runner-name';
expect(
splitArgsIntoNxArgsAndOverrides(
{
__overrides_unparsed__: ['--notNxArg', 'true', '--override'],
$0: '',
},
'run-one',
{} as any,
{} as any
).nxArgs.runner
).toEqual('some-env-runner-name');
expect(
splitArgsIntoNxArgsAndOverrides(
{
__overrides_unparsed__: ['--notNxArg', 'true', '--override'],
$0: '',
runner: 'directlyOnCommand', // higher priority than $NX_RUNNER
},
'run-one',
{} as any,
{} as any
).nxArgs.runner
).toEqual('directlyOnCommand');
// Reset process data
process.env.NX_RUNNER = originalRunner;
});
describe('--parallel', () => {
it('should be a number', () => {
const parallel = splitArgsIntoNxArgsAndOverrides(

View File

@ -176,6 +176,17 @@ export function splitArgsIntoNxArgsAndOverrides(
nxArgs.skipNxCache = process.env.NX_SKIP_NX_CACHE === 'true';
}
if (!nxArgs.runner && process.env.NX_RUNNER) {
nxArgs.runner = process.env.NX_RUNNER;
if (options.printWarnings) {
output.note({
title: `No explicit --runner argument provided, but found environment variable NX_RUNNER so using its value: ${output.bold(
`${nxArgs.runner}`
)}`,
});
}
}
if (args['parallel'] === 'false' || args['parallel'] === false) {
nxArgs['parallel'] = 1;
} else if (