fix(@angular-devkit/build-angular): exclude .map files from budget … (#12012)

* fix(@angular-devkit/build-angular): exclude `.map` files from budget calculations

Closes #11999
This commit is contained in:
Alan Agius 2018-08-28 03:12:04 +02:00 committed by vikerman
parent 62e72fea38
commit 1730c79b99
2 changed files with 40 additions and 2 deletions

View File

@ -64,6 +64,7 @@ class InitialCalculator extends Calculator {
const initialChunks = this.compilation.chunks.filter(chunk => chunk.isOnlyInitial());
const size: number = initialChunks
.reduce((files, chunk) => [...files, ...chunk.files], [])
.filter((file: string) => !file.endsWith('.map'))
.map((file: string) => this.compilation.assets[file].size())
.reduce((total: number, size: number) => total + size, 0);
return [{size, label: 'initial'}];
@ -76,7 +77,7 @@ class InitialCalculator extends Calculator {
class AllScriptCalculator extends Calculator {
calculate() {
const size: number = Object.keys(this.compilation.assets)
.filter(key => /\.js$/.test(key))
.filter(key => key.endsWith('.js'))
.map(key => this.compilation.assets[key])
.map(asset => asset.size())
.reduce((total: number, size: number) => total + size, 0);
@ -90,6 +91,7 @@ class AllScriptCalculator extends Calculator {
class AllCalculator extends Calculator {
calculate() {
const size: number = Object.keys(this.compilation.assets)
.filter(key => !key.endsWith('.map'))
.map(key => this.compilation.assets[key].size())
.reduce((total: number, size: number) => total + size, 0);
return [{size, label: 'total'}];
@ -102,7 +104,7 @@ class AllCalculator extends Calculator {
class AnyScriptCalculator extends Calculator {
calculate() {
return Object.keys(this.compilation.assets)
.filter(key => /\.js$/.test(key))
.filter(key => key.endsWith('.js'))
.map(key => {
const asset = this.compilation.assets[key];
return {
@ -119,6 +121,7 @@ class AnyScriptCalculator extends Calculator {
class AnyCalculator extends Calculator {
calculate() {
return Object.keys(this.compilation.assets)
.filter(key => !key.endsWith('.map'))
.map(key => {
const asset = this.compilation.assets[key];
return {

View File

@ -54,4 +54,39 @@ describe('Browser Builder bundle budgets', () => {
tap(() => expect(logger.includes('WARNING')).toBe(true)),
).toPromise().then(done, done.fail);
});
describe(`should ignore '.map' files`, () => {
it(`when 'intial' budget`, (done) => {
const overrides = {
optimization: true,
budgets: [{ type: 'initial', maximumError: '1mb' }],
};
runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout * 2).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
).toPromise().then(done, done.fail);
});
it(`when 'all' budget`, (done) => {
const overrides = {
optimization: true,
budgets: [{ type: 'all', maximumError: '1mb' }],
};
runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout * 2).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
).toPromise().then(done, done.fail);
});
it(`when 'any' budget`, (done) => {
const overrides = {
optimization: true,
budgets: [{ type: 'any', maximumError: '1mb' }],
};
runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout * 2).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
).toPromise().then(done, done.fail);
});
});
});