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

webpack-bundle-diff

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-bundle-diff - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0-alpha.1

lib/api/deriveBundleData/getStatsFromRawStats.d.ts

5

lib/api/deriveBundleData/deriveBundleData.d.ts
import { BundleData } from '../../types/BundleData';
import { Stats } from '../../types/Stats';
import { RawStats } from '../../types/Stats';
import { DataOptions } from '../../types/DataOptions';
export declare function deriveBundleData(stats: Stats, options?: DataOptions): BundleData;
import { MultiStats, Stats } from 'webpack';
export declare function deriveBundleData(rawStats: RawStats | Stats | MultiStats, options?: DataOptions): BundleData;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deriveBundleData = void 0;
const deriveGraph_1 = require("./deriveGraph");
const deriveGraph_1 = require("./graph/deriveGraph");
const deriveChunkGroupData_1 = require("./deriveChunkGroupData");
function deriveBundleData(stats, options) {
const getStatsFromRawStats_1 = require("./getStatsFromRawStats");
function deriveBundleData(rawStats, options) {
const stats = (0, getStatsFromRawStats_1.getStatsFromRawStats)(rawStats, options === null || options === void 0 ? void 0 : options.childStats);
return {
graph: deriveGraph_1.deriveGraph(stats),
chunkGroups: deriveChunkGroupData_1.deriveChunkGroupData(stats, options),
graph: (0, deriveGraph_1.deriveGraph)(stats, options === null || options === void 0 ? void 0 : options.validate),
chunkGroups: (0, deriveChunkGroupData_1.deriveChunkGroupData)(stats, options),
};
}
exports.deriveBundleData = deriveBundleData;

3

lib/api/deriveBundleData/deriveChunkGroupData.d.ts
import { Stats } from '../../types/Stats';
import { ChunkGroupData } from '../../types/BundleData';
import { DataOptions } from '../../types/DataOptions';
export declare function deriveChunkGroupData(stats: Stats, options: DataOptions): ChunkGroupData;
import { Compilation } from 'webpack';
export declare function deriveChunkGroupData(stats: Stats | Compilation, options: DataOptions): ChunkGroupData;

@@ -9,8 +9,18 @@ "use strict";

for (let chunkGroupName of Object.keys(stats.namedChunkGroups)) {
const chunkGroup = stats.namedChunkGroups[chunkGroupName];
const chunkGroup = stats.namedChunkGroups instanceof Map
? stats.namedChunkGroups.get(chunkGroupName)
: stats.namedChunkGroups[chunkGroupName];
let chunkGroupSize = 0;
let assets = [];
let ignoredAssets = [];
const chunkGroupAssets = 'pushChunk' in chunkGroup
? chunkGroup
.getFiles()
.map((assetName) => ({
name: assetName,
size: stats.getAsset(assetName).info.size,
}))
: chunkGroup.assets;
// Process each asset in the chunk group
for (let { name, size } of chunkGroup.assets) {
for (let { name, size } of chunkGroupAssets) {
if (!assetFilter(name)) {

@@ -17,0 +27,0 @@ ignoredAssets.push(name);

@@ -0,6 +1,7 @@

import { Compilation } from 'webpack';
import { Stats, ChunkId } from '../../types/Stats';
export default class NamedChunkGroupLookupMap {
private map;
constructor(stats: Stats);
constructor(stats: Stats | Compilation);
getNamedChunkGroups(chunks: ChunkId[]): string[];
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const webpack_1 = require("webpack");
// Helper class to look up what named chunk groups a given chunk is in

@@ -8,5 +9,7 @@ class NamedChunkGroupLookupMap {

this.map = new Map();
for (let name of Object.keys(stats.namedChunkGroups)) {
const chunkGroup = stats.namedChunkGroups[name];
for (let chunkId of chunkGroup.chunks) {
for (let [name, chunkGroup] of stats.namedChunkGroups instanceof Map
? stats.namedChunkGroups
: Object.entries(stats.namedChunkGroups)) {
for (let chunk of chunkGroup.chunks) {
const chunkId = chunk instanceof webpack_1.Chunk ? chunk.id : chunk;
if (!this.map.has(chunkId)) {

@@ -13,0 +16,0 @@ this.map.set(chunkId, []);

@@ -0,0 +0,0 @@ import { BundleData } from '../../types/BundleData';

@@ -13,5 +13,5 @@ "use strict";

// Diff named chunk groups
const results = diffChunkGroups_1.default(baseline, comparison);
const results = (0, diffChunkGroups_1.default)(baseline, comparison);
// Diff the graph
diffGraph_1.default(new EnhancedModuleGraph_1.EnhancedModuleGraph(baseline.graph), new EnhancedModuleGraph_1.EnhancedModuleGraph(comparison.graph), results);
(0, diffGraph_1.default)(new EnhancedModuleGraph_1.EnhancedModuleGraph(baseline.graph), new EnhancedModuleGraph_1.EnhancedModuleGraph(comparison.graph), results);
return results;

@@ -21,3 +21,3 @@ }

function getBundleData(data, options) {
return data.graph ? data : deriveBundleData_1.deriveBundleData(data, options);
return data.graph ? data : (0, deriveBundleData_1.deriveBundleData)(data, options);
}
import { BundleData } from '../../types/BundleData';
import { DiffResults } from '../../types/DiffResults';
export default function diffChunkGroups(baseline: BundleData, comparison: BundleData): DiffResults;

@@ -0,0 +0,0 @@ "use strict";

import { DiffResults } from '../../types/DiffResults';
import { EnhancedModuleGraph } from './EnhancedModuleGraph';
export default function diffGraph(baselineGraph: EnhancedModuleGraph, comparisonGraph: EnhancedModuleGraph, results: DiffResults): void;

@@ -11,5 +11,5 @@ "use strict";

for (let moduleName of allModules) {
diffModuleNode_1.default(baselineGraph, comparisonGraph, moduleName, results);
(0, diffModuleNode_1.default)(baselineGraph, comparisonGraph, moduleName, results);
}
}
exports.default = diffGraph;
import { DiffResults } from '../../types/DiffResults';
import { EnhancedModuleGraph } from './EnhancedModuleGraph';
export default function diffModuleNode(baselineGraph: EnhancedModuleGraph, comparisonGraph: EnhancedModuleGraph, moduleName: string, results: DiffResults): void;

@@ -16,9 +16,9 @@ "use strict";

if (!baselineChunkGroups.has(chunkGroupName)) {
handleAddedModule_1.default(moduleName, baselineGraph, comparisonGraph, comparisonModule, chunkGroupName, chunkGroupDiff);
(0, handleAddedModule_1.default)(moduleName, baselineGraph, comparisonGraph, comparisonModule, chunkGroupName, chunkGroupDiff);
}
else if (!comparisonChunkGroups.has(chunkGroupName)) {
handleRemovedModule_1.default(moduleName, baselineGraph, comparisonGraph, baselineModule, chunkGroupName, chunkGroupDiff);
(0, handleRemovedModule_1.default)(moduleName, baselineGraph, comparisonGraph, baselineModule, chunkGroupName, chunkGroupDiff);
}
else {
handleChangedModule_1.default(moduleName, baselineModule, comparisonModule, chunkGroupDiff);
(0, handleChangedModule_1.default)(moduleName, baselineModule, comparisonModule, chunkGroupDiff);
}

@@ -25,0 +25,0 @@ }

@@ -0,0 +0,0 @@ import { ModuleGraph, ModuleGraphNode } from '../../types/BundleData';

@@ -0,0 +0,0 @@ "use strict";

import { EnhancedModuleGraph } from './EnhancedModuleGraph';
export default function filterToChunkGroup(modules: string[], chunkGroupName: string, graph: EnhancedModuleGraph): string[];

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { ImportWeight } from '../../types/DiffResults';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { ModuleGraphNode } from '../../types/BundleData';

@@ -11,3 +11,3 @@ "use strict";

// Get all parents in same chunk group
const comparisonParents = filterToChunkGroup_1.default(comparisonModule.parents, chunkGroupName, comparisonGraph);
const comparisonParents = (0, filterToChunkGroup_1.default)(comparisonModule.parents, chunkGroupName, comparisonGraph);
if (!comparisonParents.length) {

@@ -18,3 +18,3 @@ // The added module has no parents in this chunk group; it must be a new entry point

parents: [],
weight: getWeight_1.getAddedWeight(moduleName, baselineGraph, comparisonGraph, chunkGroupName),
weight: (0, getWeight_1.getAddedWeight)(moduleName, baselineGraph, comparisonGraph, chunkGroupName),
});

@@ -30,3 +30,3 @@ }

parents: previouslyExistingParents,
weight: getWeight_1.getAddedWeight(moduleName, baselineGraph, comparisonGraph, chunkGroupName),
weight: (0, getWeight_1.getAddedWeight)(moduleName, baselineGraph, comparisonGraph, chunkGroupName),
});

@@ -33,0 +33,0 @@ }

import { ModuleGraphNode } from '../../types/BundleData';
import { ChunkGroupDiff } from '../../types/DiffResults';
export default function handleChangedModule(moduleName: string, baselineModule: ModuleGraphNode, comparisonModule: ModuleGraphNode, chunkGroupDiff: ChunkGroupDiff): void;

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { ModuleGraphNode } from '../../types/BundleData';

@@ -11,3 +11,3 @@ "use strict";

// Get all parents that were in same chunk group
const baselineParents = filterToChunkGroup_1.default(baselineModule.parents, chunkGroupName, baselineGraph);
const baselineParents = (0, filterToChunkGroup_1.default)(baselineModule.parents, chunkGroupName, baselineGraph);
if (!baselineParents.length) {

@@ -18,3 +18,3 @@ // The removed module had no parents in this chunk group; it must have been an entry point

parents: [],
weight: getWeight_1.getRemovedWeight(moduleName, baselineGraph, comparisonGraph, chunkGroupName),
weight: (0, getWeight_1.getRemovedWeight)(moduleName, baselineGraph, comparisonGraph, chunkGroupName),
});

@@ -30,3 +30,3 @@ }

parents: stillExistingParents,
weight: getWeight_1.getRemovedWeight(moduleName, baselineGraph, comparisonGraph, chunkGroupName),
weight: (0, getWeight_1.getRemovedWeight)(moduleName, baselineGraph, comparisonGraph, chunkGroupName),
});

