webpack-bundle-analyzer 4.10.2 → 5.0.1

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.
@@ -4,45 +4,36 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _Node = _interopRequireDefault(require("./Node"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
9
  class BaseFolder extends _Node.default {
13
10
  constructor(name, parent) {
14
11
  super(name, parent);
15
12
  this.children = Object.create(null);
16
13
  }
17
-
18
14
  get src() {
19
15
  if (!Object.prototype.hasOwnProperty.call(this, '_src')) {
20
16
  this._src = this.walk((node, src) => src += node.src || '', '', false);
21
17
  }
22
-
23
18
  return this._src;
24
19
  }
25
-
26
20
  get size() {
27
21
  if (!Object.prototype.hasOwnProperty.call(this, '_size')) {
28
22
  this._size = this.walk((node, size) => size + node.size, 0, false);
29
23
  }
30
-
31
24
  return this._size;
32
25
  }
33
-
34
26
  getChild(name) {
35
27
  return this.children[name];
36
28
  }
37
-
38
29
  addChildModule(module) {
39
30
  const {
40
31
  name
41
32
  } = module;
42
- const currentChild = this.children[name]; // For some reason we already have this node in children and it's a folder.
33
+ const currentChild = this.children[name];
43
34
 
35
+ // For some reason we already have this node in children and it's a folder.
44
36
  if (currentChild && currentChild instanceof BaseFolder) return;
45
-
46
37
  if (currentChild) {
47
38
  // We already have this node in children and it's a module.
48
39
  // Merging it's data.
@@ -52,11 +43,9 @@ class BaseFolder extends _Node.default {
52
43
  module.parent = this;
53
44
  this.children[name] = module;
54
45
  }
55
-
56
46
  delete this._size;
57
47
  delete this._src;
58
48
  }
59
-
60
49
  addChildFolder(folder) {
61
50
  folder.parent = this;
62
51
  this.children[folder.name] = folder;
@@ -64,7 +53,6 @@ class BaseFolder extends _Node.default {
64
53
  delete this._src;
65
54
  return folder;
66
55
  }
67
-
68
56
  walk(walker, state = {}, deep = true) {
69
57
  let stopped = false;
70
58
  Object.values(this.children).forEach(child => {
@@ -73,25 +61,20 @@ class BaseFolder extends _Node.default {
73
61
  } else {
74
62
  state = walker(child, state, stop);
75
63
  }
76
-
77
64
  if (stopped) return false;
78
65
  });
79
66
  return state;
80
-
81
67
  function stop(finalState) {
82
68
  stopped = true;
83
69
  return finalState;
84
70
  }
85
71
  }
86
-
87
72
  mergeNestedFolders() {
88
73
  if (!this.isRoot) {
89
74
  let childNames;
90
-
91
75
  while ((childNames = Object.keys(this.children)).length === 1) {
92
76
  const childName = childNames[0];
93
77
  const onlyChild = this.children[childName];
94
-
95
78
  if (onlyChild instanceof this.constructor) {
96
79
  this.name += `/${onlyChild.name}`;
97
80
  this.children = onlyChild.children;
@@ -100,16 +83,13 @@ class BaseFolder extends _Node.default {
100
83
  }
101
84
  }
102
85
  }
103
-
104
86
  this.walk(child => {
105
87
  child.parent = this;
106
-
107
88
  if (child.mergeNestedFolders) {
108
89
  child.mergeNestedFolders();
109
90
  }
110
91
  }, null, false);
111
92
  }
112
-
113
93
  toChartData() {
114
94
  return {
115
95
  label: this.name,
@@ -118,8 +98,6 @@ class BaseFolder extends _Node.default {
118
98
  groups: Object.values(this.children).map(child => child.toChartData())
119
99
  };
120
100
  }
121
-
122
101
  }
123
-
124
102
  exports.default = BaseFolder;
125
103
  ;
@@ -4,87 +4,66 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _Module = _interopRequireDefault(require("./Module"));
9
-
10
8
  var _ContentModule = _interopRequireDefault(require("./ContentModule"));
11
-
12
9
  var _ContentFolder = _interopRequireDefault(require("./ContentFolder"));
13
-
14
10
  var _utils = require("./utils");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
12
  class ConcatenatedModule extends _Module.default {
19
- constructor(name, data, parent) {
20
- super(name, data, parent);
13
+ constructor(name, data, parent, opts) {
14
+ super(name, data, parent, opts);
21
15
  this.name += ' (concatenated)';
22
16
  this.children = Object.create(null);
23
17
  this.fillContentModules();
24
18
  }
25
-
26
19
  get parsedSize() {
27
- var _this$getParsedSize;
28
-
29
- return (_this$getParsedSize = this.getParsedSize()) !== null && _this$getParsedSize !== void 0 ? _this$getParsedSize : this.getEstimatedSize('parsedSize');
20
+ return this.getParsedSize() ?? this.getEstimatedSize('parsedSize');
30
21
  }
31
-
32
22
  get gzipSize() {
33
- var _this$getGzipSize;
34
-
35
- return (_this$getGzipSize = this.getGzipSize()) !== null && _this$getGzipSize !== void 0 ? _this$getGzipSize : this.getEstimatedSize('gzipSize');
23
+ return this.getGzipSize() ?? this.getEstimatedSize('gzipSize');
24
+ }
25
+ get brotliSize() {
26
+ return this.getBrotliSize() ?? this.getEstimatedSize('brotliSize');
36
27
  }
37
-
38
28
  getEstimatedSize(sizeType) {
39
29
  const parentModuleSize = this.parent[sizeType];
40
-
41
30
  if (parentModuleSize !== undefined) {
42
31
  return Math.floor(this.size / this.parent.size * parentModuleSize);
43
32
  }
44
33
  }
45
-
46
34
  fillContentModules() {
47
35
  this.data.modules.forEach(moduleData => this.addContentModule(moduleData));
48
36
  }
49
-
50
37
  addContentModule(moduleData) {
51
38
  const pathParts = (0, _utils.getModulePathParts)(moduleData);
52
-
53
39
  if (!pathParts) {
54
40
  return;
55
41
  }
56
-
57
42
  const [folders, fileName] = [pathParts.slice(0, -1), pathParts[pathParts.length - 1]];
58
43
  let currentFolder = this;
59
44
  folders.forEach(folderName => {
60
45
  let childFolder = currentFolder.getChild(folderName);
61
-
62
46
  if (!childFolder) {
63
47
  childFolder = currentFolder.addChildFolder(new _ContentFolder.default(folderName, this));
64
48
  }
65
-
66
49
  currentFolder = childFolder;
67
50
  });
68
51
  const ModuleConstructor = moduleData.modules ? ConcatenatedModule : _ContentModule.default;
69
- const module = new ModuleConstructor(fileName, moduleData, this);
52
+ const module = new ModuleConstructor(fileName, moduleData, this, this.opts);
70
53
  currentFolder.addChildModule(module);
71
54
  }
72
-
73
55
  getChild(name) {
74
56
  return this.children[name];
75
57
  }
76
-
77
58
  addChildModule(module) {
78
59
  module.parent = this;
79
60
  this.children[module.name] = module;
80
61
  }
81
-
82
62
  addChildFolder(folder) {
83
63
  folder.parent = this;
84
64
  this.children[folder.name] = folder;
85
65
  return folder;
86
66
  }
87
-
88
67
  mergeNestedFolders() {
89
68
  Object.values(this.children).forEach(child => {
90
69
  if (child.mergeNestedFolders) {
@@ -92,15 +71,13 @@ class ConcatenatedModule extends _Module.default {
92
71
  }
93
72
  });
94
73
  }
95
-
96
74
  toChartData() {
97
- return { ...super.toChartData(),
75
+ return {
76
+ ...super.toChartData(),
98
77
  concatenated: true,
99
78
  groups: Object.values(this.children).map(child => child.toChartData())
100
79
  };
101
80
  }
102
-
103
81
  }
104
-
105
82
  exports.default = ConcatenatedModule;
106
83
  ;
@@ -4,42 +4,37 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _BaseFolder = _interopRequireDefault(require("./BaseFolder"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
9
  class ContentFolder extends _BaseFolder.default {
13
10
  constructor(name, ownerModule, parent) {
14
11
  super(name, parent);
15
12
  this.ownerModule = ownerModule;
16
13
  }
17
-
18
14
  get parsedSize() {
19
15
  return this.getSize('parsedSize');
20
16
  }
21
-
22
17
  get gzipSize() {
23
18
  return this.getSize('gzipSize');
24
19
  }
25
-
20
+ get brotliSize() {
21
+ return this.getSize('brotliSize');
22
+ }
26
23
  getSize(sizeType) {
27
24
  const ownerModuleSize = this.ownerModule[sizeType];
28
-
29
25
  if (ownerModuleSize !== undefined) {
30
26
  return Math.floor(this.size / this.ownerModule.size * ownerModuleSize);
31
27
  }
32
28
  }
33
-
34
29
  toChartData() {
35
- return { ...super.toChartData(),
30
+ return {
31
+ ...super.toChartData(),
36
32
  parsedSize: this.parsedSize,
37
33
  gzipSize: this.gzipSize,
34
+ brotliSize: this.brotliSize,
38
35
  inaccurateSizes: true
39
36
  };
40
37
  }
41
-
42
38
  }
43
-
44
39
  exports.default = ContentFolder;
45
40
  ;
@@ -4,40 +4,34 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _Module = _interopRequireDefault(require("./Module"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
9
  class ContentModule extends _Module.default {
13
10
  constructor(name, data, ownerModule, parent) {
14
11
  super(name, data, parent);
15
12
  this.ownerModule = ownerModule;
16
13
  }
17
-
18
14
  get parsedSize() {
19
15
  return this.getSize('parsedSize');
20
16
  }
21
-
22
17
  get gzipSize() {
23
18
  return this.getSize('gzipSize');
24
19
  }
25
-
20
+ get brotliSize() {
21
+ return this.getSize('brotliSize');
22
+ }
26
23
  getSize(sizeType) {
27
24
  const ownerModuleSize = this.ownerModule[sizeType];
28
-
29
25
  if (ownerModuleSize !== undefined) {
30
26
  return Math.floor(this.size / this.ownerModule.size * ownerModuleSize);
31
27
  }
32
28
  }
33
-
34
29
  toChartData() {
35
- return { ...super.toChartData(),
30
+ return {
31
+ ...super.toChartData(),
36
32
  inaccurateSizes: true
37
33
  };
38
34
  }
39
-
40
35
  }
41
-
42
36
  exports.default = ContentModule;
43
37
  ;
@@ -4,68 +4,66 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _gzipSize = _interopRequireDefault(require("gzip-size"));
9
-
10
7
  var _Module = _interopRequireDefault(require("./Module"));
11
-
12
8
  var _BaseFolder = _interopRequireDefault(require("./BaseFolder"));
13
-
14
9
  var _ConcatenatedModule = _interopRequireDefault(require("./ConcatenatedModule"));
15
-
16
10
  var _utils = require("./utils");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
11
+ var _sizeUtils = require("../sizeUtils");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
13
  class Folder extends _BaseFolder.default {
14
+ constructor(name, opts) {
15
+ super(name);
16
+ this.opts = opts;
17
+ }
21
18
  get parsedSize() {
22
19
  return this.src ? this.src.length : 0;
23
20
  }
24
-
25
21
  get gzipSize() {
26
- if (!Object.prototype.hasOwnProperty.call(this, '_gzipSize')) {
27
- this._gzipSize = this.src ? _gzipSize.default.sync(this.src) : 0;
22
+ return this.opts.compressionAlgorithm === 'gzip' ? this.getCompressedSize('gzip') : undefined;
23
+ }
24
+ get brotliSize() {
25
+ return this.opts.compressionAlgorithm === 'brotli' ? this.getCompressedSize('brotli') : undefined;
26
+ }
27
+ getCompressedSize(compressionAlgorithm) {
28
+ const key = `_${compressionAlgorithm}Size`;
29
+ if (!Object.prototype.hasOwnProperty.call(this, key)) {
30
+ this[key] = this.src ? (0, _sizeUtils.getCompressedSize)(compressionAlgorithm, this.src) : 0;
28
31
  }
29
-
30
- return this._gzipSize;
32
+ return this[key];
31
33
  }
32
-
33
34
  addModule(moduleData) {
34
35
  const pathParts = (0, _utils.getModulePathParts)(moduleData);
35
-
36
36
  if (!pathParts) {
37
37
  return;
38
38
  }
39
-
40
39
  const [folders, fileName] = [pathParts.slice(0, -1), pathParts[pathParts.length - 1]];
41
40
  let currentFolder = this;
42
41
  folders.forEach(folderName => {
43
42
  let childNode = currentFolder.getChild(folderName);
44
-
45
- if ( // Folder is not created yet
46
- !childNode || // In some situations (invalid usage of dynamic `require()`) webpack generates a module with empty require
43
+ if (
44
+ // Folder is not created yet
45
+ !childNode ||
46
+ // In some situations (invalid usage of dynamic `require()`) webpack generates a module with empty require
47
47
  // context, but it's moduleId points to a directory in filesystem.
48
48
  // In this case we replace this `File` node with `Folder`.
49
49
  // See `test/stats/with-invalid-dynamic-require.json` as an example.
50
50
  !(childNode instanceof Folder)) {
51
- childNode = currentFolder.addChildFolder(new Folder(folderName));
51
+ childNode = currentFolder.addChildFolder(new Folder(folderName, this.opts));
52
52
  }
53
-
54
53
  currentFolder = childNode;
55
54
  });
56
55
  const ModuleConstructor = moduleData.modules ? _ConcatenatedModule.default : _Module.default;
57
- const module = new ModuleConstructor(fileName, moduleData, this);
56
+ const module = new ModuleConstructor(fileName, moduleData, this, this.opts);
58
57
  currentFolder.addChildModule(module);
59
58
  }
60
-
61
59
  toChartData() {
62
- return { ...super.toChartData(),
60
+ return {
61
+ ...super.toChartData(),
63
62
  parsedSize: this.parsedSize,
64
- gzipSize: this.gzipSize
63
+ gzipSize: this.gzipSize,
64
+ brotliSize: this.brotliSize
65
65
  };
66
66
  }
67
-
68
67
  }
69
-
70
68
  exports.default = Folder;
71
69
  ;
@@ -4,66 +4,62 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _gzipSize = _interopRequireDefault(require("gzip-size"));
9
-
10
7
  var _Node = _interopRequireDefault(require("./Node"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
8
+ var _sizeUtils = require("../sizeUtils");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
10
  class Module extends _Node.default {
15
- constructor(name, data, parent) {
11
+ constructor(name, data, parent, opts) {
16
12
  super(name, parent);
17
13
  this.data = data;
14
+ this.opts = opts;
18
15
  }
19
-
20
16
  get src() {
21
17
  return this.data.parsedSrc;
22
18
  }
23
-
24
19
  set src(value) {
25
20
  this.data.parsedSrc = value;
26
21
  delete this._gzipSize;
22
+ delete this._brotliSize;
27
23
  }
28
-
29
24
  get size() {
30
25
  return this.data.size;
31
26
  }
32
-
33
27
  set size(value) {
34
28
  this.data.size = value;
35
29
  }
36
-
37
30
  get parsedSize() {
38
31
  return this.getParsedSize();
39
32
  }
40
-
41
33
  get gzipSize() {
42
34
  return this.getGzipSize();
43
35
  }
44
-
36
+ get brotliSize() {
37
+ return this.getBrotliSize();
38
+ }
45
39
  getParsedSize() {
46
40
  return this.src ? this.src.length : undefined;
47
41
  }
48
-
49
42
  getGzipSize() {
50
- if (!('_gzipSize' in this)) {
51
- this._gzipSize = this.src ? _gzipSize.default.sync(this.src) : undefined;
43
+ return this.opts.compressionAlgorithm === 'gzip' ? this.getCompressedSize('gzip') : undefined;
44
+ }
45
+ getBrotliSize() {
46
+ return this.opts.compressionAlgorithm === 'brotli' ? this.getCompressedSize('brotli') : undefined;
47
+ }
48
+ getCompressedSize(compressionAlgorithm) {
49
+ const key = `_${compressionAlgorithm}Size`;
50
+ if (!(key in this)) {
51
+ this[key] = this.src ? (0, _sizeUtils.getCompressedSize)(compressionAlgorithm, this.src) : undefined;
52
52
  }
53
-
54
- return this._gzipSize;
53
+ return this[key];
55
54
  }
56
-
57
55
  mergeData(data) {
58
56
  if (data.size) {
59
57
  this.size += data.size;
60
58
  }
61
-
62
59
  if (data.parsedSrc) {
63
60
  this.src = (this.src || '') + data.parsedSrc;
64
61
  }
65
62
  }
66
-
67
63
  toChartData() {
68
64
  return {
69
65
  id: this.data.id,
@@ -71,11 +67,10 @@ class Module extends _Node.default {
71
67
  path: this.path,
72
68
  statSize: this.size,
73
69
  parsedSize: this.parsedSize,
74
- gzipSize: this.gzipSize
70
+ gzipSize: this.gzipSize,
71
+ brotliSize: this.brotliSize
75
72
  };
76
73
  }
77
-
78
74
  }
79
-
80
75
  exports.default = Module;
81
76
  ;
package/lib/tree/Node.js CHANGED
@@ -4,30 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  class Node {
9
8
  constructor(name, parent) {
10
9
  this.name = name;
11
10
  this.parent = parent;
12
11
  }
13
-
14
12
  get path() {
15
13
  const path = [];
16
14
  let node = this;
17
-
18
15
  while (node) {
19
16
  path.push(node.name);
20
17
  node = node.parent;
21
18
  }
22
-
23
19
  return path.reverse().join('/');
24
20
  }
25
-
26
21
  get isRoot() {
27
22
  return !this.parent;
28
23
  }
29
-
30
24
  }
31
-
32
25
  exports.default = Node;
33
26
  ;
package/lib/tree/utils.js CHANGED
@@ -5,17 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getModulePathParts = getModulePathParts;
7
7
  const MULTI_MODULE_REGEXP = /^multi /u;
8
-
9
8
  function getModulePathParts(moduleData) {
10
9
  if (MULTI_MODULE_REGEXP.test(moduleData.identifier)) {
11
10
  return [moduleData.identifier];
12
11
  }
13
-
14
- const loaders = moduleData.name.split('!'); // Removing loaders from module path: they're joined by `!` and the last part is a raw module path
15
-
16
- const parsedPath = loaders[loaders.length - 1] // Splitting module path into parts
17
- .split('/') // Removing first `.`
18
- .slice(1) // Replacing `~` with `node_modules`
12
+ const loaders = moduleData.name.split('!');
13
+ // Removing loaders from module path: they're joined by `!` and the last part is a raw module path
14
+ const parsedPath = loaders[loaders.length - 1]
15
+ // Splitting module path into parts
16
+ .split('/')
17
+ // Removing first `.`
18
+ .slice(1)
19
+ // Replacing `~` with `node_modules`
19
20
  .map(part => part === '~' ? 'node_modules' : part);
20
21
  return parsedPath.length ? parsedPath : null;
21
22
  }
package/lib/utils.js CHANGED
@@ -4,43 +4,35 @@ const {
4
4
  inspect,
5
5
  types
6
6
  } = require('util');
7
-
8
7
  const opener = require('opener');
9
-
10
8
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
11
9
  exports.createAssetsFilter = createAssetsFilter;
12
-
13
10
  function createAssetsFilter(excludePatterns) {
14
11
  const excludeFunctions = (Array.isArray(excludePatterns) ? excludePatterns : [excludePatterns]).filter(Boolean).map(pattern => {
15
12
  if (typeof pattern === 'string') {
16
13
  pattern = new RegExp(pattern, 'u');
17
14
  }
18
-
19
15
  if (types.isRegExp(pattern)) {
20
16
  return asset => pattern.test(asset);
21
17
  }
22
-
23
18
  if (typeof pattern !== 'function') {
24
19
  throw new TypeError(`Pattern should be either string, RegExp or a function, but "${inspect(pattern, {
25
20
  depth: 0
26
21
  })}" got.`);
27
22
  }
28
-
29
23
  return pattern;
30
24
  });
31
-
32
25
  if (excludeFunctions.length) {
33
26
  return asset => excludeFunctions.every(fn => fn(asset) !== true);
34
27
  } else {
35
28
  return () => true;
36
29
  }
37
30
  }
31
+
38
32
  /**
39
33
  * @desc get string of current time
40
34
  * format: dd/MMM HH:mm
41
35
  * */
42
-
43
-
44
36
  exports.defaultTitle = function () {
45
37
  const time = new Date();
46
38
  const year = time.getFullYear();
@@ -51,7 +43,6 @@ exports.defaultTitle = function () {
51
43
  const currentTime = `${day} ${month} ${year} at ${hour}:${minute}`;
52
44
  return `${process.env.npm_package_name || 'Webpack Bundle Analyzer'} [${currentTime}]`;
53
45
  };
54
-
55
46
  exports.defaultAnalyzerUrl = function (options) {
56
47
  const {
57
48
  listenHost,
@@ -59,11 +50,10 @@ exports.defaultAnalyzerUrl = function (options) {
59
50
  } = options;
60
51
  return `http://${listenHost}:${boundAddress.port}`;
61
52
  };
53
+
62
54
  /**
63
55
  * Calls opener on a URI, but silently try / catches it.
64
56
  */
65
-
66
-
67
57
  exports.open = function (uri, logger) {
68
58
  try {
69
59
  opener(uri);