django-webpack / webpack-bundle-tracker

Spits out some stats about webpack compilation process to a file
MIT License
266 stars 107 forks source link

Sort properties of `assets` and `chunks` objects. #111

Closed etlovett closed 1 year ago

etlovett commented 1 year ago

This change ensures that the assets and chunks properties of the compilation output are sorted before the JSON is written to disk. This provides an increased degree of determinism in the output file, which is helpful when checking it into git or when running under a system like Bazel that caches build results. This commit only sorts the assets and chunks sub-objects because in practice those seem to be the ones most likely to differ.

Fixes issue #69.

etlovett commented 1 year ago

Note that this PR duplicates #70, with the following additions: sorting the chunks property, ensuring that the output file is sorted across all codepaths and after the final update to the file contents, and adding tests. If this one is merged I believe we can therefore close that one.

etlovett commented 1 year ago

FYI the CI failures appear to be due to the Node.js LTS and current versions changing this week, in conjunction with this Webpack issue: https://github.com/webpack/webpack/issues/14532. See also https://stackoverflow.com/a/73027407 and https://stackoverflow.com/a/73465262 for more context. I'm assuming those failures should therefore be handled separately, but let me know if you'd like me to do anything in this PR to resolve them.

fjsj commented 1 year ago

Thanks for the PR, we'll evaluate this soon.

fjsj commented 1 year ago

Thanks @etlovett I'm merging this one. If you can open another one to address the failures, please feel free.

etlovett commented 1 year ago

@fjsj Great, thanks! When should we expect this to be available in NPM? Do you have a release planned that this will go out in, or could you ship a new version just for it?

fjsj commented 1 year ago

This PR doesn't sort yet the chunkGroups, right? Ideally all nested objects should be sorted. But if that's too hard, I can make a release including only this change. @etlovett

etlovett commented 1 year ago

This PR doesn't sort yet the chunkGroups, right? Ideally all nested objects should be sorted.

@fjsj Is there a chunkGroups object in the output? I don't see one in the file produced in the tests at https://github.com/django-webpack/webpack-bundle-tracker/blob/5e6213cd7a26e23bf705e302e21f8d14ea945271/tests/base.test.js#L761. The only mention of chunkGroups in this codebase is on stats.compilation.chunkGroups here, which is used to produce the chunks property of the output file. Or is there something I'm missing?

I am aware of one thing I didn't sort the keys of: the top-level object itself. This was deliberate since in practice it's deterministic because of the way _handleDone is written, but I'd be happy to add that if you'd like.

fjsj commented 1 year ago

You're right, if chunks are sorted, then it's enough. Thanks, we'll make a release.

rvlb commented 1 year ago

Hi folks, we've released v1.7.0 on NPM https://www.npmjs.com/package/webpack-bundle-tracker

We've also updated django-webpack-loader on PyPi to ensure version parity across both libs https://pypi.org/project/django-webpack-loader/1.7.0/