Skip to content

Commit a9bbe2a

Browse files
committed
fix(@angular/cli): when a schematic fails on commit errors fail the command
Before the only way it could fail was to have the schematic throw, but that does not happen when the schematic creates files that already exist (e.g.). This fixes that.
1 parent 5dee617 commit a9bbe2a

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

packages/@angular/cli/tasks/schematic-run.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { concat, concatMap, ignoreElements, map } from 'rxjs/operators';
1717
import { getCollection, getSchematic, getEngineHost, getEngine } from '../utilities/schematics';
1818

1919
const { green, red, yellow } = chalk;
20+
const SilentError = require('silent-error');
2021
const Task = require('../ember-cli/lib/models/task');
2122

2223
export interface SchematicRunOptions {
@@ -135,9 +136,11 @@ export default Task.extend({
135136
if (!error) {
136137
// Output the logging queue.
137138
loggingQueue.forEach(log => ui.writeLine(` ${log.color(log.keyword)} ${log.message}`));
139+
} else {
140+
throw new SilentError();
138141
}
139142

140-
if (opts.dryRun || error) {
143+
if (opts.dryRun) {
141144
return observableOf(tree);
142145
}
143146
return fsSink.commit(tree).pipe(
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ng } from '../../../utils/process';
2+
import { expectToFail } from "../../../utils/utils";
23
import { oneLine } from 'common-tags';
34

45
export default function () {
@@ -11,13 +12,5 @@ export default function () {
1112
in ${output.stdout}.`);
1213
}
1314
})
14-
.then(() => ng('generate', 'component', 'test-component'))
15-
.then((output) => {
16-
if (!output.stdout.match(/error! src[\\|\/]app[\\|\/]test-component[\\|\/]test-component.component.ts already exists./)) {
17-
throw new Error(oneLine`
18-
Expected to match
19-
"ERROR! src/app/test-component/test-component.ts"
20-
in ${output.stdout}.`);
21-
}
22-
});
15+
.then(() => expectToFail(() => ng('generate', 'component', 'test-component')));
2316
}

0 commit comments

Comments
 (0)