UNPKG

webpack-bundle-analyzer

Version:

Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap

73 lines (72 loc) 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _Module = _interopRequireDefault(require("./Module")); var _BaseFolder = _interopRequireDefault(require("./BaseFolder")); var _ConcatenatedModule = _interopRequireDefault(require("./ConcatenatedModule")); var _utils = require("./utils"); var _sizeUtils = require("../sizeUtils"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } class Folder extends _BaseFolder.default { constructor(name, opts) { super(name); this.opts = opts; } get parsedSize() { return this.src ? this.src.length : 0; } get gzipSize() { return this.opts.compressionAlgorithm === 'gzip' ? this.getCompressedSize('gzip') : undefined; } get brotliSize() { return this.opts.compressionAlgorithm === 'brotli' ? this.getCompressedSize('brotli') : undefined; } get zstdSize() { return this.opts.compressionAlgorithm === 'zstd' ? this.getCompressedSize('zstd') : undefined; } getCompressedSize(compressionAlgorithm) { const key = `_${compressionAlgorithm}Size`; if (!Object.prototype.hasOwnProperty.call(this, key)) { this[key] = this.src ? (0, _sizeUtils.getCompressedSize)(compressionAlgorithm, this.src) : 0; } return this[key]; } addModule(moduleData) { const pathParts = (0, _utils.getModulePathParts)(moduleData); if (!pathParts) { return; } const [folders, fileName] = [pathParts.slice(0, -1), pathParts[pathParts.length - 1]]; let currentFolder = this; folders.forEach(folderName => { let childNode = currentFolder.getChild(folderName); if ( // Folder is not created yet !childNode || // In some situations (invalid usage of dynamic `require()`) webpack generates a module with empty require // context, but it's moduleId points to a directory in filesystem. // In this case we replace this `File` node with `Folder`. // See `test/stats/with-invalid-dynamic-require.json` as an example. !(childNode instanceof Folder)) { childNode = currentFolder.addChildFolder(new Folder(folderName, this.opts)); } currentFolder = childNode; }); const ModuleConstructor = moduleData.modules ? _ConcatenatedModule.default : _Module.default; const module = new ModuleConstructor(fileName, moduleData, this, this.opts); currentFolder.addChildModule(module); } toChartData() { return { ...super.toChartData(), parsedSize: this.parsedSize, gzipSize: this.gzipSize, brotliSize: this.brotliSize, zstdSize: this.zstdSize }; } } exports.default = Folder; ;