Skip to content

Commit 1a1efd9

Browse files
authored
Merge pull request microsoft#789 from Microsoft/pgonzal/fix-rush-help
[rush] Improve command-line help for "rush build" and "rush rebuild"
2 parents 28fc021 + 47ee702 commit 1a1efd9

6 files changed

Lines changed: 76 additions & 33 deletions

File tree

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,31 @@ export class RushCommandLineParser extends CommandLineParser {
117117
}
118118

119119
private _populateScriptActions(): void {
120-
if (!this.rushConfiguration) {
121-
return;
122-
}
120+
let commandLineConfiguration: CommandLineConfiguration | undefined = undefined;
123121

124-
const commandLineConfigFile: string = path.join(
125-
this.rushConfiguration.commonRushConfigFolder, RushConstants.commandLineFilename
126-
);
127-
const commandLineConfiguration: CommandLineConfiguration
128-
= CommandLineConfiguration.loadFromFileOrDefault(commandLineConfigFile);
122+
// If there is not a rush.json file, we still want "build" and "rebuild" to appear in the
123+
// command-line help
124+
if (this.rushConfiguration) {
125+
const commandLineConfigFile: string = path.join(
126+
this.rushConfiguration.commonRushConfigFolder, RushConstants.commandLineFilename
127+
);
129128

130-
const documentationForBuild: string = 'The Rush build command assumes that the package.json file for each'
131-
+ ' project contains a "scripts" entry for "npm run build". It invokes'
132-
+ ' this commands to build each project. Projects are built in parallel where'
133-
+ ' possible, but always respecting the dependency graph for locally linked projects.'
134-
+ ' The number of simultaneous processes will be based on the number of machine cores'
135-
+ ' unless overridden by the --parallelism flag.';
129+
commandLineConfiguration = CommandLineConfiguration.loadFromFileOrDefault(commandLineConfigFile);
130+
}
136131

137132
// always create a build and a rebuild command
138133
this.addAction(new BulkScriptAction({
139134
actionName: 'build',
140135
summary: '(EXPERIMENTAL) Build all projects that haven\'t been built, or have changed since they were last '
141136
+ 'built.',
142-
documentation: documentationForBuild,
143-
137+
documentation: 'This command is similar to "rush rebuild", except that "rush build" performs'
138+
+ ' an incremental build. In other words, it only builds projects whose source files have'
139+
+ ' changed since the last successful build. The analysis requires a Git working tree, and'
140+
+ ' only considers source files that are tracked by Git and whose path is under the project folder.'
141+
+ ' (For more details about this algorithm, see the documentation for the "package-deps-hash"'
142+
+ ' NPM package.) The incremental build state is tracked in a file "package-deps.json" which should'
143+
+ ' NOT be added to Git. The build command is tracked by the "arguments" field in this JSON file;'
144+
+ ' a full rebuild is forced whenever the command has changed (e.g. "--production" or not).',
144145
parser: this,
145146
commandLineConfiguration: commandLineConfiguration,
146147

@@ -151,15 +152,25 @@ export class RushCommandLineParser extends CommandLineParser {
151152
this.addAction(new BulkScriptAction({
152153
actionName: 'rebuild',
153154
summary: 'Clean and rebuild the entire set of projects',
154-
documentation: documentationForBuild,
155-
155+
documentation: 'This command assumes that the package.json file for each project contains'
156+
+ ' a "scripts" entry for "npm run build" that performs a full clean build.'
157+
+ ' Rush invokes this script to build each project that is registered in rush.json.'
158+
+ ' Projects are built in parallel where possible, but always respecting the dependency'
159+
+ ' graph for locally linked projects. The number of simultaneous processes will be'
160+
+ ' based on the number of machine cores unless overridden by the --parallelism flag.'
161+
+ ' (For an incremental build, see "rush build" instead of "rush rebuild".)',
156162
parser: this,
157163
commandLineConfiguration: commandLineConfiguration,
158164

159165
enableParallelism: true,
160166
ignoreMissingScript: false
161167
}));
162168

169+
if (!commandLineConfiguration) {
170+
// If there is not a rush.json file, so don't attempt to define custom commands/parameters
171+
return;
172+
}
173+
163174
// Register each custom command
164175
for (const command of commandLineConfiguration.commands) {
165176
if (this.tryGetAction(command.name)) {

‎apps/rush-lib/src/cli/scriptActions/BaseScriptAction.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { RushConstants } from '../../logic/RushConstants';
1111
* Constructor parameters for BaseScriptAction
1212
*/
1313
export interface IBaseScriptActionOptions extends IBaseRushActionOptions {
14-
commandLineConfiguration: CommandLineConfiguration;
14+
commandLineConfiguration: CommandLineConfiguration | undefined;
1515
}
1616

1717
/**
@@ -25,7 +25,7 @@ export interface IBaseScriptActionOptions extends IBaseRushActionOptions {
2525
* The two subclasses are BulkScriptAction and GlobalScriptAction.
2626
*/
2727
export abstract class BaseScriptAction extends BaseRushAction {
28-
protected readonly _commandLineConfiguration: CommandLineConfiguration;
28+
protected readonly _commandLineConfiguration: CommandLineConfiguration | undefined;
2929
protected readonly customParameters: CommandLineParameter[] = [];
3030

3131
constructor(
@@ -36,6 +36,10 @@ export abstract class BaseScriptAction extends BaseRushAction {
3636
}
3737

3838
protected defineScriptParameters(): void {
39+
if (!this._commandLineConfiguration) {
40+
return;
41+
}
42+
3943
// Find any parameters that are associated with this command
4044
for (const parameter of this._commandLineConfiguration.parameters) {
4145
let associated: boolean = false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class BulkScriptAction extends BaseScriptAction {
6969

7070
const isQuietMode: boolean = !(this._verboseParameter.value);
7171

72-
// if this is parallizable, then use the value from the flag (undefined or a number),
72+
// if this is parallelizable, then use the value from the flag (undefined or a number),
7373
// if parallelism is not enabled, then restrict to 1 core
7474
const parallelism: string | undefined = this._isParallelismEnabled()
7575
? this._parallelismParameter!.value

‎apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ exports[`CommandLineHelp prints the help for "rush build" 1`] = `
5656
[-o] [-s] [-m]
5757
5858
59-
The Rush build command assumes that the package.json file for each project
60-
contains a \\"scripts\\" entry for \\"npm run build\\". It invokes this commands to
61-
build each project. Projects are built in parallel where possible, but always
62-
respecting the dependency graph for locally linked projects. The number of
63-
simultaneous processes will be based on the number of machine cores unless
64-
overridden by the --parallelism flag.
59+
This command is similar to \\"rush rebuild\\", except that \\"rush build\\" performs
60+
an incremental build. In other words, it only builds projects whose source
61+
files have changed since the last successful build. The analysis requires a
62+
Git working tree, and only considers source files that are tracked by Git and
63+
whose path is under the project folder. (For more details about this
64+
algorithm, see the documentation for the \\"package-deps-hash\\" NPM package.)
65+
The incremental build state is tracked in a file \\"package-deps.json\\" which
66+
should NOT be added to Git. The build command is tracked by the \\"arguments\\"
67+
field in this JSON file; a full rebuild is forced whenever the command has
68+
changed (e.g. \\"--production\\" or not).
6569
6670
Optional arguments:
6771
-h, --help Show this help message and exit.
@@ -336,12 +340,14 @@ exports[`CommandLineHelp prints the help for "rush rebuild" 1`] = `
336340
[-v] [-s] [-m]
337341
338342
339-
The Rush build command assumes that the package.json file for each project
340-
contains a \\"scripts\\" entry for \\"npm run build\\". It invokes this commands to
341-
build each project. Projects are built in parallel where possible, but always
342-
respecting the dependency graph for locally linked projects. The number of
343-
simultaneous processes will be based on the number of machine cores unless
344-
overridden by the --parallelism flag.
343+
This command assumes that the package.json file for each project contains a
344+
\\"scripts\\" entry for \\"npm run build\\" that performs a full clean build. Rush
345+
invokes this script to build each project that is registered in rush.json.
346+
Projects are built in parallel where possible, but always respecting the
347+
dependency graph for locally linked projects. The number of simultaneous
348+
processes will be based on the number of machine cores unless overridden by
349+
the --parallelism flag. (For an incremental build, see \\"rush build\\" instead
350+
of \\"rush rebuild\\".)
345351
346352
Optional arguments:
347353
-h, --help Show this help message and exit.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Fix an issue where \"rush -h\" didn't print help for the \"build\" and \"rebuild\" commands, unless invoked under a Rush folder",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Improve command-line help for \"rush build\"",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)