Skip to content

Commit 10a4d09

Browse files
committed
feat: handle undefined assets/modules in analyzer with minimal stats support
1 parent ed1eebe commit 10a4d09

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/analyzer.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ function getViewerData(bundleStats, bundleDir, opts) {
2626

2727
const isAssetIncluded = createAssetsFilter(excludeAssets);
2828

29-
// Handle minimal stats format that only has assetsByChunkName but no assets array
30-
if ((bundleStats.assets == null || bundleStats.assets.length === 0) && bundleStats.assetsByChunkName) {
29+
// Handle minimal stats format that only has assetsByChunkName but no assets array
30+
if ((bundleStats.assets == null || bundleStats.assets.length === 0) && bundleStats.assetsByChunkName) {
3131
// Convert assetsByChunkName to assets array for minimal stats
32-
bundleStats.assets = [];
33-
Object.entries(bundleStats.assetsByChunkName).forEach(([chunkName, assetNames]) => {
34-
assetNames.forEach(assetName => {
35-
bundleStats.assets.push({
36-
name: assetName,
37-
chunks: [chunkName],
38-
size: 0 // Default size for minimal stats
32+
bundleStats.assets = [];
33+
Object.entries(bundleStats.assetsByChunkName).forEach(([chunkName, assetNames]) => {
34+
assetNames.forEach(assetName => {
35+
bundleStats.assets.push({
36+
name: assetName,
37+
chunks: [chunkName],
38+
size: 0 // Default size for minimal stats
39+
});
3940
});
4041
});
41-
});
42-
}
42+
}
4343

44-
// Sometimes all the information is located in `children` array (e.g. problem in #10)
45-
if ((bundleStats.assets == null || bundleStats.assets.length === 0) && bundleStats.children && bundleStats.children.length > 0) {
44+
// Sometimes all the information is located in `children` array (e.g. problem in #10)
45+
if ((bundleStats.assets == null || bundleStats.assets.length === 0) && bundleStats.children && bundleStats.children.length > 0) {
4646
const {children} = bundleStats;
4747
bundleStats = bundleStats.children[0];
4848
// Sometimes if there are additional child chunks produced add them as child assets,
@@ -205,16 +205,16 @@ function getBundleModules(bundleStats) {
205205
if (!bundleStats) {
206206
return [];
207207
}
208-
208+
209209
const seenIds = new Set();
210-
210+
211211
// Safely handle chunks and modules that might be undefined
212-
const chunksModules = bundleStats.chunks ?
213-
bundleStats.chunks.map(chunk => chunk.modules || []) :
212+
const chunksModules = bundleStats.chunks ?
213+
bundleStats.chunks.map(chunk => chunk.modules || []) :
214214
[];
215-
215+
216216
const statsModules = bundleStats.modules || [];
217-
217+
218218
return flatten(chunksModules.concat(statsModules).filter(Boolean)).filter(mod => {
219219
// Filtering out Webpack's runtime modules as they don't have ids and can't be parsed (introduced in Webpack 5)
220220
if (isRuntimeModule(mod)) {

test/analyzer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ describe('Analyzer', function () {
9999
await expectValidReport({
100100
bundleLabel: 'viewer.js',
101101
statSize: 0
102+
});
102103
});
103-
});
104104

105105
it.skip("should not filter out modules that we couldn't find during parsing", async function () {
106106
generateReportFrom('with-missing-parsed-module/stats.json');

0 commit comments

Comments
 (0)