Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): add defaults to reduce methods in…
Browse files Browse the repository at this point in the history
… bundle calculator

Fixes #17215
  • Loading branch information
alan-agius4 authored and mgechev committed Mar 13, 2020
1 parent b704eb9 commit 1a9cbd3
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,16 @@ abstract class Calculator {
} else {
// No differential builds, get the chunk size by summing its assets.
return chunk.files
.filter((file) => !file.endsWith('.map'))
.map((file: string) => {
.filter(file => !file.endsWith('.map'))
.map(file => {
const asset = this.assets.find((asset) => asset.name === file);
if (!asset) {
throw new Error(`Could not find asset for file: ${file}`);
}

return asset;
return asset.size;
})
.map((asset) => asset.size)
.reduce((l, r) => l + r);
.reduce((l, r) => l + r, 0);
}
}
}
Expand All @@ -197,8 +196,8 @@ class BundleCalculator extends Calculator {
const buildSizes = Object.values(DifferentialBuildType).map((buildType) => {
const size = this.chunks
.filter(chunk => chunk.names.indexOf(budgetName) !== -1)
.map((chunk) => this.calculateChunkSize(chunk, buildType))
.reduce((l, r) => l + r);
.map(chunk => this.calculateChunkSize(chunk, buildType))
.reduce((l, r) => l + r, 0);

return {size, label: `${this.budget.name}-${buildType}`};
});
Expand All @@ -223,8 +222,8 @@ class InitialCalculator extends Calculator {
label: `initial-${buildType}`,
size: this.chunks
.filter(chunk => chunk.initial)
.map((chunk) => this.calculateChunkSize(chunk, buildType))
.reduce((l, r) => l + r),
.map(chunk => this.calculateChunkSize(chunk, buildType))
.reduce((l, r) => l + r, 0),
};
});

Expand All @@ -244,7 +243,7 @@ class InitialCalculator extends Calculator {
class AllScriptCalculator extends Calculator {
calculate() {
const size = this.assets
.filter((asset) => asset.name.endsWith('.js'))
.filter(asset => asset.name.endsWith('.js'))
.map(asset => asset.size)
.reduce((total: number, size: number) => total + size, 0);

Expand Down

0 comments on commit 1a9cbd3

Please sign in to comment.