Skip to content

Commit

Permalink
fix(@angular-devkit/build-webpack): provide more complete compilation…
Browse files Browse the repository at this point in the history
… stats
  • Loading branch information
clydin authored and vikerman committed Sep 26, 2019
1 parent 8dd67cd commit 1930bd5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
13 changes: 3 additions & 10 deletions packages/angular_devkit/build_webpack/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as path from 'path';
import * as webpack from 'webpack';

export interface EmittedFiles {
id?: string;
name?: string;
file: string;
initial: boolean;
Expand All @@ -20,19 +21,11 @@ export interface EmittedFiles {
export function getEmittedFiles(compilation: webpack.compilation.Compilation): EmittedFiles[] {
const files: EmittedFiles[] = [];

// entrypoints might have multiple outputs
// such as runtime.js
for (const [name, entrypoint] of compilation.entrypoints) {
const entryFiles: string[] = (entrypoint && entrypoint.getFiles()) || [];
for (const file of entryFiles) {
files.push({ name, file, extension: path.extname(file), initial: true });
}
}

// adds all chunks to the list of emitted files such as lazy loaded modules
for (const chunk of Object.values(compilation.chunks)) {
for (const chunk of compilation.chunks as webpack.compilation.Chunk[]) {
for (const file of chunk.files as string[]) {
files.push({
id: chunk.id.toString(),
name: chunk.name,
file,
extension: path.extname(file),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('Dev Server Builder', () => {

expect(output.success).toBe(true);
expect(output.emittedFiles).toContain({
id: 'main',
name: 'main',
initial: true,
file: 'bundle.js',
Expand Down
2 changes: 2 additions & 0 deletions packages/angular_devkit/build_webpack/src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface WebpackFactory {

export type BuildResult = BuilderOutput & {
emittedFiles?: EmittedFiles[];
webpackStats?: webpack.Stats.ToJsonOutput;
};

export function runWebpack(
Expand Down Expand Up @@ -59,6 +60,7 @@ export function runWebpack(

obs.next({
success: !stats.hasErrors(),
webpackStats: stats.toJson(),
emittedFiles: getEmittedFiles(stats.compilation),
} as unknown as BuildResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('Webpack Builder basic test', () => {

expect(output.success).toBe(true);
expect(output.emittedFiles).toContain({
id: 'main',
name: 'main',
initial: true,
file: 'bundle.js',
Expand Down Expand Up @@ -94,8 +95,8 @@ describe('Webpack Builder basic test', () => {

expect(output.success).toBe(true);
expect(output.emittedFiles).toContain(
{ name: 'main', initial: true, file: 'main.js', extension: '.js' },
{ name: 'polyfills', initial: true, file: 'polyfills.js', extension: '.js' },
{ id: 'main', name: 'main', initial: true, file: 'main.js', extension: '.js' },
{ id: 'polyfills', name: 'polyfills', initial: true, file: 'polyfills.js', extension: '.js' },
);

await run.stop();
Expand Down

0 comments on commit 1930bd5

Please sign in to comment.