bonsai-analyzer
Version:
Trim your dependency tree.
41 lines (32 loc) • 1.44 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = chunkSizes;
var _getChunkModules = _interopRequireDefault(require("./getChunkModules"));
var _getChunkName = _interopRequireDefault(require("./getChunkName"));
var _getChunkNamesFromImportedModules = _interopRequireDefault(require("./getChunkNamesFromImportedModules"));
var _getEntryHierarchy = _interopRequireDefault(require("./getEntryHierarchy"));
var _getParentChunks = _interopRequireDefault(require("./getParentChunks"));
var _invariant = _interopRequireDefault(require("invariant"));
function chunkSizes(rawStats) {
return rawStats.map(stats => {
const chunksByParent = (0, _getEntryHierarchy.default)(stats);
const importedChunkNames = (0, _getChunkNamesFromImportedModules.default)(stats);
return stats.chunks.map(chunk => {
const parentChunks = (0, _getParentChunks.default)(chunksByParent, chunk.id);
const modules = (0, _getChunkModules.default)(stats, parentChunks);
(0, _invariant.default)(modules, 'for flow');
const size = modules.reduce((sum, module) => {
return sum + module.size;
}, 0);
return {
id: chunk.id,
name: (0, _getChunkName.default)(chunk, importedChunkNames),
moduleCount: modules.length,
totalSize: size
};
});
});
}