UNPKG

bonsai-analyzer

Version:
60 lines (56 loc) 1.49 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = chunkSizesDiff; var _invariant = _interopRequireDefault(require("invariant")); function chunkSizesDiff(a, b) { const diffMap = {}; a.forEach(file => { file.forEach(chunkSize => { if (!diffMap[chunkSize.name]) { diffMap[chunkSize.name] = { name: chunkSize.name, a: chunkSize, b: null, diff: null }; } else { (0, _invariant.default)('we have the same chunk twice?'); } }); }); b.forEach(file => { file.forEach(chunkSize => { if (!diffMap[chunkSize.name]) { diffMap[chunkSize.name] = { name: chunkSize.name, a: null, b: null, diff: null }; } else { diffMap[chunkSize.name].b = chunkSize; } }); }); Object.keys(diffMap).forEach(name => { const chunkDiff = diffMap[name]; const a = chunkDiff.a || { moduleCount: 0, totalSize: 0 }; const b = chunkDiff.b || { moduleCount: 0, totalSize: 0 }; chunkDiff.diff = { moduleCount: b.moduleCount - a.moduleCount, modulePercent: (b.moduleCount - a.moduleCount) / a.moduleCount, sizeCount: b.totalSize - a.totalSize, sizePercent: (b.totalSize - a.totalSize) / a.totalSize }; }); return diffMap; }