Skip to content

Commit 2f707b9

Browse files
authored
Merge pull request microsoft#1283 from microsoft/octogonz/rush-issue1282
[rush] Fix an issue where "rush build" ignored changes for projects with an empty build script
2 parents 4637b27 + 01f7a5c commit 2f707b9

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export interface ITaskDefinition {
2121
*/
2222
isIncrementalBuildAllowed: boolean;
2323

24+
/**
25+
* Assigned by execute(). True if the build script was an empty string. Operationally an empty string is
26+
* like a shell command that succeeds instantly, but e.g. it would be odd to report build time statistics for it.
27+
*/
28+
hadEmptyScript: boolean;
29+
2430
/**
2531
* Method to be executed for the task.
2632
*/

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class ProjectTask implements ITaskDefinition {
4242
}
4343

4444
public isIncrementalBuildAllowed: boolean;
45+
public hadEmptyScript: boolean = false;
4546

4647
private _hasWarningOrError: boolean;
4748
private _rushProject: RushConfigurationProject;
@@ -64,6 +65,9 @@ export class ProjectTask implements ITaskDefinition {
6465
public execute(writer: ITaskWriter): Promise<TaskStatus> {
6566
try {
6667
const taskCommand: string = this._getScriptToRun();
68+
if (!taskCommand) {
69+
this.hadEmptyScript = true;
70+
}
6771
const deps: IPackageDependencies | undefined = this._getPackageDependencies(taskCommand, writer);
6872
return this._executeTask(taskCommand, writer, deps);
6973
} catch (error) {
@@ -128,9 +132,15 @@ export class ProjectTask implements ITaskDefinition {
128132
FileSystem.deleteFile(currentDepsPath);
129133

130134
if (!taskCommand) {
131-
// tslint:disable-next-line:max-line-length
132-
writer.writeLine(`The task command ${this._commandToRun} was registered in the package.json but is blank, so no action will be taken.`);
133-
return Promise.resolve(TaskStatus.Skipped);
135+
writer.writeLine(`The task command ${this._commandToRun} was registered in the package.json but is blank,`
136+
+ ` so no action will be taken.`);
137+
138+
// Write deps on success.
139+
if (currentPackageDeps) {
140+
JsonFile.save(currentPackageDeps, currentDepsPath);
141+
}
142+
143+
return Promise.resolve(TaskStatus.Success);
134144
}
135145

136146
// Run the task
@@ -166,7 +176,7 @@ export class ProjectTask implements ITaskDefinition {
166176

167177
return new Promise((resolve: (status: TaskStatus) => void, reject: (error: TaskError) => void) => {
168178
task.on('close', (code: number) => {
169-
this._writeLogsToDisk(writer);
179+
this._writeLogsToDisk(writer);
170180

171181
if (code !== 0) {
172182
reject(new TaskError('error', `Returned error code: ${code}`));

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,13 @@ export class TaskRunner {
272272
* Marks a task as being completed, and removes it from the dependencies list of all its dependents
273273
*/
274274
private _markTaskAsSuccess(task: ITask): void {
275-
this._terminal.writeLine(Colors.green(`${this._getCurrentCompletedTaskString()}`
275+
if (task.hadEmptyScript) {
276+
this._terminal.writeLine(Colors.green(`${this._getCurrentCompletedTaskString()}`
277+
+ `[${task.name}] had an empty script`));
278+
} else {
279+
this._terminal.writeLine(Colors.green(`${this._getCurrentCompletedTaskString()}`
276280
+ `[${task.name}] completed successfully in ${task.stopwatch.toString()}`));
281+
}
277282
task.status = TaskStatus.Success;
278283

279284
task.dependents.forEach((dependent: ITask) => {
@@ -417,7 +422,7 @@ export class TaskRunner {
417422
case TaskStatus.SuccessWithWarning:
418423
case TaskStatus.Blocked:
419424
case TaskStatus.Failure:
420-
if (task.stopwatch) {
425+
if (task.stopwatch && !task.hadEmptyScript) {
421426
const time: string = task.stopwatch.toString();
422427
this._terminal.writeLine(headingColor(`${task.name} (${time})`));
423428
} else {

apps/rush-lib/src/logic/taskRunner/test/TaskRunner.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function createDummyTask(name: string, action?: () => void): ITaskDefinition {
1414
action();
1515
}
1616
return Promise.resolve(TaskStatus.Success);
17-
}
17+
},
18+
hadEmptyScript: false
1819
};
1920
}
2021

@@ -95,7 +96,8 @@ describe('TaskRunner', () => {
9596
writer.write('Build step 1' + EOL);
9697
writer.writeError('Error: step 1 failed' + EOL);
9798
return Promise.resolve(TaskStatus.Failure);
98-
}
99+
},
100+
hadEmptyScript: false
99101
});
100102
return taskRunner
101103
.execute()
@@ -117,7 +119,8 @@ describe('TaskRunner', () => {
117119
writer.write('Build step 1' + EOL);
118120
writer.write('Error: step 1 failed' + EOL);
119121
return Promise.resolve(TaskStatus.Failure);
120-
}
122+
},
123+
hadEmptyScript: false
121124
});
122125
return taskRunner
123126
.execute()
@@ -139,7 +142,8 @@ describe('TaskRunner', () => {
139142
writer.write(` - unit #${i};${EOL}`);
140143
}
141144
return Promise.resolve(TaskStatus.Failure);
142-
}
145+
},
146+
hadEmptyScript: false
143147
});
144148
return taskRunner
145149
.execute()
@@ -162,7 +166,8 @@ describe('TaskRunner', () => {
162166
writer.writeError(` - error #${i}; ${EOL}`);
163167
}
164168
return Promise.resolve(TaskStatus.Failure);
165-
}
169+
},
170+
hadEmptyScript: false
166171
});
167172
return taskRunner
168173
.execute()
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 build\" ignored changes to a project with an empty build script (GitHub #1282)",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "4673363+octogonz@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)