Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
info-arnav committed Apr 13, 2024
2 parents 737a267 + 36d7bc7 commit 87b033e
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,14 @@ _Note: Gaps between patch versions are faulty, broken or test releases._

## UNRELEASED

## 4.10.2

* **Bug Fix**
* fix `.cjs` files not being handled ([#512](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/512) by [@Rush](https://github.com/Rush))

* **Internal**
* Remove `is-plain-object` ([#627](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/627) by [@SukkaW](https://github.com/SukkaW))

## 4.10.1

* **Bug Fix**
Expand Down
7 changes: 1 addition & 6 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "webpack-bundle-analyzer",
"version": "4.10.1",
"version": "4.10.2",
"description": "Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap",
"author": "Yury Grunin <grunin.ya@ya.ru>",
"license": "MIT",
Expand Down Expand Up @@ -41,7 +41,6 @@
"escape-string-regexp": "^4.0.0",
"gzip-size": "^6.0.0",
"html-escaper": "^2.0.2",
"is-plain-object": "^5.0.0",
"opener": "^1.5.2",
"picocolors": "^1.0.0",
"sirv": "^2.0.3",
Expand Down
4 changes: 2 additions & 2 deletions src/analyzer.js
Expand Up @@ -10,7 +10,7 @@ const {parseBundle} = require('./parseUtils');
const {createAssetsFilter} = require('./utils');

const FILENAME_QUERY_REGEXP = /\?.*$/u;
const FILENAME_EXTENSIONS = /\.(js|mjs)$/iu;
const FILENAME_EXTENSIONS = /\.(js|mjs|cjs)$/iu;

module.exports = {
getViewerData,
Expand Down Expand Up @@ -50,7 +50,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
});
}

// Picking only `*.js or *.mjs` assets from bundle that has non-empty `chunks` array
// Picking only `*.js, *.cjs or *.mjs` assets from bundle that has non-empty `chunks` array
bundleStats.assets = bundleStats.assets.filter(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') {
Expand Down
12 changes: 8 additions & 4 deletions src/viewer.js
Expand Up @@ -4,7 +4,6 @@ const http = require('http');

const WebSocket = require('ws');
const sirv = require('sirv');
const {isPlainObject} = require('is-plain-object');
const {bold} = require('picocolors');

const Logger = require('./Logger');
Expand Down Expand Up @@ -190,7 +189,12 @@ function getChartData(analyzerOpts, ...args) {
chartData = null;
}

if (isPlainObject(chartData) && Object.keys(chartData).length === 0) {
// chartData can either be an array (bundleInfo[]) or null. It can't be an plain object anyway
if (
// analyzer.getViewerData() doesn't failed in the previous step
chartData
&& !Array.isArray(chartData)
) {
logger.error("Could't find any javascript bundles in provided stats file");
chartData = null;
}
Expand All @@ -199,8 +203,8 @@ function getChartData(analyzerOpts, ...args) {
}

function getEntrypoints(bundleStats) {
if (bundleStats === null || bundleStats === undefined) {
if (bundleStats === null || bundleStats === undefined || !bundleStats.entrypoints) {
return [];
}
return Object.values(bundleStats.entrypoints || {}).map(entrypoint => entrypoint.name);
return Object.values(bundleStats.entrypoints).map(entrypoint => entrypoint.name);
}
5 changes: 5 additions & 0 deletions test/analyzer.js
Expand Up @@ -158,6 +158,11 @@ describe('Analyzer', function () {
await expectValidReport({bundleLabel: 'bundle.mjs'});
});

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

it('should properly parse extremely optimized bundle from webpack 5', async function () {
generateReportFrom('extremely-optimized-webpack-5-bundle/stats.json');
const chartData = await getChartData();
Expand Down

0 comments on commit 87b033e

Please sign in to comment.