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

webpack-stats-diff

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-stats-diff - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

2

package.json
{
"name": "webpack-stats-diff",
"version": "1.0.2",
"version": "1.1.0",
"description": "CLI tool to report changes in bundle sizes across builds",

@@ -5,0 +5,0 @@ "bin": "src/cli.js",

@@ -25,2 +25,34 @@ const { getStatsDiff } = require('../index');

test('Matches bundles by name (string before first period) and ext', () => {
const oldAssets = [
{ name: 'main.a83fjads83ja.js', size: 32768 },
{ name: 'main.23r8f2398sdz.css', size: 4000 },
{ name: 'form.i8aejf3iad.chunk.js', size: 5000 },
{ name: 'form.aefc83zl9a.css', size: 2000 }
];
const newAssets = [
{ name: 'main.aweifa09eh3.js', size: 16384 },
{ name: 'main.jo821kjdsi9.css', size: 5000 },
{ name: 'form.awe9f3nads893oz.chunk.js', size: 6500 },
{ name: 'form.89aw3jiuawefh8d.css', size: 1500 }
];
expect(getStatsDiff(oldAssets, newAssets)).toMatchObject({
added: [],
removed: [],
bigger: [
{ name: 'form.js', oldSize: 5000, newSize: 6500 },
{ name: 'main.css', oldSize: 4000, newSize: 5000 }
],
smaller: [
{
name: 'main.js',
oldSize: 32768,
newSize: 16384
},
{ name: 'form.css', oldSize: 2000, newSize: 1500 }
],
sameSize: []
});
});
test('filters assets by ext config', () => {

@@ -70,14 +102,14 @@ const oldAssets = [

const oldAssets = [
{ name: 'big-file-small-change', size: 100000 },
{ name: 'big-file-biggest-change', size: 100000 },
{ name: 'big-file-no-change', size: 100000 },
{ name: 'small-file-small-change', size: 1000 },
{ name: 'small-file-big-change', size: 1000 }
{ name: 'big-file-small-change.js', size: 100000 },
{ name: 'big-file-biggest-change.js', size: 100000 },
{ name: 'big-file-no-change.js', size: 100000 },
{ name: 'small-file-small-change.js', size: 1000 },
{ name: 'small-file-big-change.js', size: 1000 }
];
const newAssets = [
{ name: 'big-file-small-change', size: 104000 },
{ name: 'big-file-biggest-change', size: 110001 },
{ name: 'big-file-no-change', size: 100000 },
{ name: 'small-file-small-change', size: 960 },
{ name: 'small-file-big-change', size: 949 }
{ name: 'big-file-small-change.js', size: 104000 },
{ name: 'big-file-biggest-change.js', size: 110001 },
{ name: 'big-file-no-change.js', size: 100000 },
{ name: 'small-file-small-change.js', size: 960 },
{ name: 'small-file-big-change.js', size: 949 }
];

@@ -87,8 +119,8 @@

expect(getStatsDiff(oldAssets, newAssets)).toMatchObject({
bigger: [{ name: 'big-file-biggest-change' }],
smaller: [{ name: 'small-file-big-change' }],
bigger: [{ name: 'big-file-biggest-change.js' }],
smaller: [{ name: 'small-file-big-change.js' }],
sameSize: [
{ name: 'big-file-small-change' },
{ name: 'big-file-no-change' },
{ name: 'small-file-small-change' }
{ name: 'big-file-small-change.js' },
{ name: 'big-file-no-change.js' },
{ name: 'small-file-small-change.js' }
]

@@ -101,10 +133,10 @@ });

bigger: [
{ name: 'big-file-biggest-change' },
{ name: 'big-file-small-change' }
{ name: 'big-file-biggest-change.js' },
{ name: 'big-file-small-change.js' }
],
smaller: [
{ name: 'small-file-big-change' },
{ name: 'small-file-small-change' }
{ name: 'small-file-big-change.js' },
{ name: 'small-file-small-change.js' }
],
sameSize: [{ name: 'big-file-no-change' }]
sameSize: [{ name: 'big-file-no-change.js' }]
});

@@ -114,9 +146,9 @@

{
bigger: [{ name: 'big-file-biggest-change' }],
bigger: [{ name: 'big-file-biggest-change.js' }],
smaller: [],
sameSize: [
{ name: 'big-file-small-change' },
{ name: 'big-file-no-change' },
{ name: 'small-file-small-change' },
{ name: 'small-file-big-change' }
{ name: 'big-file-small-change.js' },
{ name: 'big-file-no-change.js' },
{ name: 'small-file-small-change.js' },
{ name: 'small-file-big-change.js' }
]

@@ -123,0 +155,0 @@ }

@@ -13,7 +13,13 @@ const path = require('path');

const removeHash = filename => {
const fileParts = filename.split('.');
return `${fileParts[0]}.${fileParts[fileParts.length - 1]}`;
};
const indexByName = assets => {
return assets.reduce((assetsByName, asset) => {
assetsByName[asset.name] = asset;
return assetsByName;
}, {});
const assetsByName = {};
assets.forEach(asset => {
assetsByName[removeHash(asset.name)] = asset;
});
return assetsByName;
};

@@ -69,3 +75,3 @@

newSizeTotal += newAsset.size;
if (!oldAssetsByName[newAsset.name]) {
if (!oldAssetsByName[name]) {
added.push(Object.assign({ name }, createDiff(0, newAsset.size)));

@@ -72,0 +78,0 @@ }

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