@@ -33,0 +33,0 @@ }

import { DiffResults } from '../../types/DiffResults';
import { ReportOptions } from '../../types/ReportOptions';
export declare function generateReport(diff: DiffResults, options?: ReportOptions): string;

@@ -0,0 +0,0 @@ "use strict";

export {};

@@ -15,8 +15,13 @@ "use strict";

.option('-o, --outFile <string>', 'output file')
.option('-c, --childStats <string>', 'child stats name or index')
.option('-v, --validate', 'validate module graph')
.action((statsPath, options) => {
console.log('Deriving bundle data from stats...');
readJson_1.default(statsPath).then((stats) => {
const bundleData = index_1.deriveBundleData(stats);
(0, readJson_1.default)(statsPath)
.then((stats) => {
const { childStats, validate } = options;
const bundleData = (0, index_1.deriveBundleData)(stats, { childStats, validate });
fs.writeFileSync(options.outFile, JSON.stringify(bundleData, null, 2));
});
})
.catch(reportError);
});

@@ -29,6 +34,8 @@ program

console.log('Diffing bundles...');
Promise.all([readJson_1.default(baselinePath), readJson_1.default(comparisonPath)]).then(data => {
let result = index_1.diff(data[0], data[1]);
Promise.all([(0, readJson_1.default)(baselinePath), (0, readJson_1.default)(comparisonPath)])
.then(data => {
let result = (0, index_1.diff)(data[0], data[1]);
fs.writeFileSync(options.outFile, JSON.stringify(result, null, 2));
});
})
.catch(reportError);
});

