Skip to content

Commit 3c5ccff

Browse files
committed
Rebuild can be overridden.
1 parent 2582799 commit 3c5ccff

File tree

5 files changed

+20
-30
lines changed

5 files changed

+20
-30
lines changed

apps/rush-lib/src/cli/RushCommandLineParser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ export class RushCommandLineParser extends CommandLineParser {
178178
if (!this.tryGetAction('rebuild')) {
179179
this.addAction(new BulkScriptAction({
180180
actionName: 'rebuild',
181+
// To remain compatible with existing repos, `rebuild` defaults to calling the `build` command in each repo.
182+
commandToRun: 'build',
181183
summary: 'Clean and rebuild the entire set of projects',
182184
documentation: 'This command assumes that the package.json file for each project contains'
183185
+ ' a "scripts" entry for "npm run build" that performs a full clean build.'

apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import { FileSystem } from '@microsoft/node-core-library';
2828
export interface IBulkScriptActionOptions extends IBaseScriptActionOptions {
2929
enableParallelism: boolean;
3030
ignoreMissingScript: boolean;
31+
32+
/**
33+
* Optional command to run. Otherwise, use the `actionName` as the command to run.
34+
*/
35+
commandToRun?: string;
3136
}
3237

3338
/**
@@ -42,6 +47,7 @@ export interface IBulkScriptActionOptions extends IBaseScriptActionOptions {
4247
export class BulkScriptAction extends BaseScriptAction {
4348
private _enableParallelism: boolean;
4449
private _ignoreMissingScript: boolean;
50+
private _commandToRun: string;
4551

4652
private _changedProjectsOnly: CommandLineFlagParameter;
4753
private _fromFlag: CommandLineStringListParameter;
@@ -56,6 +62,7 @@ export class BulkScriptAction extends BaseScriptAction {
5662
super(options);
5763
this._enableParallelism = options.enableParallelism;
5864
this._ignoreMissingScript = options.ignoreMissingScript;
65+
this._commandToRun = options.commandToRun || options.actionName;
5966
}
6067

6168
public run(): Promise<void> {
@@ -71,7 +78,7 @@ export class BulkScriptAction extends BaseScriptAction {
7178

7279
// if this is parallelizable, then use the value from the flag (undefined or a number),
7380
// if parallelism is not enabled, then restrict to 1 core
74-
const parallelism: string | undefined = this._isParallelismEnabled()
81+
const parallelism: string | undefined = this._enableParallelism
7582
? this._parallelismParameter!.value
7683
: '1';
7784

@@ -89,7 +96,7 @@ export class BulkScriptAction extends BaseScriptAction {
8996
rushConfiguration: this.rushConfiguration,
9097
toFlags: this._mergeToProjects(),
9198
fromFlags: this._fromFlag.values,
92-
commandToRun: this.actionName,
99+
commandToRun: this._commandToRun,
93100
customParameterValues,
94101
isQuietMode,
95102
parallelism,
@@ -117,7 +124,7 @@ export class BulkScriptAction extends BaseScriptAction {
117124
}
118125

119126
protected onDefineParameters(): void {
120-
if (this._isParallelismEnabled()) {
127+
if (this._enableParallelism) {
121128
this._parallelismParameter = this.defineStringParameter({
122129
parameterLongName: '--parallelism',
123130
parameterShortName: '-p',
@@ -176,12 +183,6 @@ export class BulkScriptAction extends BaseScriptAction {
176183
return projects;
177184
}
178185

179-
private _isParallelismEnabled(): boolean {
180-
return this.actionName === 'build'
181-
|| this.actionName === 'rebuild'
182-
|| this._enableParallelism;
183-
}
184-
185186
private _doBeforeTask(): void {
186187
if (this.actionName !== 'build' && this.actionName !== 'rebuild') {
187188
// Only collects information for built-in tasks like build or rebuild.

apps/rush-lib/src/cli/test/basicAndRunBuildActionRepo/a/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"description": "Test package a",
55
"scripts": {
6-
"build": "fake_build_task_but_works_with_mock"
6+
"build": "fake_build_task_but_works_with_mock",
7+
"rebuild": "fake_REbuild_task_but_works_with_mock"
78
}
89
}

apps/rush-lib/src/cli/test/basicAndRunBuildActionRepo/b/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"description": "Test package b",
55
"scripts": {
6-
"build": "fake_build_task_but_works_with_mock"
6+
"build": "fake_build_task_but_works_with_mock",
7+
"rebuild": "fake_REbuild_task_but_works_with_mock"
78
}
89
}

apps/rush-lib/src/logic/taskRunner/ProjectTask.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,12 @@ export class ProjectTask implements ITaskDefinition {
180180
}
181181
}
182182

183-
private _isBuildCommand(): boolean {
184-
return this._commandToRun === 'build' || this._commandToRun === 'rebuild';
185-
}
186-
187183
private _getScriptToRun(): string {
188-
let script: string | undefined = undefined;
189-
if (this._isBuildCommand()) {
190-
script = this._getScriptCommand('build');
191-
192-
if (script === undefined) {
193-
// tslint:disable-next-line:max-line-length
194-
throw new Error(`The project [${this._rushProject.packageName}] does not define a 'build' command in the 'scripts' section of its package.json`);
195-
}
196-
197-
} else {
198-
script = this._getScriptCommand(this._commandToRun);
184+
const script: string | undefined = this._getScriptCommand(this._commandToRun);
199185

200-
if (script === undefined && !this._ignoreMissingScript) {
201-
// tslint:disable-next-line:max-line-length
202-
throw new Error(`The project [${this._rushProject.packageName}] does not define a '${this._commandToRun}' command in the 'scripts' section of its package.json`);
203-
}
186+
if (script === undefined && !this._ignoreMissingScript) {
187+
// tslint:disable-next-line:max-line-length
188+
throw new Error(`The project [${this._rushProject.packageName}] does not define a '${this._commandToRun}' command in the 'scripts' section of its package.json`);
204189
}
205190

206191
if (!script) {

0 commit comments

Comments
 (0)