webpack-bundle-analyzer 4.10.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/viewer.js CHANGED
@@ -1,37 +1,22 @@
1
1
  "use strict";
2
2
 
3
3
  const path = require('path');
4
-
5
4
  const fs = require('fs');
6
-
7
5
  const http = require('http');
8
-
9
6
  const WebSocket = require('ws');
10
-
11
7
  const sirv = require('sirv');
12
-
13
- const {
14
- isPlainObject
15
- } = require('is-plain-object');
16
-
17
8
  const {
18
9
  bold
19
10
  } = require('picocolors');
20
-
21
11
  const Logger = require('./Logger');
22
-
23
12
  const analyzer = require('./analyzer');
24
-
25
13
  const {
26
14
  open
27
15
  } = require('./utils');
28
-
29
16
  const {
30
17
  renderViewer
31
18
  } = require('./template');
32
-
33
19
  const projectRoot = path.resolve(__dirname, '..');
34
-
35
20
  function resolveTitle(reportTitle) {
36
21
  if (typeof reportTitle === 'function') {
37
22
  return reportTitle();
@@ -39,7 +24,10 @@ function resolveTitle(reportTitle) {
39
24
  return reportTitle;
40
25
  }
41
26
  }
42
-
27
+ function resolveDefaultSizes(defaultSizes, compressionAlgorithm) {
28
+ if (['gzip', 'brotli'].includes(defaultSizes)) return compressionAlgorithm;
29
+ return defaultSizes;
30
+ }
43
31
  module.exports = {
44
32
  startServer,
45
33
  generateReport,
@@ -48,7 +36,6 @@ module.exports = {
48
36
  // deprecated
49
37
  start: startServer
50
38
  };
51
-
52
39
  async function startServer(bundleStats, opts) {
53
40
  const {
54
41
  port = 8888,
@@ -57,13 +44,15 @@ async function startServer(bundleStats, opts) {
57
44
  bundleDir = null,
58
45
  logger = new Logger(),
59
46
  defaultSizes = 'parsed',
47
+ compressionAlgorithm,
60
48
  excludeAssets = null,
61
49
  reportTitle,
62
50
  analyzerUrl
63
51
  } = opts || {};
64
52
  const analyzerOpts = {
65
53
  logger,
66
- excludeAssets
54
+ excludeAssets,
55
+ compressionAlgorithm
67
56
  };
68
57
  let chartData = getChartData(analyzerOpts, bundleStats, bundleDir);
69
58
  const entrypoints = getEntrypoints(bundleStats);
@@ -79,7 +68,8 @@ async function startServer(bundleStats, opts) {
79
68
  title: resolveTitle(reportTitle),
80
69
  chartData,
81
70
  entrypoints,
82
- defaultSizes,
71
+ defaultSizes: resolveDefaultSizes(defaultSizes, compressionAlgorithm),
72
+ compressionAlgorithm,
83
73
  enableWebSocket: true
84
74
  });
85
75
  res.writeHead(200, {
@@ -99,7 +89,6 @@ async function startServer(bundleStats, opts) {
99
89
  boundAddress: server.address()
100
90
  });
101
91
  logger.info(`${bold('Webpack Bundle Analyzer')} is started at ${bold(url)}\n` + `Use ${bold('Ctrl+C')} to close it`);
102
-
103
92
  if (openBrowser) {
104
93
  open(url, logger);
105
94
  }
@@ -120,7 +109,6 @@ async function startServer(bundleStats, opts) {
120
109
  http: server,
121
110
  updateChartData
122
111
  };
123
-
124
112
  function updateChartData(bundleStats) {
125
113
  const newChartData = getChartData(analyzerOpts, bundleStats, bundleDir);
126
114
  if (!newChartData) return;
@@ -135,7 +123,6 @@ async function startServer(bundleStats, opts) {
135
123
  });
136
124
  }
137
125
  }
138
-
139
126
  async function generateReport(bundleStats, opts) {
140
127
  const {
141
128
  openBrowser = true,
@@ -144,11 +131,13 @@ async function generateReport(bundleStats, opts) {
144
131
  bundleDir = null,
145
132
  logger = new Logger(),
146
133
  defaultSizes = 'parsed',
134
+ compressionAlgorithm,
147
135
  excludeAssets = null
148
136
  } = opts || {};
149
137
  const chartData = getChartData({
150
138
  logger,
151
- excludeAssets
139
+ excludeAssets,
140
+ compressionAlgorithm
152
141
  }, bundleStats, bundleDir);
153
142
  const entrypoints = getEntrypoints(bundleStats);
154
143
  if (!chartData) return;
@@ -157,7 +146,8 @@ async function generateReport(bundleStats, opts) {
157
146
  title: resolveTitle(reportTitle),
158
147
  chartData,
159
148
  entrypoints,
160
- defaultSizes,
149
+ defaultSizes: resolveDefaultSizes(defaultSizes, compressionAlgorithm),
150
+ compressionAlgorithm,
161
151
  enableWebSocket: false
162
152
  });
163
153
  const reportFilepath = path.resolve(bundleDir || process.cwd(), reportFilename);
@@ -166,22 +156,22 @@ async function generateReport(bundleStats, opts) {
166
156
  });
167
157
  fs.writeFileSync(reportFilepath, reportHtml);
168
158
  logger.info(`${bold('Webpack Bundle Analyzer')} saved report to ${bold(reportFilepath)}`);
169
-
170
159
  if (openBrowser) {
171
160
  open(`file://${reportFilepath}`, logger);
172
161
  }
173
162
  }
174
-
175
163
  async function generateJSONReport(bundleStats, opts) {
176
164
  const {
177
165
  reportFilename,
178
166
  bundleDir = null,
179
167
  logger = new Logger(),
180
- excludeAssets = null
168
+ excludeAssets = null,
169
+ compressionAlgorithm
181
170
  } = opts || {};
182
171
  const chartData = getChartData({
183
172
  logger,
184
- excludeAssets
173
+ excludeAssets,
174
+ compressionAlgorithm
185
175
  }, bundleStats, bundleDir);
186
176
  if (!chartData) return;
187
177
  await fs.promises.mkdir(path.dirname(reportFilename), {
@@ -190,33 +180,31 @@ async function generateJSONReport(bundleStats, opts) {
190
180
  await fs.promises.writeFile(reportFilename, JSON.stringify(chartData));
191
181
  logger.info(`${bold('Webpack Bundle Analyzer')} saved JSON report to ${bold(reportFilename)}`);
192
182
  }
193
-
194
183
  function getChartData(analyzerOpts, ...args) {
195
184
  let chartData;
196
185
  const {
197
186
  logger
198
187
  } = analyzerOpts;
199
-
200
188
  try {
201
189
  chartData = analyzer.getViewerData(...args, analyzerOpts);
202
190
  } catch (err) {
203
- logger.error(`Could't analyze webpack bundle:\n${err}`);
191
+ logger.error(`Couldn't analyze webpack bundle:\n${err}`);
204
192
  logger.debug(err.stack);
205
193
  chartData = null;
206
194
  }
207
195
 
208
- if (isPlainObject(chartData) && Object.keys(chartData).length === 0) {
209
- logger.error("Could't find any javascript bundles in provided stats file");
196
+ // chartData can either be an array (bundleInfo[]) or null. It can't be an plain object anyway
197
+ if (
198
+ // analyzer.getViewerData() doesn't failed in the previous step
199
+ chartData && !Array.isArray(chartData)) {
200
+ logger.error("Couldn't find any javascript bundles in provided stats file");
210
201
  chartData = null;
211
202
  }
212
-
213
203
  return chartData;
214
204
  }
215
-
216
205
  function getEntrypoints(bundleStats) {
217
- if (bundleStats === null || bundleStats === undefined) {
206
+ if (bundleStats === null || bundleStats === undefined || !bundleStats.entrypoints) {
218
207
  return [];
219
208
  }
220
-
221
- return Object.values(bundleStats.entrypoints || {}).map(entrypoint => entrypoint.name);
209
+ return Object.values(bundleStats.entrypoints).map(entrypoint => entrypoint.name);
222
210
  }
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "webpack-bundle-analyzer",
3
- "version": "4.10.1",
3
+ "version": "5.0.0",
4
4
  "description": "Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap",
5
5
  "author": "Yury Grunin <grunin.ya@ya.ru>",
6
6
  "license": "MIT",
7
- "homepage": "https://github.com/webpack-contrib/webpack-bundle-analyzer",
8
- "changelog": "https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/master/CHANGELOG.md",
7
+ "homepage": "https://github.com/webpack/webpack-bundle-analyzer",
8
+ "changelog": "https://github.com/webpack/webpack-bundle-analyzer/blob/main/CHANGELOG.md",
9
9
  "bugs": {
10
- "url": "https://github.com/webpack-contrib/webpack-bundle-analyzer/issues"
10
+ "url": "https://github.com/webpack/webpack-bundle-analyzer/issues"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git+https://github.com/webpack-contrib/webpack-bundle-analyzer.git"
14
+ "url": "git+https://github.com/webpack/webpack-bundle-analyzer.git"
15
15
  },
16
16
  "main": "lib/index.js",
17
17
  "bin": "lib/bin/analyzer.js",
18
18
  "engines": {
19
- "node": ">= 10.13.0"
19
+ "node": ">= 20.9.0"
20
20
  },
21
21
  "packageManager": "npm@6.14.8",
22
22
  "scripts": {
@@ -25,8 +25,8 @@
25
25
  "npm-publish": "npm run lint && npm run build && npm test && npm publish",
26
26
  "lint": "eslint --ext js,jsx .",
27
27
  "install-test-webpack-versions": "./bin/install-test-webpack-versions.sh",
28
- "test": "npm run install-test-webpack-versions && jest --runInBand",
29
- "test-dev": "npm run install-test-webpack-versions && jest --watch --runInBand"
28
+ "test": "npm run install-test-webpack-versions && NODE_OPTIONS=--openssl-legacy-provider jest --runInBand",
29
+ "test-dev": "npm run install-test-webpack-versions && NODE_OPTIONS=--openssl-legacy-provider jest --watch --runInBand"
30
30
  },
31
31
  "files": [
32
32
  "public",
@@ -39,26 +39,23 @@
39
39
  "commander": "^7.2.0",
40
40
  "debounce": "^1.2.1",
41
41
  "escape-string-regexp": "^4.0.0",
42
- "gzip-size": "^6.0.0",
43
42
  "html-escaper": "^2.0.2",
44
- "is-plain-object": "^5.0.0",
45
43
  "opener": "^1.5.2",
46
44
  "picocolors": "^1.0.0",
47
45
  "sirv": "^2.0.3",
48
46
  "ws": "^7.3.1"
49
47
  },
50
48
  "devDependencies": {
51
- "@babel/core": "7.14.3",
52
- "@babel/plugin-proposal-class-properties": "7.13.0",
53
- "@babel/plugin-proposal-decorators": "7.14.2",
54
- "@babel/plugin-transform-runtime": "7.14.3",
55
- "@babel/preset-env": "7.14.2",
56
- "@babel/preset-react": "7.13.13",
57
- "@babel/runtime": "7.14.0",
49
+ "@babel/core": "7.26.9",
50
+ "@babel/plugin-proposal-decorators": "7.25.9",
51
+ "@babel/plugin-transform-runtime": "7.26.9",
52
+ "@babel/preset-env": "7.26.9",
53
+ "@babel/preset-react": "7.26.3",
54
+ "@babel/runtime": "7.26.9",
58
55
  "@carrotsearch/foamtree": "3.5.0",
59
56
  "autoprefixer": "10.2.5",
60
57
  "babel-eslint": "10.1.0",
61
- "babel-loader": "8.2.2",
58
+ "babel-loader": "9.2.1",
62
59
  "babel-plugin-lodash": "3.3.4",
63
60
  "chai": "4.3.4",
64
61
  "chai-subset": "1.6.0",
@@ -75,7 +72,7 @@
75
72
  "globby": "11.0.3",
76
73
  "gulp": "4.0.2",
77
74
  "gulp-babel": "8.0.0",
78
- "jest": "27.2.2",
75
+ "jest": "^30.2.0",
79
76
  "lodash.memoize": "^4.1.2",
80
77
  "lodash.merge": "^4.6.2",
81
78
  "lodash.partial": "^4.2.1",
@@ -85,14 +82,14 @@
85
82
  "postcss-icss-values": "2.0.2",
86
83
  "postcss-loader": "5.3.0",
87
84
  "preact": "10.5.13",
88
- "puppeteer": "10.4.0",
85
+ "puppeteer": "^24.30.0",
89
86
  "stream-combiner2": "1.1.1",
90
87
  "style-loader": "2.0.0",
91
88
  "terser-webpack-plugin": "5.1.2",
92
89
  "url-loader": "4.1.1",
93
- "webpack": "5.76.0",
94
- "webpack-cli": "3.3.12",
95
- "webpack-dev-server": "3.11.3"
90
+ "webpack": "5.98.0",
91
+ "webpack-cli": "6.0.1",
92
+ "webpack-dev-server": "5.2.0"
96
93
  },
97
94
  "keywords": [
98
95
  "webpack",