Skip to content

Commit 2180c88

Browse files
authored
Merge pull request microsoft#1825 from iclanton/ianc/rebuild
[rush] When the "rebuild" command is overridden, run the "rebuild" script.
2 parents 98fee0d + 9e12377 commit 2180c88

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

apps/rush-lib/assets/rush-init/common/config/rush/command-line.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
* The name should be comprised of lower case words separated by hyphens or colons. The name should include an
3030
* English verb (e.g. "deploy"). Use a hyphen to separate words (e.g. "upload-docs"). A group of related commands
3131
* can be prefixed with a colon (e.g. "docs:generate", "docs:deploy", "docs:serve", etc).
32+
*
33+
* Note that if the "rebuild" command is overridden here, it becomes separated from the "build" command
34+
* and will call the "rebuild" script instead of the "build" script.
3235
*/
3336
"name": "my-bulk-command",
3437

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ export class RushCommandLineParser extends CommandLineParser {
200200
}
201201

202202
if (!this.tryGetAction(RushConstants.rebuildCommandName)) {
203-
this._addCommandLineConfigAction(commandLineConfiguration, CommandLineConfiguration.defaultRebuildCommandJson);
203+
this._addCommandLineConfigAction(
204+
commandLineConfiguration,
205+
CommandLineConfiguration.defaultRebuildCommandJson,
206+
RushConstants.buildCommandName
207+
);
204208
}
205209
}
206210

@@ -217,7 +221,8 @@ export class RushCommandLineParser extends CommandLineParser {
217221

218222
private _addCommandLineConfigAction(
219223
commandLineConfiguration: CommandLineConfiguration | undefined,
220-
command: CommandJson
224+
command: CommandJson,
225+
commandToRun?: string
221226
): void {
222227
if (this.tryGetAction(command.name)) {
223228
throw new Error(`${RushConstants.commandLineFilename} defines a command "${command.name}"`
@@ -231,9 +236,9 @@ export class RushCommandLineParser extends CommandLineParser {
231236
this.addAction(new BulkScriptAction({
232237
actionName: command.name,
233238

234-
// The rush rebuild and rush build command invoke the same NPM script because they share the same
235-
// package-deps-hash state.
236-
commandToRun: command.name === RushConstants.rebuildCommandName ? 'build' : undefined,
239+
// By default, the "rebuild" action runs the "build" script. However, if the command-line.json file
240+
// overrides "rebuild," the "rebuild" script should be run.
241+
commandToRun: commandToRun,
237242

238243
summary: command.summary,
239244
documentation: command.description || command.summary,

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,28 @@
44
import * as os from 'os';
55
import * as colors from 'colors';
66

7-
import {
8-
Event
9-
} from '../../index';
10-
117
import {
128
CommandLineFlagParameter,
139
CommandLineStringParameter,
1410
CommandLineStringListParameter,
1511
CommandLineParameterKind
1612
} from '@rushstack/ts-command-line';
13+
import {
14+
FileSystem,
15+
PackageJsonLookup,
16+
IPackageJson
17+
} from '@rushstack/node-core-library';
1718

19+
import { Event } from '../../index';
1820
import { SetupChecks } from '../../logic/SetupChecks';
1921
import { TaskSelector } from '../../logic/TaskSelector';
2022
import { Stopwatch } from '../../utilities/Stopwatch';
2123
import { AlreadyReportedError } from '../../utilities/AlreadyReportedError';
2224
import { BaseScriptAction, IBaseScriptActionOptions } from './BaseScriptAction';
23-
import {
24-
FileSystem,
25-
PackageJsonLookup,
26-
IPackageJson
27-
} from '@rushstack/node-core-library';
2825
import { TaskRunner } from '../../logic/taskRunner/TaskRunner';
2926
import { TaskCollection } from '../../logic/taskRunner/TaskCollection';
3027
import { Utilities } from '../../utilities/Utilities';
28+
import { RushConstants } from '../../logic/RushConstants';
3129

3230
/**
3331
* Constructor parameters for BulkScriptAction.
@@ -255,7 +253,7 @@ export class BulkScriptAction extends BaseScriptAction {
255253
}
256254

257255
private _doBeforeTask(): void {
258-
if (this.actionName !== 'build' && this.actionName !== 'rebuild') {
256+
if (this.actionName !== RushConstants.buildCommandName && this.actionName !== RushConstants.rebuildCommandName) {
259257
// Only collects information for built-in tasks like build or rebuild.
260258
return;
261259
}
@@ -266,7 +264,7 @@ export class BulkScriptAction extends BaseScriptAction {
266264
}
267265

268266
private _doAfterTask(stopwatch: Stopwatch, success: boolean): void {
269-
if (this.actionName !== 'build' && this.actionName !== 'rebuild') {
267+
if (this.actionName !== RushConstants.buildCommandName && this.actionName !== RushConstants.rebuildCommandName) {
270268
// Only collects information for built-in tasks like build or rebuild.
271269
return;
272270
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ describe('RushCommandLineParser', () => {
199199
});
200200

201201
describe(`'rebuild' action`, () => {
202-
it(`executes the package's 'build' script`, () => {
202+
it(`executes the package's 'rebuild' script`, () => {
203203
const repoName: string = 'overrideRebuildAndRunRebuildActionRepo';
204204
const instance: IParserTestInstance = getCommandLineParserInstance(repoName, 'rebuild');
205205

@@ -211,7 +211,7 @@ describe('RushCommandLineParser', () => {
211211
expect(packageCount).toEqual(2);
212212

213213
// Use regex for task name in case spaces were prepended or appended to spawned command
214-
const expectedBuildTaskRegexp: RegExp = /fake_build_task_but_works_with_mock/;
214+
const expectedBuildTaskRegexp: RegExp = /fake_REbuild_task_but_works_with_mock/;
215215

216216
// eslint-disable-next-line @typescript-eslint/no-explicit-any
217217
const firstSpawn: any[] = instance.spawnMock.mock.calls[0];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Fix a regression in Rush 5.19.0 where customizing \"rush rebuild\" would call the \"build\" script instead of the \"rebuild\" script.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "iclanton@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)