Skip to content

Commit a1a2dbc

Browse files
committed
Single source of thruth for compressed size helper
1 parent 4159e0a commit a1a2dbc

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/analyzer.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ module.exports = {
2020
function getViewerData(bundleStats, bundleDir, opts) {
2121
const {
2222
logger = new Logger(),
23-
excludeAssets = null
23+
excludeAssets = null,
24+
compressedSize = gzipSize
2425
} = opts || {};
2526

2627
const isAssetIncluded = createAssetsFilter(excludeAssets);
@@ -102,7 +103,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
102103

103104
if (assetSources) {
104105
asset.parsedSize = Buffer.byteLength(assetSources.src);
105-
asset.gzipSize = gzipSize(assetSources.src);
106+
asset.gzipSize = compressedSize(assetSources.src);
106107
}
107108

108109
// Picking modules from current bundle script
@@ -143,7 +144,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
143144
}
144145

145146
asset.modules = assetModules;
146-
asset.tree = createModulesTree(asset.modules);
147+
asset.tree = createModulesTree(asset.modules, {compressedSize});
147148
return result;
148149
}, {});
149150

@@ -203,8 +204,8 @@ function isRuntimeModule(statModule) {
203204
return statModule.moduleType === 'runtime';
204205
}
205206

206-
function createModulesTree(modules) {
207-
const root = new Folder('.');
207+
function createModulesTree(modules, opts) {
208+
const root = new Folder('.', opts);
208209

209210
modules.forEach(module => root.addModule(module));
210211
root.mergeNestedFolders();

src/tree/Folder.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import _ from 'lodash';
2-
import {gzipSize} from '../sizeUtils';
32

43
import Module from './Module';
54
import BaseFolder from './BaseFolder';
@@ -8,13 +7,18 @@ import {getModulePathParts} from './utils';
87

98
export default class Folder extends BaseFolder {
109

10+
constructor(name, opts) {
11+
super(name);
12+
this.opts = opts;
13+
}
14+
1115
get parsedSize() {
1216
return this.src ? this.src.length : 0;
1317
}
1418

1519
get gzipSize() {
1620
if (!_.has(this, '_gzipSize')) {
17-
this._gzipSize = this.src ? gzipSize(this.src) : 0;
21+
this._gzipSize = this.src ? this.opts.compressedSize(this.src) : 0;
1822
}
1923

2024
return this._gzipSize;
@@ -42,7 +46,7 @@ export default class Folder extends BaseFolder {
4246
// See `test/stats/with-invalid-dynamic-require.json` as an example.
4347
!(childNode instanceof Folder)
4448
) {
45-
childNode = currentFolder.addChildFolder(new Folder(folderName));
49+
childNode = currentFolder.addChildFolder(new Folder(folderName, this.opts));
4650
}
4751

4852
currentFolder = childNode;

0 commit comments

Comments
 (0)