Skip to content

Commit d04b767

Browse files
authored
Merge pull request #394 from ctavan/fix-webpack-array-config
Fix handling of webpack array configs
2 parents d093666 + 303d801 commit d04b767

6 files changed

Lines changed: 355 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
1414

1515
<!-- Add changelog entries for new changes under this section -->
1616
* **Bug Fix**
17-
* Fix `non-asset` assets causing analyze failure. ([##385](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/385) by [@ZKHelloworld](https://github.com/ZKHelloworld))
17+
* Prevent crashes for bundles generated from webpack array configs. ([#394](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/394) by [@ctavan](https://github.com/ctavan))
18+
* Fix `non-asset` assets causing analyze failure. ([#385](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/385) by [@ZKHelloworld](https://github.com/ZKHelloworld))
1819

1920
## 4.1.0
2021

src/analyzer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
3232
// Sometimes if there are additional child chunks produced add them as child assets,
3333
// leave the 1st one as that is considered the 'root' asset.
3434
for (let i = 1; i < children.length; i++) {
35-
bundleStats.children[i].assets.forEach((asset) => {
35+
children[i].assets.forEach((asset) => {
3636
asset.isChild = true;
3737
bundleStats.assets.push(asset);
3838
});

test/analyzer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ describe('Analyzer', function () {
3737
});
3838
});
3939

40+
it('should generate report for array webpack.config.js', async function () {
41+
generateReportFrom('with-array-config/stats.json');
42+
const chartData = await getChartData();
43+
expect(chartData).to.have.lengthOf(2);
44+
expect(chartData[0]).to.containSubset({
45+
label: 'config-1-main.js'
46+
});
47+
expect(chartData[1]).to.containSubset({
48+
label: 'config-2-main.js'
49+
});
50+
});
51+
4052
it('should generate report when worker bundles have dynamic imports', async function () {
4153
generateReportFrom('with-worker-loader-dynamic-import/stats.json');
4254
const chartData = await getChartData();

test/stats/with-array-config/config-1-main.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/stats/with-array-config/config-2-main.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
{
2+
"errors": [],
3+
"warnings": [],
4+
"version": "4.44.2",
5+
"hash": "a30aaa779dd06e8979b1a30aaa779dd06e8979b1",
6+
"children": [
7+
{
8+
"errors": [],
9+
"warnings": [],
10+
"hash": "a30aaa779dd06e8979b1",
11+
"time": 105,
12+
"builtAt": 1605088887042,
13+
"publicPath": "",
14+
"outputPath": "/webpack-bundle-analyzer-example/",
15+
"assetsByChunkName": {
16+
"main": "config-1-main.js"
17+
},
18+
"assets": [
19+
{
20+
"name": "config-1-main.js",
21+
"size": 948,
22+
"chunks": [0],
23+
"chunkNames": ["main"],
24+
"info": {},
25+
"emitted": true
26+
}
27+
],
28+
"filteredAssets": 0,
29+
"entrypoints": {
30+
"main": {
31+
"chunks": [0],
32+
"assets": ["config-1-main.js"],
33+
"children": {},
34+
"childAssets": {}
35+
}
36+
},
37+
"namedChunkGroups": {
38+
"main": {
39+
"chunks": [0],
40+
"assets": ["config-1-main.js"],
41+
"children": {},
42+
"childAssets": {}
43+
}
44+
},
45+
"chunks": [
46+
{
47+
"id": 0,
48+
"rendered": true,
49+
"initial": true,
50+
"entry": true,
51+
"size": 20,
52+
"names": ["main"],
53+
"files": ["config-1-main.js"],
54+
"hash": "0e20b5164c4e5cda6fe0",
55+
"siblings": [],
56+
"parents": [],
57+
"children": [],
58+
"childrenByOrder": {},
59+
"modules": [
60+
{
61+
"id": 0,
62+
"identifier": "/webpack-bundle-analyzer-example/src/index.js",
63+
"name": "./src/index.js",
64+
"index": 0,
65+
"index2": 0,
66+
"size": 20,
67+
"cacheable": true,
68+
"built": true,
69+
"optional": false,
70+
"prefetched": false,
71+
"chunks": [0],
72+
"issuer": null,
73+
"issuerId": null,
74+
"issuerName": null,
75+
"issuerPath": null,
76+
"profile": {
77+
"factory": 35,
78+
"building": 38
79+
},
80+
"failed": false,
81+
"errors": 0,
82+
"warnings": 0,
83+
"assets": [],
84+
"reasons": [
85+
{
86+
"moduleId": null,
87+
"moduleIdentifier": null,
88+
"module": null,
89+
"moduleName": null,
90+
"type": "single entry",
91+
"userRequest": "./src/index.js",
92+
"loc": "main"
93+
}
94+
],
95+
"usedExports": true,
96+
"providedExports": null,
97+
"optimizationBailout": [
98+
"ModuleConcatenation bailout: Module is not an ECMAScript module"
99+
],
100+
"depth": 0,
101+
"source": "console.log('ABC');\n"
102+
}
103+
],
104+
"filteredModules": 0,
105+
"origins": [
106+
{
107+
"module": "",
108+
"moduleIdentifier": "",
109+
"moduleName": "",
110+
"loc": "main",
111+
"request": "./src/index.js",
112+
"reasons": []
113+
}
114+
]
115+
}
116+
],
117+
"modules": [
118+
{
119+
"id": 0,
120+
"identifier": "/webpack-bundle-analyzer-example/src/index.js",
121+
"name": "./src/index.js",
122+
"index": 0,
123+
"index2": 0,
124+
"size": 20,
125+
"cacheable": true,
126+
"built": true,
127+
"optional": false,
128+
"prefetched": false,
129+
"chunks": [0],
130+
"issuer": null,
131+
"issuerId": null,
132+
"issuerName": null,
133+
"issuerPath": null,
134+
"profile": {
135+
"factory": 35,
136+
"building": 38
137+
},
138+
"failed": false,
139+
"errors": 0,
140+
"warnings": 0,
141+
"assets": [],
142+
"reasons": [
143+
{
144+
"moduleId": null,
145+
"moduleIdentifier": null,
146+
"module": null,
147+
"moduleName": null,
148+
"type": "single entry",
149+
"userRequest": "./src/index.js",
150+
"loc": "main"
151+
}
152+
],
153+
"usedExports": true,
154+
"providedExports": null,
155+
"optimizationBailout": [
156+
"ModuleConcatenation bailout: Module is not an ECMAScript module"
157+
],
158+
"depth": 0,
159+
"source": "console.log('ABC');\n"
160+
}
161+
],
162+
"filteredModules": 0,
163+
"logging": {
164+
"webpack.buildChunkGraph.visitModules": {
165+
"entries": [],
166+
"filteredEntries": 2,
167+
"debug": false
168+
}
169+
},
170+
"children": []
171+
},
172+
{
173+
"errors": [],
174+
"warnings": [],
175+
"hash": "a30aaa779dd06e8979b1",
176+
"time": 88,
177+
"builtAt": 1605088887043,
178+
"publicPath": "",
179+
"outputPath": "/webpack-bundle-analyzer-example/",
180+
"assetsByChunkName": {
181+
"main": "config-2-main.js"
182+
},
183+
"assets": [
184+
{
185+
"name": "config-2-main.js",
186+
"size": 948,
187+
"chunks": [0],
188+
"chunkNames": ["main"],
189+
"info": {},
190+
"emitted": true
191+
}
192+
],
193+
"filteredAssets": 0,
194+
"entrypoints": {
195+
"main": {
196+
"chunks": [0],
197+
"assets": ["config-2-main.js"],
198+
"children": {},
199+
"childAssets": {}
200+
}
201+
},
202+
"namedChunkGroups": {
203+
"main": {
204+
"chunks": [0],
205+
"assets": ["config-2-main.js"],
206+
"children": {},
207+
"childAssets": {}
208+
}
209+
},
210+
"chunks": [
211+
{
212+
"id": 0,
213+
"rendered": true,
214+
"initial": true,
215+
"entry": true,
216+
"size": 20,
217+
"names": ["main"],
218+
"files": ["config-2-main.js"],
219+
"hash": "0e20b5164c4e5cda6fe0",
220+
"siblings": [],
221+
"parents": [],
222+
"children": [],
223+
"childrenByOrder": {},
224+
"modules": [
225+
{
226+
"id": 0,
227+
"identifier": "/webpack-bundle-analyzer-example/src/index.js",
228+
"name": "./src/index.js",
229+
"index": 0,
230+
"index2": 0,
231+
"size": 20,
232+
"cacheable": true,
233+
"built": true,
234+
"optional": false,
235+
"prefetched": false,
236+
"chunks": [0],
237+
"issuer": null,
238+
"issuerId": null,
239+
"issuerName": null,
240+
"issuerPath": null,
241+
"profile": {
242+
"factory": 29,
243+
"building": 9
244+
},
245+
"failed": false,
246+
"errors": 0,
247+
"warnings": 0,
248+
"assets": [],
249+
"reasons": [
250+
{
251+
"moduleId": null,
252+
"moduleIdentifier": null,
253+
"module": null,
254+
"moduleName": null,
255+
"type": "single entry",
256+
"userRequest": "./src/index.js",
257+
"loc": "main"
258+
}
259+
],
260+
"usedExports": true,
261+
"providedExports": null,
262+
"optimizationBailout": [
263+
"ModuleConcatenation bailout: Module is not an ECMAScript module"
264+
],
265+
"depth": 0,
266+
"source": "console.log('ABC');\n"
267+
}
268+
],
269+
"filteredModules": 0,
270+
"origins": [
271+
{
272+
"module": "",
273+
"moduleIdentifier": "",
274+
"moduleName": "",
275+
"loc": "main",
276+
"request": "./src/index.js",
277+
"reasons": []
278+
}
279+
]
280+
}
281+
],
282+
"modules": [
283+
{
284+
"id": 0,
285+
"identifier": "/webpack-bundle-analyzer-example/src/index.js",
286+
"name": "./src/index.js",
287+
"index": 0,
288+
"index2": 0,
289+
"size": 20,
290+
"cacheable": true,
291+
"built": true,
292+
"optional": false,
293+
"prefetched": false,
294+
"chunks": [0],
295+
"issuer": null,
296+
"issuerId": null,
297+
"issuerName": null,
298+
"issuerPath": null,
299+
"profile": {
300+
"factory": 29,
301+
"building": 9
302+
},
303+
"failed": false,
304+
"errors": 0,
305+
"warnings": 0,
306+
"assets": [],
307+
"reasons": [
308+
{
309+
"moduleId": null,
310+
"moduleIdentifier": null,
311+
"module": null,
312+
"moduleName": null,
313+
"type": "single entry",
314+
"userRequest": "./src/index.js",
315+
"loc": "main"
316+
}
317+
],
318+
"usedExports": true,
319+
"providedExports": null,
320+
"optimizationBailout": [
321+
"ModuleConcatenation bailout: Module is not an ECMAScript module"
322+
],
323+
"depth": 0,
324+
"source": "console.log('ABC');\n"
325+
}
326+
],
327+
"filteredModules": 0,
328+
"logging": {
329+
"webpack.buildChunkGraph.visitModules": {
330+
"entries": [],
331+
"filteredEntries": 2,
332+
"debug": false
333+
}
334+
},
335+
"children": []
336+
}
337+
]
338+
}

0 commit comments

Comments
 (0)