Skip to content

Commit 68bc0c7

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
fix(@angular-devkit/build-angular): extract i18n should only show warnings/errors
Fixes #14373
1 parent 5f80702 commit 68bc0c7

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

packages/angular_devkit/build_angular/src/extract-i18n/index.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
createBuilder,
1111
targetFromTargetString,
1212
} from '@angular-devkit/architect';
13-
import { runWebpack } from '@angular-devkit/build-webpack';
13+
import { WebpackLoggingCallback, runWebpack } from '@angular-devkit/build-webpack';
1414
import { JsonObject } from '@angular-devkit/core';
1515
import * as path from 'path';
1616
import * as webpack from 'webpack';
@@ -20,6 +20,7 @@ import {
2020
getStatsConfig,
2121
getStylesConfig,
2222
} from '../angular-cli-files/models/webpack-configs';
23+
import { statsErrorsToString, statsWarningsToString } from '../angular-cli-files/utilities/stats';
2324
import { Schema as BrowserBuilderOptions } from '../browser/schema';
2425
import { Version } from '../utils/version';
2526
import { generateBrowserWebpackConfigFromContext } from '../utils/webpack-browser-config';
@@ -91,7 +92,19 @@ async function execute(options: ExtractI18nBuilderOptions, context: BuilderConte
9192
],
9293
);
9394

94-
return runWebpack(config[0], context).toPromise();
95+
const logging: WebpackLoggingCallback = (stats, config) => {
96+
const json = stats.toJson({ errors: true, warnings: true });
97+
98+
if (stats.hasWarnings()) {
99+
context.logger.warn(statsWarningsToString(json, config.stats));
100+
}
101+
102+
if (stats.hasErrors()) {
103+
context.logger.error(statsErrorsToString(json, config.stats));
104+
}
105+
};
106+
107+
return runWebpack(config[0], context, { logging }).toPromise();
95108
}
96109

97110
export default createBuilder<JsonObject & ExtractI18nBuilderOptions>(execute);

packages/angular_devkit/build_angular/test/extract-i18n/works_spec_large.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('Extract i18n Target', () => {
2222

2323
afterEach(() => host.restore().toPromise());
2424

25-
it('works', async () => {
25+
it('generates an extraction file', async () => {
2626
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
2727

2828
const run = await architect.scheduleTarget(extractI18nTargetSpec);
@@ -40,6 +40,20 @@ describe('Extract i18n Target', () => {
4040
}
4141
}, 30000);
4242

43+
it('does not show full build logs', async () => {
44+
const logger = new TestLogger('i18n');
45+
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');
46+
47+
const run = await architect.scheduleTarget(extractI18nTargetSpec);
48+
49+
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
50+
51+
await run.stop();
52+
53+
expect(logger.includes('Chunk Names')).toBe(false);
54+
expect(logger.includes('[emitted]')).toBe(false);
55+
}, 30000);
56+
4357
it('shows errors', async () => {
4458
const logger = new TestLogger('i18n-errors');
4559
host.appendToFile('src/app/app.component.html',

0 commit comments

Comments
 (0)