Skip to content

Commit a912320

Browse files
committed
Add support for a -p max argument to rush
1 parent d09563d commit a912320

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎apps/rush-lib/src/cli/actions/CustomRushAction.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import {
1818
CommandLineFlagParameter,
19-
CommandLineIntegerParameter,
19+
CommandLineStringParameter,
2020
CommandLineStringListParameter,
2121
CommandLineOptionParameter,
2222
ICommandLineActionOptions
@@ -39,7 +39,7 @@ export class CustomRushAction extends BaseRushAction {
3939
private _fromFlag: CommandLineStringListParameter;
4040
private _toFlag: CommandLineStringListParameter;
4141
private _verboseParameter: CommandLineFlagParameter;
42-
private _parallelismParameter: CommandLineIntegerParameter | undefined;
42+
private _parallelismParameter: CommandLineStringParameter | undefined;
4343

4444
constructor(private _parser: RushCommandLineParser,
4545
options: ICommandLineActionOptions,
@@ -75,9 +75,9 @@ export class CustomRushAction extends BaseRushAction {
7575

7676
// if this is parallizable, then use the value from the flag (undefined or a number),
7777
// if this is not parallelized, then use 1 core
78-
const parallelism: number | undefined = this._isParallelized()
78+
const parallelism: string | undefined = this._isParallelized()
7979
? this._parallelismParameter!.value
80-
: 1;
80+
: '1';
8181

8282
// collect all custom flags here
8383
const customFlags: string[] = [];
@@ -127,7 +127,7 @@ export class CustomRushAction extends BaseRushAction {
127127

128128
protected onDefineParameters(): void {
129129
if (this._isParallelized()) {
130-
this._parallelismParameter = this.defineIntegerParameter({
130+
this._parallelismParameter = this.defineStringParameter({
131131
parameterLongName: '--parallelism',
132132
parameterShortName: '-p',
133133
key: 'COUNT',

‎apps/rush-lib/src/cli/logic/TaskSelector.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ITaskSelectorConstructor {
1515
commandToRun: string;
1616
customFlags: string[];
1717
isQuietMode: boolean;
18-
parallelism: number;
18+
parallelism: string;
1919
isIncrementalBuildAllowed: boolean;
2020
changedProjectsOnly: boolean;
2121
}

‎apps/rush-lib/src/cli/taskRunner/TaskRunner.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,36 @@ export default class TaskRunner {
3131
private _completedTasks: number;
3232

3333
constructor(quietMode: boolean,
34-
parallelism: number | undefined,
34+
parallelism: string |undefined,
3535
changedProjectsOnly: boolean) {
3636
this._tasks = new Map<string, ITask>();
3737
this._buildQueue = [];
3838
this._quietMode = quietMode;
3939
this._hasAnyFailures = false;
4040
this._changedProjectsOnly = changedProjectsOnly;
4141

42+
const numberOfCores: number = os.cpus().length;
43+
4244
if (parallelism) {
43-
this._parallelism = parallelism;
44-
} else {
45+
if (parallelism === 'max') {
46+
this._parallelism = numberOfCores;
47+
} else {
48+
const parallelismInt: number = parseInt(parallelism, 10);
49+
50+
if (isNaN(parallelismInt)) {
51+
throw new Error(`Invalid parallelism value of '${parallelism}', expected a number or 'max'`);
52+
}
53+
54+
this._parallelism = parallelismInt;
55+
}
56+
57+
} else {
4558
// If an explicit parallelism number wasn't provided, then choose a sensible
4659
// default.
47-
const numberOfCores: number = os.cpus().length;
48-
4960
if (os.platform() === 'win32') {
5061
// On desktop Windows, some people have complained that their system becomes
5162
// sluggish if Rush is using all the CPU cores. Leave one thread for
52-
// other operations.
63+
// other operations. For CI environments, you can use the "max" argument to use all available cores.
5364
this._parallelism = Math.max(numberOfCores - 1, 1);
5465
} else {
5566
// Unix-like operating systems have more balanced scheduling, so default

0 commit comments

Comments
 (0)