Skip to content

Commit

Permalink
Merge pull request #386 from ZKHelloworld/fix-no-name-asset
Browse files Browse the repository at this point in the history
Fix assets without name causing analyze failure
  • Loading branch information
th0r committed Nov 7, 2020
2 parents 9624991 + 493c30c commit 0188312
Show file tree
Hide file tree
Showing 5 changed files with 513 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
## UNRELEASED

<!-- Add changelog entries for new changes under this section -->
* **Bug Fix**
* Fix `non-asset` assets causing analyze failure. ([##385](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/385) by [@ZKHelloworld](https://github.com/ZKHelloworld))

## 4.1.0

Expand Down
5 changes: 5 additions & 0 deletions src/analyzer.js
Expand Up @@ -49,6 +49,11 @@ function getViewerData(bundleStats, bundleDir, opts) {

// Picking only `*.js or *.mjs` assets from bundle that has non-empty `chunks` array
bundleStats.assets = _.filter(bundleStats.assets, asset => {
// Filter out non 'asset' type asset if type is provided (Webpack 5 add a type to indicate asset types)
if (asset.type && asset.type !== 'asset') {
return false;
}

// Removing query part from filename (yes, somebody uses it for some reason and Webpack supports it)
// See #22
asset.name = asset.name.replace(FILENAME_QUERY_REGEXP, '');
Expand Down
5 changes: 5 additions & 0 deletions test/analyzer.js
Expand Up @@ -155,6 +155,11 @@ describe('Analyzer', function () {
expect(chartData).to.containSubset(require('./stats/with-modules-in-chunks/expected-chart-data'));
});

it('should support stats files with non-asset asset', async function () {
generateReportFrom('with-non-asset-asset/stats.json');
await expectValidReport({bundleLabel: 'bundle.js'});
});

describe('options', function () {
describe('title', function () {
it('should take the --title option', async function () {
Expand Down
1 change: 1 addition & 0 deletions test/stats/with-non-asset-asset/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0188312

Please sign in to comment.