From bb246e6caadbabeaf8585977fd9f815609841419 Mon Sep 17 00:00:00 2001 From: zhengkenghong Date: Tue, 13 Oct 2020 01:28:00 +0800 Subject: [PATCH 1/3] Fix assets without name causing analyze failure --- src/analyzer.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/analyzer.js b/src/analyzer.js index 35bd2e19..b1141b97 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -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, ''); From 9873f278dd95bcb91d177481a2f31b74f4b9c32b Mon Sep 17 00:00:00 2001 From: zhengkenghong Date: Wed, 14 Oct 2020 01:21:43 +0800 Subject: [PATCH 2/3] Add test for non-asset asset --- test/analyzer.js | 5 + test/stats/with-non-asset-asset/bundle.js | 1 + test/stats/with-non-asset-asset/stats.json | 500 +++++++++++++++++++++ 3 files changed, 506 insertions(+) create mode 100644 test/stats/with-non-asset-asset/bundle.js create mode 100644 test/stats/with-non-asset-asset/stats.json diff --git a/test/analyzer.js b/test/analyzer.js index 4765255e..e9e01adc 100644 --- a/test/analyzer.js +++ b/test/analyzer.js @@ -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 () { diff --git a/test/stats/with-non-asset-asset/bundle.js b/test/stats/with-non-asset-asset/bundle.js new file mode 100644 index 00000000..071d44b2 --- /dev/null +++ b/test/stats/with-non-asset-asset/bundle.js @@ -0,0 +1 @@ +(()=>{var r={146:r=>{r.exports="module a"},296:r=>{r.exports="module a"},260:r=>{r.exports="module b"}},e={};function o(t){if(e[t])return e[t].exports;var p=e[t]={exports:{}};return r[t](p,p.exports,o),p.exports}o(296),o(260),o(146)})(); \ No newline at end of file diff --git a/test/stats/with-non-asset-asset/stats.json b/test/stats/with-non-asset-asset/stats.json new file mode 100644 index 00000000..946bb94b --- /dev/null +++ b/test/stats/with-non-asset-asset/stats.json @@ -0,0 +1,500 @@ +{ + "hash": "a00ccf8c892bb7cacd85", + "version": "5.1.0", + "time": 279, + "builtAt": 1602608505481, + "publicPath": "auto", + "outputPath": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/stats/with-non-asset-chunk", + "assetsByChunkName": { + "main": [ + "bundle.js" + ] + }, + "assets": [ + { + "type": "hidden assets", + "filteredChildren": 1, + "size": 29 + }, + { + "type": "asset", + "name": "bundle.js", + "size": 237, + "chunkNames": [ + "main" + ], + "chunkIdHints": [], + "auxiliaryChunkNames": [], + "auxiliaryChunkIdHints": [], + "emitted": true, + "comparedForEmit": false, + "cached": false, + "info": { + "minimized": true, + "size": 237 + }, + "related": {}, + "chunks": [ + 179 + ], + "auxiliaryChunks": [], + "isOverSizeLimit": false + } + ], + "chunks": [ + { + "rendered": true, + "initial": true, + "entry": true, + "recorded": false, + "size": 141, + "sizes": { + "javascript": 141 + }, + "names": [ + "main" + ], + "idHints": [], + "runtime": [ + "main" + ], + "files": [ + "bundle.js" + ], + "auxiliaryFiles": [], + "hash": "368fad705e34fecd2ddf", + "childrenByOrder": {}, + "id": 179, + "siblings": [], + "parents": [], + "children": [], + "origins": [ + { + "module": "", + "moduleIdentifier": "", + "moduleName": "", + "loc": "main", + "request": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js" + } + ] + } + ], + "modules": [ + { + "type": "module", + "moduleType": "javascript/auto", + "identifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "name": "./test/src/index.js", + "nameForCondition": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "index": 0, + "preOrderIndex": 0, + "index2": 3, + "postOrderIndex": 3, + "size": 54, + "sizes": { + "javascript": 54 + }, + "cacheable": true, + "built": true, + "codeGenerated": true, + "cached": false, + "optional": false, + "orphan": false, + "issuer": null, + "issuerName": null, + "issuerPath": null, + "failed": false, + "errors": 0, + "warnings": 0, + "profile": { + "total": 44, + "resolving": 28, + "restoring": 0, + "building": 16, + "integration": 0, + "storing": 0, + "additionalResolving": 0, + "additionalIntegration": 0, + "factory": 28, + "dependencies": 0 + }, + "id": 755, + "issuerId": null, + "chunks": [ + 179 + ], + "assets": [], + "reasons": [ + { + "moduleIdentifier": null, + "module": null, + "moduleName": null, + "resolvedModuleIdentifier": null, + "resolvedModule": null, + "type": "entry", + "active": true, + "explanation": "", + "userRequest": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "loc": "main", + "moduleId": null, + "resolvedModuleId": null + } + ], + "usedExports": [], + "providedExports": null, + "optimizationBailout": [ + "ModuleConcatenation bailout: Module is not an ECMAScript module" + ], + "depth": 0 + }, + { + "type": "module", + "moduleType": "javascript/auto", + "identifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/a.js", + "name": "./test/src/a.js", + "nameForCondition": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/a.js", + "index": 1, + "preOrderIndex": 1, + "index2": 0, + "postOrderIndex": 0, + "size": 29, + "sizes": { + "javascript": 29 + }, + "cacheable": true, + "built": true, + "codeGenerated": true, + "cached": false, + "optional": false, + "orphan": false, + "issuer": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "issuerName": "./test/src/index.js", + "issuerPath": [ + { + "identifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "name": "./test/src/index.js", + "profile": { + "total": 44, + "resolving": 28, + "restoring": 0, + "building": 16, + "integration": 0, + "storing": 0, + "additionalResolving": 0, + "additionalIntegration": 0, + "factory": 28, + "dependencies": 0 + }, + "id": 755 + } + ], + "failed": false, + "errors": 0, + "warnings": 0, + "profile": { + "total": 0, + "resolving": 0, + "restoring": 0, + "building": 0, + "integration": 0, + "storing": 0, + "additionalResolving": 0, + "additionalIntegration": 0, + "factory": 0, + "dependencies": 0 + }, + "id": 296, + "issuerId": 755, + "chunks": [ + 179 + ], + "assets": [], + "reasons": [ + { + "moduleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/a.js", + "module": "./test/src/a.js", + "moduleName": "./test/src/a.js", + "resolvedModuleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/a.js", + "resolvedModule": "./test/src/a.js", + "type": "cjs self exports reference", + "active": true, + "explanation": "", + "userRequest": null, + "loc": "1:0-14", + "moduleId": 296, + "resolvedModuleId": 296 + }, + { + "moduleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "module": "./test/src/index.js", + "moduleName": "./test/src/index.js", + "resolvedModuleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "resolvedModule": "./test/src/index.js", + "type": "cjs require", + "active": true, + "explanation": "", + "userRequest": "./a", + "loc": "1:0-14", + "moduleId": 755, + "resolvedModuleId": 755 + } + ], + "usedExports": null, + "providedExports": null, + "optimizationBailout": [ + "CommonJS bailout: module.exports is used directly at 1:0-14", + "ModuleConcatenation bailout: Module is not an ECMAScript module" + ], + "depth": 1 + }, + { + "type": "module", + "moduleType": "javascript/auto", + "identifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/b.js", + "name": "./test/src/b.js", + "nameForCondition": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/b.js", + "index": 2, + "preOrderIndex": 2, + "index2": 1, + "postOrderIndex": 1, + "size": 29, + "sizes": { + "javascript": 29 + }, + "cacheable": true, + "built": true, + "codeGenerated": true, + "cached": false, + "optional": false, + "orphan": false, + "issuer": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "issuerName": "./test/src/index.js", + "issuerPath": [ + { + "identifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "name": "./test/src/index.js", + "profile": { + "total": 44, + "resolving": 28, + "restoring": 0, + "building": 16, + "integration": 0, + "storing": 0, + "additionalResolving": 0, + "additionalIntegration": 0, + "factory": 28, + "dependencies": 0 + }, + "id": 755 + } + ], + "failed": false, + "errors": 0, + "warnings": 0, + "profile": { + "total": 0, + "resolving": 0, + "restoring": 0, + "building": 0, + "integration": 0, + "storing": 0, + "additionalResolving": 0, + "additionalIntegration": 0, + "factory": 0, + "dependencies": 0 + }, + "id": 260, + "issuerId": 755, + "chunks": [ + 179 + ], + "assets": [], + "reasons": [ + { + "moduleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/b.js", + "module": "./test/src/b.js", + "moduleName": "./test/src/b.js", + "resolvedModuleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/b.js", + "resolvedModule": "./test/src/b.js", + "type": "cjs self exports reference", + "active": true, + "explanation": "", + "userRequest": null, + "loc": "1:0-14", + "moduleId": 260, + "resolvedModuleId": 260 + }, + { + "moduleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "module": "./test/src/index.js", + "moduleName": "./test/src/index.js", + "resolvedModuleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "resolvedModule": "./test/src/index.js", + "type": "cjs require", + "active": true, + "explanation": "", + "userRequest": "./b", + "loc": "2:0-14", + "moduleId": 755, + "resolvedModuleId": 755 + } + ], + "usedExports": null, + "providedExports": null, + "optimizationBailout": [ + "CommonJS bailout: module.exports is used directly at 1:0-14", + "ModuleConcatenation bailout: Module is not an ECMAScript module" + ], + "depth": 1 + }, + { + "type": "module", + "moduleType": "javascript/auto", + "identifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/a-clone.js", + "name": "./test/src/a-clone.js", + "nameForCondition": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/a-clone.js", + "index": 3, + "preOrderIndex": 3, + "index2": 2, + "postOrderIndex": 2, + "size": 29, + "sizes": { + "javascript": 29 + }, + "cacheable": true, + "built": true, + "codeGenerated": true, + "cached": false, + "optional": false, + "orphan": false, + "issuer": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "issuerName": "./test/src/index.js", + "issuerPath": [ + { + "identifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "name": "./test/src/index.js", + "profile": { + "total": 44, + "resolving": 28, + "restoring": 0, + "building": 16, + "integration": 0, + "storing": 0, + "additionalResolving": 0, + "additionalIntegration": 0, + "factory": 28, + "dependencies": 0 + }, + "id": 755 + } + ], + "failed": false, + "errors": 0, + "warnings": 0, + "profile": { + "total": 0, + "resolving": 0, + "restoring": 0, + "building": 0, + "integration": 0, + "storing": 0, + "additionalResolving": 0, + "additionalIntegration": 0, + "factory": 0, + "dependencies": 0 + }, + "id": 146, + "issuerId": 755, + "chunks": [ + 179 + ], + "assets": [], + "reasons": [ + { + "moduleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/a-clone.js", + "module": "./test/src/a-clone.js", + "moduleName": "./test/src/a-clone.js", + "resolvedModuleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/a-clone.js", + "resolvedModule": "./test/src/a-clone.js", + "type": "cjs self exports reference", + "active": true, + "explanation": "", + "userRequest": null, + "loc": "1:0-14", + "moduleId": 146, + "resolvedModuleId": 146 + }, + { + "moduleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "module": "./test/src/index.js", + "moduleName": "./test/src/index.js", + "resolvedModuleIdentifier": "/Users/zhengkenghong/Projects/Other/webpack-bundle-analyzer/test/src/index.js", + "resolvedModule": "./test/src/index.js", + "type": "cjs require", + "active": true, + "explanation": "", + "userRequest": "./a-clone", + "loc": "3:0-20", + "moduleId": 755, + "resolvedModuleId": 755 + } + ], + "usedExports": null, + "providedExports": null, + "optimizationBailout": [ + "CommonJS bailout: module.exports is used directly at 1:0-14", + "ModuleConcatenation bailout: Module is not an ECMAScript module" + ], + "depth": 1 + } + ], + "entrypoints": { + "main": { + "name": "main", + "chunks": [ + 179 + ], + "assets": [ + { + "name": "bundle.js", + "size": 237 + } + ], + "filteredAssets": 0, + "assetsSize": 237, + "auxiliaryAssets": [], + "filteredAuxiliaryAssets": 0, + "auxiliaryAssetsSize": 0, + "children": {}, + "childAssets": {}, + "isOverSizeLimit": false + } + }, + "namedChunkGroups": { + "main": { + "name": "main", + "chunks": [ + 179 + ], + "assets": [ + { + "name": "bundle.js", + "size": 237 + } + ], + "filteredAssets": 0, + "assetsSize": 237, + "auxiliaryAssets": [], + "filteredAuxiliaryAssets": 0, + "auxiliaryAssetsSize": 0, + "children": {}, + "childAssets": {}, + "isOverSizeLimit": false + } + }, + "errors": [], + "errorsCount": 0, + "warnings": [], + "warningsCount": 0, + "children": [] +} From 493c30c9d06e4dddf3ba9d2f736002ed8beb8df8 Mon Sep 17 00:00:00 2001 From: zhengkenghong Date: Wed, 14 Oct 2020 01:31:36 +0800 Subject: [PATCH 3/3] Add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 377e0b74..6b3554b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ _Note: Gaps between patch versions are faulty, broken or test releases._ ## UNRELEASED + * **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