UNPKG

bonsai-analyzer

Version:
31 lines (26 loc) 879 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getChunkNamesFromImportedModules; function isImportType(reason) { return reason.type === 'import()'; } function wasImported(module) { return module.reasons.filter(isImportType).length > 0; } function getChunkNamesFromImportedModules(stats) { const chunksById = stats.chunks.reduce((map, chunk) => { map[chunk.id] = chunk; return map; }, {}); return stats.modules.filter(wasImported).reduce((namesByChunks, module) => { module.reasons.filter(isImportType).forEach(reason => { const chunk = module.chunks.map(chunkId => chunksById[chunkId]).filter(chunk => chunk.origins.length >= 1 && chunk.origins[0].loc === reason.loc).shift(); if (chunk) { namesByChunks[chunk.id] = module.name; } }); return namesByChunks; }, {}); }