Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): extract i18n should only show war…
Browse files Browse the repository at this point in the history
…nings/errors

Fixes #14373
  • Loading branch information
clydin authored and Keen Yee Liau committed May 10, 2019
1 parent c883f67 commit 6f13a24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
17 changes: 15 additions & 2 deletions packages/angular_devkit/build_angular/src/extract-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
createBuilder,
targetFromTargetString,
} from '@angular-devkit/architect';
import { runWebpack } from '@angular-devkit/build-webpack';
import { WebpackLoggingCallback, runWebpack } from '@angular-devkit/build-webpack';
import { JsonObject } from '@angular-devkit/core';
import * as path from 'path';
import * as webpack from 'webpack';
Expand All @@ -20,6 +20,7 @@ import {
getStatsConfig,
getStylesConfig,
} from '../angular-cli-files/models/webpack-configs';
import { statsErrorsToString, statsWarningsToString } from '../angular-cli-files/utilities/stats';
import { Schema as BrowserBuilderOptions } from '../browser/schema';
import { Version } from '../utils/version';
import { generateBrowserWebpackConfigFromContext } from '../utils/webpack-browser-config';
Expand Down Expand Up @@ -91,7 +92,19 @@ async function execute(options: ExtractI18nBuilderOptions, context: BuilderConte
],
);

return runWebpack(config[0], context).toPromise();
const logging: WebpackLoggingCallback = (stats, config) => {
const json = stats.toJson({ errors: true, warnings: true });

if (stats.hasWarnings()) {
context.logger.warn(statsWarningsToString(json, config.stats));
}

if (stats.hasErrors()) {
context.logger.error(statsErrorsToString(json, config.stats));
}
};

return runWebpack(config[0], context, { logging }).toPromise();
}

export default createBuilder<JsonObject & ExtractI18nBuilderOptions>(execute);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Extract i18n Target', () => {

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

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

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

it('does not show full build logs', async () => {
const logger = new TestLogger('i18n');
host.appendToFile('src/app/app.component.html', '<p i18n>i18n test</p>');

const run = await architect.scheduleTarget(extractI18nTargetSpec);

await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));

await run.stop();

expect(logger.includes('Chunk Names')).toBe(false);
expect(logger.includes('[emitted]')).toBe(false);
}, 30000);

it('shows errors', async () => {
const logger = new TestLogger('i18n-errors');
host.appendToFile('src/app/app.component.html',
Expand Down

0 comments on commit 6f13a24

Please sign in to comment.