webpack-bundle-analyzer icon indicating copy to clipboard operation
webpack-bundle-analyzer copied to clipboard

Incorrect total size in search result

Open kyriiherman opened this issue 6 years ago • 14 comments

Issue description

When I search for some modules total size isn't correct. It looks like total size is folder size + size of each file in folder

Technical info

  • Webpack Bundle Analyzer version: 3.0.3
  • Webpack version: 4.19.1
  • Node.js version: 11.9.0
  • npm/yarn version: 1.13.0
  • OS: macOS Mojave

Debug info

How do you use this module? As CLI utility or as plugin? plugin

If plugin, what options were provided? (e.g. new BundleAnalyzerPlugin({ analyzerMode: 'disabled', generateStatsFile: true })) { openAnalyzer: false }

screen shot 2019-02-14 at 13 04 00

kyriiherman avatar Feb 14 '19 11:02 kyriiherman

Hmm are you sure your lodash in 5.chunk.js isn't that large? Does it show a different size in the treeview?

valscion avatar Feb 14 '19 11:02 valscion

I think its a legit bug. I've overlooked this case.

th0r avatar Feb 14 '19 11:02 th0r

@th0r @valscion I think bug is here https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/d7682a655abda824c82b9d6bb7991b9576c33610/client/store.js#L153. You should check for !module.groups before adding module size

kyriiherman avatar Feb 14 '19 13:02 kyriiherman

@kyriiherman it's not so easy. What if the only found item is a directory? In your case the size will be zero.

th0r avatar Feb 14 '19 13:02 th0r

@th0r yes, this is correct behavior. in your case the directory is empty, otherwise all files inside directory are present in found modules, because files paths include directory name

kyriiherman avatar Feb 14 '19 14:02 kyriiherman

@kyriiherman No, it's not. You can input a regexp that will match only directory name e.g. node_modules$ and it won't be empty.

th0r avatar Feb 14 '19 15:02 th0r

@th0r oh, my fault( so we should check for this.searchQueryRegexp and if someone is looking for a directory then we should consider directory size, otherwise no 😏I can submit a pull request.

kyriiherman avatar Feb 14 '19 16:02 kyriiherman

I don't think it will work either. The proper solution would be to check nesting of the found items e.g. if we have found "lodash/find.js" module then we should ignore it's size if we also found a whole "lodash" directory. So this task is not so simple and may require quite significant changes in the data structure that currently represents modules tree.

th0r avatar Feb 14 '19 23:02 th0r

@th0r why you think solution with checking this.searchQueryRegexp isn't ok?

kyriiherman avatar Feb 15 '19 09:02 kyriiherman

@kyriiherman (lodash$)|(react) is a valid RegExp that will match both lodash folder and all the react folders and modules. core\.js$ can match both core.js folder and core.js module. RegExp can't tell you what user is looking for.

th0r avatar Feb 15 '19 09:02 th0r

@th0r so we need to filter modules tree in foundModulesByChunk, but save its structure and then in foundModules use walkModules to convert modules tree into collection. with this approach we can use tree structure to count totalSize

kyriiherman avatar Feb 15 '19 11:02 kyriiherman

Just to clarify, the problem is still here, right? If yes, what do you think about this regexp, do I get the real number this way? 🤔 image

anatoliyarkhipov avatar Oct 25 '19 10:10 anatoliyarkhipov

Yes the problem is still there. I don't know the answer to your other question, maybe someone else knows.

valscion avatar Oct 25 '19 11:10 valscion

same problem 1610438777186-image

ppJuan avatar Jan 12 '21 08:01 ppJuan