Fix file size report after build (#5335)

Fixes #5333

printFileSizesAfterBuild calls canReadAsset with an object containing
the file name while measureFileSizesBeforeBuild calls it with just the
name. When canReadAsset only receives the name it returns false since
accessing the `name` property results in undefined.

This commit fixes that by having canReadAssset instead expect only the
file name and making printFileSizesAfterBuild just like
measureFileSizesBeforeBuild only provide the name as argument.
This commit is contained in:
Oskar Persson
2018-10-07 00:27:30 +02:00
committed by Joe Haddad
parent b201aee073
commit 9fd98447d8

View File

@@ -17,9 +17,9 @@ var gzipSize = require('gzip-size').sync;
function canReadAsset(asset) {
return (
/\.(js|css)$/.test(asset.name) &&
!/service-worker\.js/.test(asset.name) &&
!/precache-manifest\.[0-9a-f]+\.js/.test(asset.name)
/\.(js|css)$/.test(asset) &&
!/service-worker\.js/.test(asset) &&
!/precache-manifest\.[0-9a-f]+\.js/.test(asset)
);
}
@@ -37,7 +37,7 @@ function printFileSizesAfterBuild(
.map(stats =>
stats
.toJson({ all: false, assets: true })
.assets.filter(canReadAsset)
.assets.filter(asset => canReadAsset(asset.name))
.map(asset => {
var fileContents = fs.readFileSync(path.join(root, asset.name));
var size = gzipSize(fileContents);