From b39594cbf811d79a479e51d3d607a89b1717fa50 Mon Sep 17 00:00:00 2001 From: Devin Abbott Date: Fri, 28 Aug 2020 18:54:49 -0700 Subject: [PATCH 1/2] Fix missing child bundles throwing an error --- src/analyzer.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/analyzer.js b/src/analyzer.js index 0a93b34d..e7a84aa5 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -89,9 +89,8 @@ function getViewerData(bundleStats, bundleDir, opts) { const assets = _.transform(bundleStats.assets, (result, statAsset) => { // If asset is a childAsset, then calculate appropriate bundle modules by looking through stats.children - const modules = statAsset.isChild ? - getBundleModules(getChildAssetBundles(bundleStats, statAsset.name)) : - getBundleModules(bundleStats); + const assetBundles = statAsset.isChild ? getChildAssetBundles(bundleStats, statAsset.name) : bundleStats; + const modules = assetBundles ? getBundleModules(assetBundles) : []; const asset = result[statAsset.name] = _.pick(statAsset, 'size'); if (bundlesSources && _.has(bundlesSources, statAsset.name)) { From 0ddc92d4efa51187b651810845e61be1264fed90 Mon Sep 17 00:00:00 2001 From: Devin Abbott Date: Wed, 9 Sep 2020 14:27:18 -0700 Subject: [PATCH 2/2] Add test for dynamic imports in worker bundles --- test/analyzer.js | 8 + .../1.bundle.js | 1 + .../1.bundle.worker.js | 1 + .../bundle.js | 1 + .../bundle.worker.js | 1 + .../stats.json | 745 ++++++++++++++++++ 6 files changed, 757 insertions(+) create mode 100644 test/stats/with-worker-loader-dynamic-import/1.bundle.js create mode 100644 test/stats/with-worker-loader-dynamic-import/1.bundle.worker.js create mode 100644 test/stats/with-worker-loader-dynamic-import/bundle.js create mode 100644 test/stats/with-worker-loader-dynamic-import/bundle.worker.js create mode 100644 test/stats/with-worker-loader-dynamic-import/stats.json diff --git a/test/analyzer.js b/test/analyzer.js index 1bd0478a..477a3218 100644 --- a/test/analyzer.js +++ b/test/analyzer.js @@ -37,6 +37,14 @@ describe('Analyzer', function () { }); }); + it('should generate report when worker bundles have dynamic imports', async function () { + generateReportFrom('with-worker-loader-dynamic-import/stats.json'); + const chartData = await getChartData(); + expect(chartData[1]).to.containSubset({ + label: '1.bundle.worker.js' + }); + }); + it('should support stats files with modules inside `chunks` array', async function () { generateReportFrom('with-modules-in-chunks/stats.json'); const chartData = await getChartData(); diff --git a/test/stats/with-worker-loader-dynamic-import/1.bundle.js b/test/stats/with-worker-loader-dynamic-import/1.bundle.js new file mode 100644 index 00000000..9941554a --- /dev/null +++ b/test/stats/with-worker-loader-dynamic-import/1.bundle.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[1],[,function(n,e,o){"use strict";o.r(e),e.default=function(){return new Worker(o.p+"bundle.worker.js")}}]]); \ No newline at end of file diff --git a/test/stats/with-worker-loader-dynamic-import/1.bundle.worker.js b/test/stats/with-worker-loader-dynamic-import/1.bundle.worker.js new file mode 100644 index 00000000..a9003537 --- /dev/null +++ b/test/stats/with-worker-loader-dynamic-import/1.bundle.worker.js @@ -0,0 +1 @@ +self.webpackChunk([1],[,function(n,t,c){"use strict";c.r(t),c.d(t,"foo",(function(){return o}));const o=42}]); \ No newline at end of file diff --git a/test/stats/with-worker-loader-dynamic-import/bundle.js b/test/stats/with-worker-loader-dynamic-import/bundle.js new file mode 100644 index 00000000..05e4c3fc --- /dev/null +++ b/test/stats/with-worker-loader-dynamic-import/bundle.js @@ -0,0 +1 @@ +!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t)}]); \ No newline at end of file diff --git a/test/stats/with-worker-loader-dynamic-import/bundle.worker.js b/test/stats/with-worker-loader-dynamic-import/bundle.worker.js new file mode 100644 index 00000000..23473b43 --- /dev/null +++ b/test/stats/with-worker-loader-dynamic-import/bundle.worker.js @@ -0,0 +1 @@ +!function(e){self.webpackChunk=function(r,n){for(var o in n)e[o]=n[o];for(;r.length;)t[r.pop()]=1};var r={},t={0:1};function n(t){if(r[t])return r[t].exports;var o=r[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.e=function(e){var r=[];return r.push(Promise.resolve().then((function(){t[e]||importScripts(n.p+""+e+".bundle.worker.js")}))),Promise.all(r)},n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)n.d(t,o,function(r){return e[r]}.bind(null,o));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=0)}([function(e,r,t){"use strict";t.r(r),t.e(1).then(t.bind(null,1)),r.default={}}]); \ No newline at end of file diff --git a/test/stats/with-worker-loader-dynamic-import/stats.json b/test/stats/with-worker-loader-dynamic-import/stats.json new file mode 100644 index 00000000..e723fefa --- /dev/null +++ b/test/stats/with-worker-loader-dynamic-import/stats.json @@ -0,0 +1,745 @@ +{ + "errors": [ + ], + "warnings": [ + ], + "version": "4.44.1", + "hash": "6a922406d27e1f958522", + "time": 108, + "builtAt": 1599686616770, + "publicPath": "", + "outputPath": "/Users/devinabbott/Projects/wba-test/dist", + "assetsByChunkName": { + "main": "bundle.js" + }, + "assets": [ + { + "name": "1.bundle.worker.js", + "size": 110, + "chunks": [ + ], + "chunkNames": [ + ], + "info": { + }, + "emitted": true + }, + { + "name": "bundle.js", + "size": 951, + "chunks": [ + 0 + ], + "chunkNames": [ + "main" + ], + "info": { + }, + "emitted": true + }, + { + "name": "bundle.worker.js", + "size": 1230, + "chunks": [ + ], + "chunkNames": [ + ], + "info": { + }, + "emitted": true + } + ], + "filteredAssets": 0, + "entrypoints": { + "main": { + "chunks": [ + 0 + ], + "assets": [ + "bundle.js" + ], + "children": { + }, + "childAssets": { + } + } + }, + "namedChunkGroups": { + "main": { + "chunks": [ + 0 + ], + "assets": [ + "bundle.js" + ], + "children": { + }, + "childAssets": { + } + } + }, + "chunks": [ + { + "id": 0, + "rendered": true, + "initial": true, + "entry": true, + "size": 128, + "names": [ + "main" + ], + "files": [ + "bundle.js" + ], + "hash": "198ac11aa4df509d7a86", + "siblings": [ + ], + "parents": [ + ], + "children": [ + ], + "childrenByOrder": { + }, + "modules": [ + { + "id": 0, + "identifier": "/Users/devinabbott/Projects/wba-test/index.js d7f0419a44af2953980a1e234962b7cb", + "name": "./index.js + 1 modules", + "index": 0, + "index2": 1, + "size": 128, + "cacheable": false, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + 0 + ], + "issuer": null, + "issuerId": null, + "issuerName": null, + "issuerPath": null, + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": null, + "moduleIdentifier": null, + "module": null, + "moduleName": null, + "type": "single entry", + "userRequest": "./index.js", + "loc": "main" + } + ], + "usedExports": true, + "providedExports": [ + ], + "optimizationBailout": [ + ], + "depth": 0, + "modules": [ + { + "id": null, + "identifier": "/Users/devinabbott/Projects/wba-test/index.js", + "name": "./index.js", + "index": 0, + "index2": 1, + "size": 31, + "cacheable": true, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + ], + "issuer": null, + "issuerId": null, + "issuerName": null, + "issuerPath": null, + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": null, + "moduleIdentifier": null, + "module": null, + "moduleName": null, + "type": "single entry", + "userRequest": "./index.js", + "loc": "main" + } + ], + "usedExports": true, + "providedExports": [ + ], + "optimizationBailout": [ + "ModuleConcatenation bailout: Module is an entry point" + ], + "depth": 0, + "source": "import worker from \"./worker\";\n" + }, + { + "id": null, + "identifier": "/Users/devinabbott/Projects/wba-test/node_modules/worker-loader/dist/cjs.js!/Users/devinabbott/Projects/wba-test/worker.js", + "name": "./worker.js", + "index": 1, + "index2": 0, + "size": 97, + "cacheable": false, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + ], + "issuer": "/Users/devinabbott/Projects/wba-test/index.js", + "issuerId": null, + "issuerName": "./index.js", + "issuerPath": [ + { + "id": null, + "identifier": "/Users/devinabbott/Projects/wba-test/index.js", + "name": "./index.js" + } + ], + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": null, + "moduleIdentifier": "/Users/devinabbott/Projects/wba-test/index.js", + "module": "./index.js", + "moduleName": "./index.js", + "type": "harmony side effect evaluation", + "userRequest": "./worker", + "loc": "1:0-30" + } + ], + "usedExports": false, + "providedExports": [ + "default" + ], + "optimizationBailout": [ + ], + "depth": 1, + "source": "export default function() {\n return new Worker(__webpack_public_path__ + \"bundle.worker.js\");\n}\n" + } + ], + "filteredModules": 0 + } + ], + "filteredModules": 0, + "origins": [ + { + "module": "", + "moduleIdentifier": "", + "moduleName": "", + "loc": "main", + "request": "./index.js", + "reasons": [ + ] + } + ] + } + ], + "modules": [ + { + "id": 0, + "identifier": "/Users/devinabbott/Projects/wba-test/index.js d7f0419a44af2953980a1e234962b7cb", + "name": "./index.js + 1 modules", + "index": 0, + "index2": 1, + "size": 128, + "cacheable": false, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + 0 + ], + "issuer": null, + "issuerId": null, + "issuerName": null, + "issuerPath": null, + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": null, + "moduleIdentifier": null, + "module": null, + "moduleName": null, + "type": "single entry", + "userRequest": "./index.js", + "loc": "main" + } + ], + "usedExports": true, + "providedExports": [ + ], + "optimizationBailout": [ + ], + "depth": 0, + "modules": [ + { + "id": null, + "identifier": "/Users/devinabbott/Projects/wba-test/index.js", + "name": "./index.js", + "index": 0, + "index2": 1, + "size": 31, + "cacheable": true, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + ], + "issuer": null, + "issuerId": null, + "issuerName": null, + "issuerPath": null, + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": null, + "moduleIdentifier": null, + "module": null, + "moduleName": null, + "type": "single entry", + "userRequest": "./index.js", + "loc": "main" + } + ], + "usedExports": true, + "providedExports": [ + ], + "optimizationBailout": [ + "ModuleConcatenation bailout: Module is an entry point" + ], + "depth": 0, + "source": "import worker from \"./worker\";\n" + }, + { + "id": null, + "identifier": "/Users/devinabbott/Projects/wba-test/node_modules/worker-loader/dist/cjs.js!/Users/devinabbott/Projects/wba-test/worker.js", + "name": "./worker.js", + "index": 1, + "index2": 0, + "size": 97, + "cacheable": false, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + ], + "issuer": "/Users/devinabbott/Projects/wba-test/index.js", + "issuerId": null, + "issuerName": "./index.js", + "issuerPath": [ + { + "id": null, + "identifier": "/Users/devinabbott/Projects/wba-test/index.js", + "name": "./index.js" + } + ], + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": null, + "moduleIdentifier": "/Users/devinabbott/Projects/wba-test/index.js", + "module": "./index.js", + "moduleName": "./index.js", + "type": "harmony side effect evaluation", + "userRequest": "./worker", + "loc": "1:0-30" + } + ], + "usedExports": false, + "providedExports": [ + "default" + ], + "optimizationBailout": [ + ], + "depth": 1, + "source": "export default function() {\n return new Worker(__webpack_public_path__ + \"bundle.worker.js\");\n}\n" + } + ], + "filteredModules": 0 + } + ], + "filteredModules": 0, + "logging": { + "webpack.buildChunkGraph.visitModules": { + "entries": [ + ], + "filteredEntries": 2, + "debug": false + } + }, + "children": [ + { + "errors": [ + ], + "warnings": [ + ], + "publicPath": "", + "outputPath": "/Users/devinabbott/Projects/wba-test/dist", + "assetsByChunkName": { + "worker": "bundle.worker.js" + }, + "assets": [ + { + "name": "1.bundle.worker.js", + "size": 110, + "chunks": [ + 1 + ], + "chunkNames": [ + ], + "info": { + }, + "emitted": true + }, + { + "name": "bundle.worker.js", + "size": 1230, + "chunks": [ + 0 + ], + "chunkNames": [ + "worker" + ], + "info": { + }, + "emitted": true + } + ], + "filteredAssets": 0, + "entrypoints": { + "worker": { + "chunks": [ + 0 + ], + "assets": [ + "bundle.worker.js" + ], + "children": { + }, + "childAssets": { + } + } + }, + "namedChunkGroups": { + "worker": { + "chunks": [ + 0 + ], + "assets": [ + "bundle.worker.js" + ], + "children": { + }, + "childAssets": { + } + } + }, + "chunks": [ + { + "id": 0, + "rendered": true, + "initial": true, + "entry": true, + "size": 44, + "names": [ + "worker" + ], + "files": [ + "bundle.worker.js" + ], + "hash": "b4762f21c1a5d6d1a430", + "siblings": [ + ], + "parents": [ + ], + "children": [ + 1 + ], + "childrenByOrder": { + }, + "modules": [ + { + "id": 0, + "identifier": "/Users/devinabbott/Projects/wba-test/worker.js", + "name": "./worker.js", + "index": 0, + "index2": 0, + "size": 44, + "cacheable": true, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + 0 + ], + "issuer": null, + "issuerId": null, + "issuerName": null, + "issuerPath": null, + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": null, + "moduleIdentifier": null, + "module": null, + "moduleName": null, + "type": "single entry", + "userRequest": "!!/Users/devinabbott/Projects/wba-test/worker.js", + "loc": "worker" + } + ], + "usedExports": true, + "providedExports": [ + "default" + ], + "optimizationBailout": [ + "ModuleConcatenation bailout: Module is an entry point" + ], + "depth": 0, + "source": "import(\"./worker-dep\");\n\nexport default {};\n" + } + ], + "filteredModules": 0, + "origins": [ + { + "module": "", + "moduleIdentifier": "", + "moduleName": "", + "loc": "worker", + "request": "!!/Users/devinabbott/Projects/wba-test/worker.js", + "reasons": [ + ] + } + ] + }, + { + "id": 1, + "rendered": true, + "initial": false, + "entry": false, + "size": 23, + "names": [ + ], + "files": [ + "1.bundle.worker.js" + ], + "hash": "72bd0d9c0a92a4a4dbf3", + "siblings": [ + ], + "parents": [ + 0 + ], + "children": [ + ], + "childrenByOrder": { + }, + "modules": [ + { + "id": 1, + "identifier": "/Users/devinabbott/Projects/wba-test/worker-dep.js", + "name": "./worker-dep.js", + "index": 1, + "index2": 1, + "size": 23, + "cacheable": true, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + 1 + ], + "issuer": "/Users/devinabbott/Projects/wba-test/worker.js", + "issuerId": 0, + "issuerName": "./worker.js", + "issuerPath": [ + { + "id": 0, + "identifier": "/Users/devinabbott/Projects/wba-test/worker.js", + "name": "./worker.js" + } + ], + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": 0, + "moduleIdentifier": "/Users/devinabbott/Projects/wba-test/worker.js", + "module": "./worker.js", + "moduleName": "./worker.js", + "type": "import()", + "userRequest": "./worker-dep", + "loc": "1:0-22" + } + ], + "usedExports": true, + "providedExports": [ + "foo" + ], + "optimizationBailout": [ + "ModuleConcatenation bailout: Module is referenced from these modules with unsupported syntax: ./worker.js (referenced with import())" + ], + "depth": 1, + "source": "export const foo = 42;\n" + } + ], + "filteredModules": 0, + "origins": [ + { + "moduleId": 0, + "module": "/Users/devinabbott/Projects/wba-test/worker.js", + "moduleIdentifier": "/Users/devinabbott/Projects/wba-test/worker.js", + "moduleName": "./worker.js", + "loc": "1:0-22", + "request": "./worker-dep", + "reasons": [ + ] + } + ] + } + ], + "modules": [ + { + "id": 0, + "identifier": "/Users/devinabbott/Projects/wba-test/worker.js", + "name": "./worker.js", + "index": 0, + "index2": 0, + "size": 44, + "cacheable": true, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + 0 + ], + "issuer": null, + "issuerId": null, + "issuerName": null, + "issuerPath": null, + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": null, + "moduleIdentifier": null, + "module": null, + "moduleName": null, + "type": "single entry", + "userRequest": "!!/Users/devinabbott/Projects/wba-test/worker.js", + "loc": "worker" + } + ], + "usedExports": true, + "providedExports": [ + "default" + ], + "optimizationBailout": [ + "ModuleConcatenation bailout: Module is an entry point" + ], + "depth": 0, + "source": "import(\"./worker-dep\");\n\nexport default {};\n" + }, + { + "id": 1, + "identifier": "/Users/devinabbott/Projects/wba-test/worker-dep.js", + "name": "./worker-dep.js", + "index": 1, + "index2": 1, + "size": 23, + "cacheable": true, + "built": true, + "optional": false, + "prefetched": false, + "chunks": [ + 1 + ], + "issuer": "/Users/devinabbott/Projects/wba-test/worker.js", + "issuerId": 0, + "issuerName": "./worker.js", + "issuerPath": [ + { + "id": 0, + "identifier": "/Users/devinabbott/Projects/wba-test/worker.js", + "name": "./worker.js" + } + ], + "failed": false, + "errors": 0, + "warnings": 0, + "assets": [ + ], + "reasons": [ + { + "moduleId": 0, + "moduleIdentifier": "/Users/devinabbott/Projects/wba-test/worker.js", + "module": "./worker.js", + "moduleName": "./worker.js", + "type": "import()", + "userRequest": "./worker-dep", + "loc": "1:0-22" + } + ], + "usedExports": true, + "providedExports": [ + "foo" + ], + "optimizationBailout": [ + "ModuleConcatenation bailout: Module is referenced from these modules with unsupported syntax: ./worker.js (referenced with import())" + ], + "depth": 1, + "source": "export const foo = 42;\n" + } + ], + "filteredModules": 0, + "logging": { + "webpack.buildChunkGraph.visitModules": { + "entries": [ + ], + "filteredEntries": 5, + "debug": false + } + }, + "children": [ + ], + "name": "worker-loader worker.js" + } + ] +} \ No newline at end of file