webpack-bundle-diff
Advanced tools
Comparing version 1.0.0 to 1.1.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[]; | ||
}; |
@@ -26,8 +26,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))); | ||
} | ||
@@ -39,9 +34,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 | ||
@@ -53,2 +42,4 @@ for (let i = 1; i < module.modules.length; i++) { | ||
parents: [primaryModule.name], | ||
directParents: [primaryModule.name], | ||
lazyParents: [], | ||
namedChunkGroups, | ||
@@ -62,10 +53,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], | ||
}; | ||
} | ||
@@ -72,0 +81,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": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Understand changes in webpack bundle size", | ||
@@ -32,3 +32,6 @@ "main": "./lib/index.js", | ||
"@types/node": "^10.12.18", | ||
"husky": "^4.3.8", | ||
"jest": "^26.6.0", | ||
"prettier": "^2.2.1", | ||
"pretty-quick": "^3.1.0", | ||
"ts-jest": "^26.4.1", | ||
@@ -41,3 +44,8 @@ "typescript": "~4.0.3" | ||
}, | ||
"license": "MIT" | ||
"license": "MIT", | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
} | ||
} |
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
42641
56
814
10