Skip to content

Commit cc19147

Browse files
TheLarkInnsokra
authored andcommitted
chore(performance): fix formatting in warnings/errors
1 parent 1f9e1a6 commit cc19147

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

lib/SizeFormatHelpers.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Sean Larkin @thelarkinn
4+
*/
15
var SizeFormatHelpers = exports;
26

37
SizeFormatHelpers.formatSize = function(size) {
4-
if(size <= 0) return "0 bytes";
8+
if (size <= 0) {
9+
return "0 bytes";
10+
}
511

6-
var abbreviations = ["bytes", "kB", "MB", "GB"];
7-
var index = Math.floor(Math.log(size) / Math.log(1000));
12+
var abbreviations = ["bytes", "kB", "MB", "GB"];
13+
var index = Math.floor(Math.log(size) / Math.log(1000));
814

9-
return +(size / Math.pow(1000, index))
10-
.toPrecision(3) + " " + abbreviations[index];
11-
}
15+
return + (size / Math.pow(1000, index))
16+
.toPrecision(3) + " " + abbreviations[index];
17+
}

lib/performance/AssetsOverSizeLimitWarning.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Sean Larkin @thelarkinn
44
*/
5-
var formatSize = require('../SizeFormatHelpers').formatSize;
5+
var SizeFormatHelpers = require('../SizeFormatHelpers');
66

77
function AssetsOverSizeLimitWarning(assetsOverSizeLimit, compilation, assetLimit) {
88
Error.call(this);
@@ -14,7 +14,7 @@ function AssetsOverSizeLimitWarning(assetsOverSizeLimit, compilation, assetLimit
1414
return "\n " + asset.name;
1515
}).join("");
1616

17-
this.message = "asset size limit: The following assets exceed the recommended size limit (" + formatSize(assetLimit) + "). \n" +
17+
this.message = "asset size limit: The following assets exceed the recommended size limit (" + SizeFormatHelpers.formatSize(assetLimit) + "). \n" +
1818
"This can impact web performance.\n" +
1919
"Assets: " + assetLists;
2020
}

lib/performance/EntrypointsOverSizeLimitWarning.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Sean Larkin @thelarkinn
44
*/
5-
var formatSize = require('../SizeFormatHelpers').formatSize;
5+
var SizeFormatHelpers = require('../SizeFormatHelpers');
66

77
function EntrypointsOverSizeLimitWarning(entrypoints, compilation, entrypointLimit) {
88
Error.call(this);
@@ -11,13 +11,13 @@ function EntrypointsOverSizeLimitWarning(entrypoints, compilation, entrypointLim
1111
this.entrypoints = entrypoints;
1212

1313
var entrypointList = this.entrypoints.map(function(entrypoint) {
14-
return "\n " + entrypoint.name + ": " + formatSize(entrypoint.getSize()) + "\n" +
14+
return "\n " + entrypoint.name + ": " + SizeFormatHelpers.formatSize(entrypoint.getSize()) + "\n" +
1515
Object.keys(entrypoint.getFiles()).map(function(filename) {
1616
return " " + entrypoint.getFiles()[filename] + "\n";
1717
}).join("");
1818
}).join("");
1919

20-
this.message = "entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (" + formatSize(entrypointLimit).string + "). " +
20+
this.message = "entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (" + SizeFormatHelpers.formatSize(entrypointLimit) + "). " +
2121
"This can impact web performance.\n" +
2222
"Entrypoints: \n" +
2323
entrypointList;

0 commit comments

Comments
 (0)