Skip to content

Commit

Permalink
fix(core): allow overriding NX_PARALLEL with --parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jul 24, 2024
1 parent 99a488a commit 6ab3bb8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 34 deletions.
26 changes: 5 additions & 21 deletions packages/nx/src/command-line/release/command-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
withRunManyOptions,
} from '../yargs-utils/shared-options';
import { VersionData } from './utils/shared';
import { readParallelFromArgsAndEnv } from '../../utils/command-line-utils';

export interface NxReleaseArgs {
groups?: string[];
Expand Down Expand Up @@ -355,27 +356,10 @@ const planCommand: CommandModule<NxReleaseArgs, PlanOptions> = {
};

function coerceParallelOption(args: any) {
if (args['parallel'] === 'false' || args['parallel'] === false) {
return {
...args,
parallel: 1,
};
} else if (
args['parallel'] === 'true' ||
args['parallel'] === true ||
args['parallel'] === ''
) {
return {
...args,
parallel: Number(args['maxParallel'] || args['max-parallel'] || 3),
};
} else if (args['parallel'] !== undefined) {
return {
...args,
parallel: Number(args['parallel']),
};
}
return args;
return {
...args,
parallel: readParallelFromArgsAndEnv(args),
};
}

function withGitCommitAndGitTagOptions<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,11 @@ describe('TargetProjectLocator', () => {
});

describe('isBuiltinModuleImport()', () => {
it('should return true for all node builtin modules', () => {
const allBuiltinModules = require('node:module').builtinModules;
allBuiltinModules.forEach((builtinModule) => {
const allBuiltinModules = require('node:module').builtinModules;
it.each(allBuiltinModules)(
`should return true for %s builtin module`,
(builtinModule) => {
expect(isBuiltinModuleImport(builtinModule)).toBe(true);
});
});
}
);
});
39 changes: 39 additions & 0 deletions packages/nx/src/utils/command-line-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,5 +473,44 @@ describe('splitArgs', () => {

expect(parallel).toEqual(5);
});

it('should be able to be specified in the environment', () => {
const { nxArgs } = withEnvironment(
{
NX_PARALLEL: '5',
},
() =>
splitArgsIntoNxArgsAndOverrides(
{
$0: '',
__overrides_unparsed__: [],
},
'affected',
{} as any,
{} as any
)
);
expect(nxArgs.parallel).toEqual(5);
});

it('should be able to override NX_PARALLEL with the parallel flag', () => {
const { nxArgs } = withEnvironment(
{
NX_PARALLEL: '5',
},
() =>
splitArgsIntoNxArgsAndOverrides(
{
$0: '',
__overrides_unparsed__: [],
parallel: '3',
},
'affected',
{} as any,
{} as any
)
);
expect(nxArgs.parallel).toEqual(3);
});
});
});
21 changes: 13 additions & 8 deletions packages/nx/src/utils/command-line-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,30 @@ export function splitArgsIntoNxArgsAndOverrides(

normalizeNxArgsRunner(nxArgs, nxJson, options);

nxArgs['parallel'] = readParallelFromArgsAndEnv(args);

return { nxArgs, overrides } as any;
}

export function readParallelFromArgsAndEnv(args: { [k: string]: any }) {
if (args['parallel'] === 'false' || args['parallel'] === false) {
nxArgs['parallel'] = 1;
return 1;
} else if (
args['parallel'] === 'true' ||
args['parallel'] === true ||
args['parallel'] === '' ||
process.env.NX_PARALLEL // dont require passing --parallel if NX_PARALLEL is set
// dont require passing --parallel if NX_PARALLEL is set, but allow overriding it
(process.env.NX_PARALLEL && args['parallel'] === undefined)
) {
nxArgs['parallel'] = Number(
nxArgs['maxParallel'] ||
nxArgs['max-parallel'] ||
return Number(
args['maxParallel'] ||
args['max-parallel'] ||
process.env.NX_PARALLEL ||
3
);
} else if (args['parallel'] !== undefined) {
nxArgs['parallel'] = Number(args['parallel']);
return Number(args['parallel']);
}

return { nxArgs, overrides } as any;
}

function normalizeNxArgsRunner(
Expand Down

0 comments on commit 6ab3bb8

Please sign in to comment.