Skip to content

Commit

Permalink
Fix edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 1, 2023
1 parent d2916cb commit aba7a57
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ function getViewerData(bundleStats, bundleDir, opts) {
const isAssetIncluded = createAssetsFilter(excludeAssets);

// Sometimes all the information is located in `children` array (e.g. problem in #10)
if (bundleStats.assets.length === 0 && bundleStats.children.length > 0) {
if (
(bundleStats.assets == null || bundleStats.assets.length === 0)
&& bundleStats.children.length > 0
) {
const {children} = bundleStats;
bundleStats = bundleStats.children[0];
// Sometimes if there are additional child chunks produced add them as child assets,
Expand Down Expand Up @@ -164,7 +167,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
statSize: asset.tree.size || asset.size,
parsedSize: asset.parsedSize,
gzipSize: asset.gzipSize,
groups: asset.tree.children.map(i => i.toChartData()),
groups: _.invokeMap(asset.tree.children, 'toChartData'),
isInitialByEntrypoint: chunkToInitialByEntrypoint[filename] ?? {}
}));
}
Expand Down
9 changes: 5 additions & 4 deletions src/parseUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const acorn = require('acorn');
const walk = require('acorn-walk');
const _ = require('lodash');

module.exports = {
parseBundle
Expand Down Expand Up @@ -139,12 +140,12 @@ function parseBundle(bundlePath) {
}
);

let modules;
const modules = {};

if (walkState.locations) {
modules = walkState.locations.map(loc => content.slice(loc.start, loc.end));
} else {
modules = {};
Object.entries(walkState.locations).forEach(([id, loc]) => {
modules[id] = content.slice(loc.start, loc.end);
});
}

return {
Expand Down
4 changes: 3 additions & 1 deletion src/tree/BaseFolder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

import Node from './Node';

export default class BaseFolder extends Node {
Expand Down Expand Up @@ -109,7 +111,7 @@ export default class BaseFolder extends Node {
label: this.name,
path: this.path,
statSize: this.size,
groups: this.children.map(i => i.toChartData())
groups: _.invokeMap(this.children, 'toChartData')
};
}

Expand Down
5 changes: 3 additions & 2 deletions src/tree/ConcatenatedModule.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import Module from './Module';
import ContentModule from './ContentModule';
import ContentFolder from './ContentFolder';
Expand Down Expand Up @@ -73,14 +74,14 @@ export default class ConcatenatedModule extends Module {
}

mergeNestedFolders() {
this.children.forEach(child => child.mergeNestedFolders());
_.invokeMap(this.children, 'mergeNestedFolders');
}

toChartData() {
return {
...super.toChartData(),
concatenated: true,
groups: this.children.map(i => i.toChartData())
groups: _.invokeMap(this.children, 'toChartData')
};
}

Expand Down

0 comments on commit aba7a57

Please sign in to comment.