Skip to content

Commit f6bca53

Browse files
committed
fix(@angular-devkit/build-angular): display correct filename for bundles that are ES2016+
(cherry picked from commit 075c988)
1 parent eb3674e commit f6bca53

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

packages/angular_devkit/build_angular/src/utils/bundle-calculator.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ export enum ThresholdSeverity {
3333
}
3434

3535
enum DifferentialBuildType {
36-
// FIXME: this should match the actual file suffix and not hardcoded.
37-
ORIGINAL = 'es2015',
38-
DOWNLEVEL = 'es5',
36+
ORIGINAL = 'original',
37+
DOWNLEVEL = 'downlevel',
3938
}
4039

4140
export function* calculateThresholds(budget: Budget): IterableIterator<Threshold> {
@@ -206,15 +205,17 @@ class BundleCalculator extends Calculator {
206205
return [];
207206
}
208207

208+
const buildTypeLabels = getBuildTypeLabels(this.processResults);
209+
209210
// The chunk may or may not have differential builds. Compute the size for
210211
// each then check afterwards if they are all the same.
211212
const buildSizes = Object.values(DifferentialBuildType).map((buildType) => {
212213
const size = this.chunks
213-
.filter(chunk => chunk.names.indexOf(budgetName) !== -1)
214-
.map(chunk => this.calculateChunkSize(chunk, buildType))
215-
.reduce((l, r) => l + r, 0);
214+
.filter(chunk => chunk.names.includes(budgetName))
215+
.map(chunk => this.calculateChunkSize(chunk, buildType))
216+
.reduce((l, r) => l + r, 0);
216217

217-
return {size, label: `bundle ${this.budget.name}-${buildType}`};
218+
return { size, label: `bundle ${this.budget.name}-${buildTypeLabels[buildType]}` };
218219
});
219220

220221
// If this bundle was not actually generated by a differential build, then
@@ -232,13 +233,14 @@ class BundleCalculator extends Calculator {
232233
*/
233234
class InitialCalculator extends Calculator {
234235
calculate() {
236+
const buildTypeLabels = getBuildTypeLabels(this.processResults);
235237
const buildSizes = Object.values(DifferentialBuildType).map((buildType) => {
236238
return {
237-
label: `bundle initial-${buildType}`,
239+
label: `bundle initial-${buildTypeLabels[buildType]}`,
238240
size: this.chunks
239-
.filter(chunk => chunk.initial)
240-
.map(chunk => this.calculateChunkSize(chunk, buildType))
241-
.reduce((l, r) => l + r, 0),
241+
.filter(chunk => chunk.initial)
242+
.map(chunk => this.calculateChunkSize(chunk, buildType))
243+
.reduce((l, r) => l + r, 0),
242244
};
243245
});
244246

@@ -432,3 +434,19 @@ function mergeDifferentialBuildSizes(buildSizes: Size[], mergeLabel: string): Si
432434
function allEquivalent<T>(items: Iterable<T>): boolean {
433435
return new Set(items).size < 2;
434436
}
437+
438+
function getBuildTypeLabels(processResults: ProcessBundleResult[]): Record<DifferentialBuildType, string> {
439+
const fileNameSuffixRegExp = /\-(es20\d{2}|esnext)\./;
440+
const originalFileName = processResults
441+
.find(({ original }) => original?.filename && fileNameSuffixRegExp.test(original.filename))?.original?.filename;
442+
443+
let originalSuffix: string | undefined;
444+
if (originalFileName) {
445+
originalSuffix = fileNameSuffixRegExp.exec(originalFileName)?.[1];
446+
}
447+
448+
return {
449+
[DifferentialBuildType.DOWNLEVEL]: 'es5',
450+
[DifferentialBuildType.ORIGINAL]: originalSuffix || 'es2015',
451+
};
452+
}

packages/angular_devkit/build_angular/src/utils/bundle-calculator_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('bundle-calculator', () => {
240240
name: '0',
241241
// Individual builds are under budget, but combined they are over.
242242
original: {
243-
filename: 'initial-es2015.js',
243+
filename: 'initial-es2017.js',
244244
size: 1.25 * KB,
245245
},
246246
downlevel: {
@@ -255,7 +255,7 @@ describe('bundle-calculator', () => {
255255
expect(failures.length).toBe(2);
256256
expect(failures).toContain({
257257
severity: ThresholdSeverity.Error,
258-
message: jasmine.stringMatching('bundle initial-es2015 exceeded maximum budget.'),
258+
message: jasmine.stringMatching('bundle initial-es2017 exceeded maximum budget.'),
259259
});
260260
expect(failures).toContain({
261261
severity: ThresholdSeverity.Error,

0 commit comments

Comments
 (0)