Skip to content

Commit 05e2a0e

Browse files
hrocha16Keen Yee Liau
authored and
Keen Yee Liau
committed
fix(@angular-devkit/build-angular): minimum threshold
1 parent 9efa933 commit 05e2a0e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function calculateBytes(
154154
let value = Number(matches[1]);
155155
switch (matches[2] && matches[2].toLowerCase()) {
156156
case '%':
157-
value = baselineBytes * value / 100 * factor;
157+
value = baselineBytes * value / 100;
158158
break;
159159
case 'kb':
160160
value *= 1024;
@@ -167,5 +167,9 @@ export function calculateBytes(
167167
break;
168168
}
169169

170-
return value + baselineBytes;
170+
if (baselineBytes === 0) {
171+
return value;
172+
}
173+
174+
return baselineBytes + value * factor;
171175
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ describe('bundle-calculator', () => {
6767
expect(calculateBytes('25.0gB')).toBe(25 * 1024 * 1024 * 1024);
6868
});
6969

70+
it ('converts a decimal with mb and baseline', () => {
71+
expect(calculateBytes('3mb', '5mb', -1)).toBe(2 * 1024 * 1024);
72+
});
73+
7074
it ('converts a percentage with baseline', () => {
7175
expect(calculateBytes('20%', '1mb')).toBe(1024 * 1024 * 1.2);
7276
expect(calculateBytes('20%', '1mb', -1)).toBe(1024 * 1024 * 0.8);

0 commit comments

Comments
 (0)