Skip to content

Commit 075c988

Browse files
committed
fix(@angular-devkit/build-angular): display correct filename for bundles that are ES2016+
1 parent 4b0223b commit 075c988

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

+29-11
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ export enum ThresholdSeverity {
3737
}
3838

3939
enum DifferentialBuildType {
40-
// FIXME: this should match the actual file suffix and not hardcoded.
41-
ORIGINAL = 'es2015',
42-
DOWNLEVEL = 'es5',
40+
ORIGINAL = 'original',
41+
DOWNLEVEL = 'downlevel',
4342
}
4443

4544
export function* calculateThresholds(budget: Budget): IterableIterator<Threshold> {
@@ -214,15 +213,17 @@ class BundleCalculator extends Calculator {
214213
return [];
215214
}
216215

216+
const buildTypeLabels = getBuildTypeLabels(this.processResults);
217+
217218
// The chunk may or may not have differential builds. Compute the size for
218219
// each then check afterwards if they are all the same.
219220
const buildSizes = Object.values(DifferentialBuildType).map((buildType) => {
220221
const size = this.chunks
221-
.filter(chunk => chunk.names.indexOf(budgetName) !== -1)
222-
.map(chunk => this.calculateChunkSize(chunk, buildType))
223-
.reduce((l, r) => l + r, 0);
222+
.filter(chunk => chunk.names.includes(budgetName))
223+
.map(chunk => this.calculateChunkSize(chunk, buildType))
224+
.reduce((l, r) => l + r, 0);
224225

225-
return {size, label: `bundle ${this.budget.name}-${buildType}`};
226+
return { size, label: `bundle ${this.budget.name}-${buildTypeLabels[buildType]}` };
226227
});
227228

228229
// If this bundle was not actually generated by a differential build, then
@@ -240,13 +241,14 @@ class BundleCalculator extends Calculator {
240241
*/
241242
class InitialCalculator extends Calculator {
242243
calculate() {
244+
const buildTypeLabels = getBuildTypeLabels(this.processResults);
243245
const buildSizes = Object.values(DifferentialBuildType).map((buildType) => {
244246
return {
245-
label: `bundle initial-${buildType}`,
247+
label: `bundle initial-${buildTypeLabels[buildType]}`,
246248
size: this.chunks
247-
.filter(chunk => chunk.initial)
248-
.map(chunk => this.calculateChunkSize(chunk, buildType))
249-
.reduce((l, r) => l + r, 0),
249+
.filter(chunk => chunk.initial)
250+
.map(chunk => this.calculateChunkSize(chunk, buildType))
251+
.reduce((l, r) => l + r, 0),
250252
};
251253
});
252254

@@ -440,3 +442,19 @@ function mergeDifferentialBuildSizes(buildSizes: Size[], mergeLabel: string): Si
440442
function allEquivalent<T>(items: Iterable<T>): boolean {
441443
return new Set(items).size < 2;
442444
}
445+
446+
function getBuildTypeLabels(processResults: ProcessBundleResult[]): Record<DifferentialBuildType, string> {
447+
const fileNameSuffixRegExp = /\-(es20\d{2}|esnext)\./;
448+
const originalFileName = processResults
449+
.find(({ original }) => original?.filename && fileNameSuffixRegExp.test(original.filename))?.original?.filename;
450+
451+
let originalSuffix: string | undefined;
452+
if (originalFileName) {
453+
originalSuffix = fileNameSuffixRegExp.exec(originalFileName)?.[1];
454+
}
455+
456+
return {
457+
[DifferentialBuildType.DOWNLEVEL]: 'es5',
458+
[DifferentialBuildType.ORIGINAL]: originalSuffix || 'es2015',
459+
};
460+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe('bundle-calculator', () => {
243243
name: '0',
244244
// Individual builds are under budget, but combined they are over.
245245
original: {
246-
filename: 'initial-es2015.js',
246+
filename: 'initial-es2017.js',
247247
size: 1.25 * KB,
248248
},
249249
downlevel: {
@@ -258,7 +258,7 @@ describe('bundle-calculator', () => {
258258
expect(failures.length).toBe(2);
259259
expect(failures).toContain({
260260
severity: ThresholdSeverity.Error,
261-
message: jasmine.stringMatching('bundle initial-es2015 exceeded maximum budget.'),
261+
message: jasmine.stringMatching('bundle initial-es2017 exceeded maximum budget.'),
262262
});
263263
expect(failures).toContain({
264264
severity: ThresholdSeverity.Error,

0 commit comments

Comments
 (0)