@@ -41,8 +48,13 @@ program

console.log('Generating report...');
readJson_1.default(diffPath).then((diff) => {
const markdown = index_1.generateReport(diff);
(0, readJson_1.default)(diffPath)
.then((diff) => {
const markdown = (0, index_1.generateReport)(diff);
fs.writeFileSync(options.outFile, markdown);
});
})
.catch(reportError);
});
// Execute the command line
program.parse(process.argv);
function reportError(error) {
console.error('webpack-bundle-diff failed with an error:', error);
}

@@ -0,0 +0,0 @@ export { deriveBundleData } from './api/deriveBundleData/deriveBundleData';

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -12,2 +12,3 @@ export interface BundleData {

name: string;
entryType?: string;
parents: string[];

@@ -14,0 +15,0 @@ directParents: string[];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -8,2 +8,12 @@ export interface DataOptions {

assetFilter?: AssetFilter;
/**
* Optional flag to validate the module graph. If any errors are detected they are reported to
* the error console and the API will fail.
*/
validate?: boolean;
/**
* Optional specifier for the child stats to use, if the webpack build included multiple
* configs. This can be the stats name or an index into the children array.
*/
childStats?: string | number;
}

@@ -10,0 +20,0 @@ export interface AssetFilter {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -0,0 +0,0 @@ export interface DiffResults {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -0,0 +0,0 @@ export interface ReportOptions {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -1,38 +0,11 @@

export interface Stats {
assets: Asset[];
chunks: Chunk[];
modules: Module[];
namedChunkGroups: {
[name: string]: NamedChunkGroup;
};
}
export interface Asset {
name: string;
chunks: ChunkId[];
size: number;
}
export interface Chunk {
id: ChunkId;
modules: Module[];
}
export interface Module {
chunks: ChunkId[];
id: string | number;
identifier: string;
modules?: Module[];
name: string;
reasons: Reason[];
size: number;
}
export interface Reason {
moduleId: string | number;
moduleName: string;
type: string;
userRequest: string;
}
import { StatsAsset, StatsChunk, StatsChunkGroup, StatsCompilation, StatsModule, StatsModuleReason } from 'webpack';
export declare type Stats = StatsCompilation & Required<Pick<StatsCompilation, 'assets' | 'chunks' | 'modules' | 'namedChunkGroups' | 'name'>>;
export declare type MultiStats = StatsCompilation & Required<Pick<StatsCompilation, 'children'>>;
export declare type RawStats = StatsCompilation;
export declare type Asset = StatsAsset;
export declare type Chunk = StatsChunk;
export declare type Module = StatsModule;
export declare type Reason = StatsModuleReason;
export declare type ChunkAsset = Pick<Asset, 'name' | 'size'>;
export interface NamedChunkGroup {
assets: ChunkAsset[];
chunks: ChunkId[];
}
export declare type NamedChunkGroup = StatsChunkGroup;
export declare type ChunkId = number | string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export declare function arrayUnion<T>(...arrays: T[][]): T[];

@@ -0,0 +0,0 @@ "use strict";

export default function readJson(path: string): Promise<any>;

@@ -0,0 +0,0 @@ "use strict";

{
"name": "webpack-bundle-diff",
"version": "1.1.0",
"version": "1.2.0-alpha.1",
"description": "Understand changes in webpack bundle size",

@@ -13,4 +13,4 @@ "main": "./lib/index.js",

"build": "tsc",
"data": "yarn build && node --max-old-space-size=12288 lib/cli.js data sampledata/stats.json -o sampledata/bundledata.json",
"ddata": "yarn build && node --inspect-brk --max-old-space-size=12288 lib/cli.js data sampledata/stats.json -o sampledata/bundledata.json",
"data": "yarn build && node --max-old-space-size=100288 lib/cli.js data sampledata/stats.json -o sampledata/bundledata.json --validate",
"ddata": "yarn build && node --inspect-brk --max-old-space-size=100288 lib/cli.js data sampledata/stats.json -o sampledata/bundledata.json --validate",
"diff": "yarn build && node lib/cli.js diff sampledata/data1.json sampledata/data2.json -o sampledata/diff.json",

@@ -31,10 +31,11 @@ "ddiff": "yarn build && node --inspect-brk lib/cli.js diff sampledata/data1.json sampledata/data2.json -o sampledata/diff.json",

"@types/event-stream": "^3.3.34",
"@types/jest": "^26.0.15",
"@types/jest": "^27.5.1",
"@types/node": "^10.12.18",
"husky": "^4.3.8",
"jest": "^26.6.0",
"jest": "^28.1.0",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"ts-jest": "^26.4.1",
"typescript": "~4.0.3"
"ts-jest": "^28.0.3",
"typescript": "~4.7.2",
"webpack": "^5.74.0"
},

@@ -41,0 +42,0 @@ "repository": {

@@ -5,2 +5,8 @@ # webpack-bundle-diff

webpack | webpack-bundle-diff
--------|--------------------
5.x.x | >=1.0.0
4.x.x | <1.0.0
## Getting started

@@ -7,0 +13,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