Skip to content

Commit a92078f

Browse files
ocombehansl
authored andcommitted
fix(@angular/cli): throw xi18n errors
Fixes #8065
1 parent a7f2e7f commit a92078f

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

packages/@angular/cli/tasks/extract-i18n.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as webpack from 'webpack';
33
import { AngularCompilerPlugin } from '@ngtools/webpack';
44
import { XI18nWebpackConfig } from '../models/webpack-xi18n-config';
55
import { getAppFromConfig } from '../utilities/app-utils';
6+
import {getWebpackStatsConfig} from '../models/webpack-configs';
7+
import {statsErrorsToString, statsWarningsToString} from '../utilities/stats';
68

79
const Task = require('../ember-cli/lib/models/task');
810
const MemoryFS = require('memory-fs');
@@ -34,27 +36,26 @@ export const Extracti18nTask = Task.extend({
3436

3537
const webpackCompiler = webpack(config);
3638
webpackCompiler.outputFileSystem = new MemoryFS();
39+
const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose);
3740

3841
return new Promise((resolve, reject) => {
3942
const callback: webpack.compiler.CompilerCallback = (err, stats) => {
4043
if (err) {
4144
return reject(err);
4245
}
4346

47+
const json = stats.toJson('verbose');
48+
if (stats.hasWarnings()) {
49+
this.ui.writeLine(statsWarningsToString(json, statsConfig));
50+
}
4451
if (stats.hasErrors()) {
45-
reject();
52+
reject(statsErrorsToString(json, statsConfig));
4653
} else {
4754
resolve();
4855
}
4956
};
5057

5158
webpackCompiler.run(callback);
52-
})
53-
.catch((err: Error) => {
54-
if (err) {
55-
this.ui.writeError('\nAn error occured during the i18n extraction:\n'
56-
+ ((err && err.stack) || err));
57-
}
5859
});
5960
}
6061
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { ng } from '../../utils/process';
2+
import { writeFile } from '../../utils/fs';
3+
import { expectToFail } from '../../utils/utils';
4+
import { join } from 'path';
5+
6+
export default function() {
7+
return ng('generate', 'component', 'i18n-test')
8+
.then(() => writeFile(
9+
join('src/app/i18n-test', 'i18n-test.component.html'),
10+
'<p i18n>Hello world <span i18n>inner</span></p>'))
11+
.then(() => expectToFail(() => ng('xi18n')))
12+
.then(({ message }) => {
13+
if (!message.includes('Could not mark an element as' +
14+
' translatable inside a translatable section')) {
15+
throw new Error(`Expected i18n extraction error, got this instead:\n${message}`);
16+
}
17+
});
18+
}

0 commit comments

Comments
 (0)