webpack-bundle-diff
Advanced tools
Comparing version 0.5.2 to 0.6.0
@@ -7,2 +7,6 @@ import { ModuleGraph } from '../../types/BundleData'; | ||
export declare function processModule(module: Module, graph: ModuleGraph, moduleIdToNameMap: ModuleIdToNameMap, ncgLookup: NamedChunkGroupLookupMap): void; | ||
export declare function getParents(reasons: Reason[], moduleIdToNameMap: ModuleIdToNameMap): string[]; | ||
export declare function getParents(reasons: Reason[], moduleIdToNameMap: ModuleIdToNameMap): { | ||
parents: string[]; | ||
directParents: string[]; | ||
lazyParents: string[]; | ||
}; |
@@ -25,8 +25,3 @@ "use strict"; | ||
// This is just an individual module, so we can add it to the graph as-is | ||
addModuleToGraph(graph, { | ||
name: module.name, | ||
parents: getParents(module.reasons, moduleIdToNameMap), | ||
namedChunkGroups, | ||
size: module.size, | ||
}); | ||
addModuleToGraph(graph, Object.assign({ name: module.name, namedChunkGroups, size: module.size }, getParents(module.reasons, moduleIdToNameMap))); | ||
} | ||
@@ -38,9 +33,3 @@ else { | ||
const primaryModule = module.modules[0]; | ||
addModuleToGraph(graph, { | ||
name: primaryModule.name, | ||
parents: getParents(module.reasons, moduleIdToNameMap), | ||
containsHoistedModules: true, | ||
namedChunkGroups, | ||
size: primaryModule.size, | ||
}); | ||
addModuleToGraph(graph, Object.assign({ name: primaryModule.name, containsHoistedModules: true, namedChunkGroups, size: primaryModule.size }, getParents(module.reasons, moduleIdToNameMap))); | ||
// Other hoisted modules are parented to the primary module | ||
@@ -52,2 +41,4 @@ for (let i = 1; i < module.modules.length; i++) { | ||
parents: [primaryModule.name], | ||
directParents: [primaryModule.name], | ||
lazyParents: [], | ||
namedChunkGroups, | ||
@@ -61,10 +52,28 @@ size: hoistedModule.size, | ||
function getParents(reasons, moduleIdToNameMap) { | ||
// Start with the module ID for each reason | ||
let moduleIds = reasons.map(r => r.moduleId); | ||
// Filter out nulls (this happens for entry point modules) | ||
moduleIds = moduleIds.filter(p => p != null); | ||
// Filter out duplicates (this happens due to scope hoisting) | ||
moduleIds = [...new Set(moduleIds)]; | ||
// Map module IDs to module names | ||
return moduleIds.map(moduleId => moduleIdToNameMap.get(moduleId)); | ||
const directParents = new Set(); | ||
const lazyParents = new Set(); | ||
for (const reason of reasons) { | ||
// If moduleId is present, use that to look up the module name. (The moduleName | ||
// property, in that case, has something like "foo.js + 12 modules" which isn't what we | ||
// want.) But if there is no moduleId, use the moduleName instead - it appears to be | ||
// correct in that case. | ||
const moduleName = (reason.moduleId && moduleIdToNameMap.get(reason.moduleId)) || reason.moduleName; | ||
// Entry point modules will have a reason with no associated module | ||
if (!moduleName) { | ||
continue; | ||
} | ||
// Distinguish between lazy and normal imports | ||
const isLazyParent = reason.type === 'import()'; | ||
if (isLazyParent) { | ||
lazyParents.add(moduleName); | ||
} | ||
else { | ||
directParents.add(moduleName); | ||
} | ||
} | ||
return { | ||
parents: [...directParents, ...lazyParents], | ||
directParents: [...directParents], | ||
lazyParents: [...lazyParents], | ||
}; | ||
} | ||
@@ -71,0 +80,0 @@ exports.getParents = getParents; |
@@ -13,2 +13,4 @@ export interface BundleData { | ||
parents: string[]; | ||
directParents: string[]; | ||
lazyParents: string[]; | ||
size: number; | ||
@@ -15,0 +17,0 @@ } |
@@ -29,2 +29,3 @@ export interface Stats { | ||
moduleId: string | number; | ||
moduleName: string; | ||
type: string; | ||
@@ -31,0 +32,0 @@ userRequest: string; |
{ | ||
"name": "webpack-bundle-diff", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "Understand changes in webpack bundle size", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
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
803
41653
52