Skip to content

Commit 1730c79

Browse files
alan-agius4vikerman
authored andcommitted
fix(@angular-devkit/build-angular): exclude .map files from budget … (#12012)
* fix(@angular-devkit/build-angular): exclude `.map` files from budget calculations Closes #11999
1 parent 62e72fe commit 1730c79

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/utilities/bundle-calculator.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class InitialCalculator extends Calculator {
6464
const initialChunks = this.compilation.chunks.filter(chunk => chunk.isOnlyInitial());
6565
const size: number = initialChunks
6666
.reduce((files, chunk) => [...files, ...chunk.files], [])
67+
.filter((file: string) => !file.endsWith('.map'))
6768
.map((file: string) => this.compilation.assets[file].size())
6869
.reduce((total: number, size: number) => total + size, 0);
6970
return [{size, label: 'initial'}];
@@ -76,7 +77,7 @@ class InitialCalculator extends Calculator {
7677
class AllScriptCalculator extends Calculator {
7778
calculate() {
7879
const size: number = Object.keys(this.compilation.assets)
79-
.filter(key => /\.js$/.test(key))
80+
.filter(key => key.endsWith('.js'))
8081
.map(key => this.compilation.assets[key])
8182
.map(asset => asset.size())
8283
.reduce((total: number, size: number) => total + size, 0);
@@ -90,6 +91,7 @@ class AllScriptCalculator extends Calculator {
9091
class AllCalculator extends Calculator {
9192
calculate() {
9293
const size: number = Object.keys(this.compilation.assets)
94+
.filter(key => !key.endsWith('.map'))
9395
.map(key => this.compilation.assets[key].size())
9496
.reduce((total: number, size: number) => total + size, 0);
9597
return [{size, label: 'total'}];
@@ -102,7 +104,7 @@ class AllCalculator extends Calculator {
102104
class AnyScriptCalculator extends Calculator {
103105
calculate() {
104106
return Object.keys(this.compilation.assets)
105-
.filter(key => /\.js$/.test(key))
107+
.filter(key => key.endsWith('.js'))
106108
.map(key => {
107109
const asset = this.compilation.assets[key];
108110
return {
@@ -119,6 +121,7 @@ class AnyScriptCalculator extends Calculator {
119121
class AnyCalculator extends Calculator {
120122
calculate() {
121123
return Object.keys(this.compilation.assets)
124+
.filter(key => !key.endsWith('.map'))
122125
.map(key => {
123126
const asset = this.compilation.assets[key];
124127
return {

packages/angular_devkit/build_angular/test/browser/bundle-budgets_spec_large.ts

+35
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,39 @@ describe('Browser Builder bundle budgets', () => {
5454
tap(() => expect(logger.includes('WARNING')).toBe(true)),
5555
).toPromise().then(done, done.fail);
5656
});
57+
58+
describe(`should ignore '.map' files`, () => {
59+
it(`when 'intial' budget`, (done) => {
60+
const overrides = {
61+
optimization: true,
62+
budgets: [{ type: 'initial', maximumError: '1mb' }],
63+
};
64+
65+
runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout * 2).pipe(
66+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
67+
).toPromise().then(done, done.fail);
68+
});
69+
70+
it(`when 'all' budget`, (done) => {
71+
const overrides = {
72+
optimization: true,
73+
budgets: [{ type: 'all', maximumError: '1mb' }],
74+
};
75+
76+
runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout * 2).pipe(
77+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
78+
).toPromise().then(done, done.fail);
79+
});
80+
81+
it(`when 'any' budget`, (done) => {
82+
const overrides = {
83+
optimization: true,
84+
budgets: [{ type: 'any', maximumError: '1mb' }],
85+
};
86+
87+
runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout * 2).pipe(
88+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
89+
).toPromise().then(done, done.fail);
90+
});
91+
});
5792
});

0 commit comments

Comments
 (0)