@jimdo/webpack-stats-diff
Advanced tools
Comparing version 1.0.0 to 1.0.2
{ | ||
"name": "@jimdo/webpack-stats-diff", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"description": "Diffs two webpack stats outputs (e.g. via [stats-webpack-plugin](https://www.npmjs.com/package/stats-webpack-plugin)) and gives back an object with file size changes in a human readable format", | ||
@@ -5,0 +5,0 @@ "bin": { |
#! /usr/bin/env node | ||
const path = require('path'); | ||
const jsondiffpatch = require('jsondiffpatch'); | ||
const bytes = require('bytes'); | ||
const differ = require('./src/index.js'); | ||
const baseFile = path.resolve(process.argv.slice(2)[0]); | ||
@@ -12,74 +13,23 @@ const base = require(baseFile); | ||
const isExtractTextGarbage = /\.css\..*\.js/; | ||
const isSourcemap = /\.map$/; | ||
const threshold = 4000; | ||
function mapStatsToEntriesWithSize(assets) { | ||
return assets.reduce((mem, asset) => { | ||
if (isExtractTextGarbage.test(asset.name)) { | ||
return mem; | ||
} | ||
if (isSourcemap.test(asset.name)) { | ||
return mem; | ||
} | ||
const entryName = asset.chunkNames[0]; | ||
return Object.assign( | ||
{}, | ||
mem, | ||
{ | ||
[entryName]: { | ||
size: asset.size, | ||
name: asset.name | ||
} | ||
} | ||
); | ||
function asHumanReadable(diff) { | ||
return Object.keys(diff).reduce((mem, asset) => { | ||
mem[asset] = bytes(diff[asset]); | ||
return mem; | ||
}, {}); | ||
} | ||
const resultBase = mapStatsToEntriesWithSize(base.assets); | ||
const resultChanged = mapStatsToEntriesWithSize(changed.assets); | ||
function run() { | ||
const diff = jsondiffpatch.diff(resultBase, resultChanged); | ||
const result = differ(base, changed); | ||
if (!diff) { | ||
return; | ||
} | ||
if (Object.keys(result).length === 0) { | ||
process.stdout.write('\nWebpack Stats Diff: No filesize changes found\n'); | ||
return; | ||
} | ||
function diffToFileSizeChange(diff) { | ||
return Object.keys(diff).reduce((mem, asset) => { | ||
if (!diff[asset].size) { | ||
return mem; | ||
} | ||
mem[asset] = diff[asset].size.reduce((mem, val, i) => i === 0 ? mem - val : mem + val, 0); | ||
return mem; | ||
}, {}); | ||
process.stdout.write('\nWebpack Stats Diff: The following files have a different file size\n'); | ||
process.stdout.write(JSON.stringify(asHumanReadable(result), null, 2)); | ||
process.stdout.write('\n'); | ||
} | ||
function filterIrrelevant(diff) { | ||
return Object.keys(diff).reduce((mem, asset) => { | ||
if (Math.abs(diff[asset]) < threshold) { | ||
return mem; | ||
} | ||
mem[asset] = diff[asset]; | ||
return mem; | ||
}, {}); | ||
} | ||
function asHumanReadable(diff) { | ||
return Object.keys(diff).reduce((mem, asset) => { | ||
mem[asset] = bytes(diff[asset]); | ||
return mem; | ||
}, {}); | ||
} | ||
process.stdout.write(JSON.stringify( | ||
asHumanReadable( | ||
filterIrrelevant( | ||
diffToFileSizeChange(diff) | ||
) | ||
), null, 2 | ||
)); | ||
run(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79
4024
5