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.2.0-alpha.1 to 1.2.0-alpha.2

lib/util/getModuleName.d.ts

25

lib/api/deriveBundleData/getStatsFromRawStats.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStatsFromRawStats = void 0;
const webpack_1 = require("webpack");
function getStatsFromRawStats(rawStats, childStats) {
if ('children' in rawStats || rawStats instanceof webpack_1.MultiStats) {
if ('children' in rawStats || 'stats' in rawStats) {
// Make sure we are given a childStats option

@@ -13,9 +12,7 @@ if (!childStats) {

if (typeof childStats === 'string') {
const stats = rawStats instanceof webpack_1.MultiStats
? rawStats.stats.find(({ compilation: { name } }) => name === childStats)
: rawStats.children.find(s => s.name === childStats);
const stats = 'children' in rawStats
? rawStats.children.find(s => s.name === childStats)
: rawStats.stats.find(({ compilation: { name } }) => name === childStats);
if (stats) {
return stats instanceof webpack_1.Stats
? stats.compilation
: stats;
return 'compilation' in stats ? stats.compilation : stats;
}

@@ -26,9 +23,7 @@ }

if (!isNaN(index)) {
const stats = rawStats instanceof webpack_1.MultiStats
? rawStats.stats[index].compilation
: rawStats.children[index];
const stats = 'children' in rawStats
? rawStats.children[index]
: rawStats.stats[index].compilation;
if (stats) {
return stats instanceof webpack_1.Stats
? stats.compilation
: stats;
return 'compilation' in stats ? stats.compilation : stats;
}

@@ -38,3 +33,3 @@ }

}
else if (rawStats instanceof webpack_1.Stats) {
else if ('compilation' in rawStats) {
return rawStats.compilation;

@@ -41,0 +36,0 @@ }

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

const processReasons_1 = require("./processReasons");
const webpack_1 = require("webpack");
const getModuleName_1 = require("../../../util/getModuleName");
function deriveGraph(stats, validate) {

@@ -32,5 +32,4 @@ const moduleIdToNameMap = new ModuleIdToNameMap_1.default(stats);

}
const moduleName = moduleIdToNameMap.get(module.id);
const moduleSize = typeof module.size === 'number' ? module.size : module.size();
const moduleReasons = module instanceof webpack_1.Module
const moduleName = (0, getModuleName_1.getModuleName)(module, compilation);
const moduleReasons = 'hasReasons' in module
? [...compilation.moduleGraph.getIncomingConnections(module)]

@@ -41,5 +40,6 @@ .map(({ dependency }) => dependency && compilation.moduleGraph.getModule(dependency).identifier())

// Precalculate named chunk groups since they are the same for all submodules
const moduleChunks = module instanceof webpack_1.Module ? module.getChunks().map(({ id }) => id) : module.chunks;
const moduleChunks = 'hasReasons' in module ? module.getChunks().map(({ id }) => id) : module.chunks;
const namedChunkGroups = ncgLookup.getNamedChunkGroups(moduleChunks);
if (!module.modules) {
const moduleSize = typeof module.size === 'number' ? module.size : module.size();
// This is just an individual module, so we can add it to the graph as-is

@@ -51,2 +51,5 @@ addModuleToGraph(graph, Object.assign({ name: moduleName, namedChunkGroups, size: moduleSize }, (0, processReasons_1.processReasons)(moduleReasons, moduleIdToNameMap)));

// them individually.
const moduleSize = typeof module.modules[0].size === 'number'
? module.modules[0].size
: module.modules[0].size();
// Assume the first hoisted module acts as the primary module

@@ -57,3 +60,3 @@ addModuleToGraph(graph, Object.assign({ name: moduleName, containsHoistedModules: true, namedChunkGroups, size: moduleSize }, (0, processReasons_1.processReasons)(moduleReasons, moduleIdToNameMap)));

const hoistedModule = module.modules[i];
const hoistedModuleName = moduleIdToNameMap.get(hoistedModule.id);
const hoistedModuleName = (0, getModuleName_1.getModuleName)(hoistedModule, compilation);
const hoistedModuleSize = typeof hoistedModule.size === 'number' ? hoistedModule.size : hoistedModule.size();

@@ -60,0 +63,0 @@ addModuleToGraph(graph, {

7

lib/api/deriveBundleData/graph/ModuleIdToNameMap.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const getModuleName_1 = require("../../../util/getModuleName");
// Helper class to map module IDs to module names

@@ -10,7 +11,3 @@ class ModuleIdToNameMap {

// If the module contains multiple hoisted modules, assume the first one is the primary module
let name = 'readableIdentifier' in module
? module.readableIdentifier(stats.requestShortener)
: module.modules
? module.modules[0].name
: module.name;
let name = (0, getModuleName_1.getModuleName)(module, stats);
this.map.set(module.id, name);

@@ -17,0 +14,0 @@ }

import { Reason } from '../../../types/Stats';
import ModuleIdToNameMap from './ModuleIdToNameMap';
export declare function processReasons(reasons: Reason[], moduleIdToNameMap: ModuleIdToNameMap): {
entryType?: string;
parents: string[];
directParents: string[];
lazyParents: string[];
entryType: string;
};

@@ -37,9 +37,4 @@ "use strict";

}
return {
parents: [...directParents, ...lazyParents],
directParents: [...directParents],
lazyParents: [...lazyParents],
entryType,
};
return Object.assign({ parents: [...directParents, ...lazyParents], directParents: [...directParents], lazyParents: [...lazyParents] }, (entryType ? { entryType } : {}));
}
exports.processReasons = processReasons;
"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

@@ -13,3 +12,3 @@ class NamedChunkGroupLookupMap {

for (let chunk of chunkGroup.chunks) {
const chunkId = chunk instanceof webpack_1.Chunk ? chunk.id : chunk;
const chunkId = typeof chunk === 'object' ? chunk.id : chunk;
if (!this.map.has(chunkId)) {

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

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

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

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