Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jimdo/webpack-stats-diff

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jimdo/webpack-stats-diff - npm Package Compare versions

Comparing version 1.0.0 to 1.0.2

src/index.js

2

package.json
{
"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();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc