Skip to content

Commit

Permalink
fix(@angular/cli): when a schematic fails on commit errors fail the c…
Browse files Browse the repository at this point in the history
…ommand

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.
  • Loading branch information
hansl committed Mar 9, 2018
1 parent 5dee617 commit a9bbe2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
5 changes: 4 additions & 1 deletion packages/@angular/cli/tasks/schematic-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { concat, concatMap, ignoreElements, map } from 'rxjs/operators';
import { getCollection, getSchematic, getEngineHost, getEngine } from '../utilities/schematics';

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

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

if (opts.dryRun || error) {
if (opts.dryRun) {
return observableOf(tree);
}
return fsSink.commit(tree).pipe(
Expand Down
11 changes: 2 additions & 9 deletions tests/e2e/tests/generate/component/component-duplicate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ng } from '../../../utils/process';
import { expectToFail } from "../../../utils/utils";
import { oneLine } from 'common-tags';

export default function () {
Expand All @@ -11,13 +12,5 @@ export default function () {
in ${output.stdout}.`);
}
})
.then(() => ng('generate', 'component', 'test-component'))
.then((output) => {
if (!output.stdout.match(/error! src[\\|\/]app[\\|\/]test-component[\\|\/]test-component.component.ts already exists./)) {
throw new Error(oneLine`
Expected to match
"ERROR! src/app/test-component/test-component.ts"
in ${output.stdout}.`);
}
});
.then(() => expectToFail(() => ng('generate', 'component', 'test-component')));
}

0 comments on commit a9bbe2a

Please sign in to comment.