webpack-bundle-analyzer 4.9.0 → 5.2.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.
@@ -4,47 +4,36 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash"));
9
-
10
7
  var _Node = _interopRequireDefault(require("./Node"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
9
  class BaseFolder extends _Node.default {
15
10
  constructor(name, parent) {
16
11
  super(name, parent);
17
12
  this.children = Object.create(null);
18
13
  }
19
-
20
14
  get src() {
21
- if (!_lodash.default.has(this, '_src')) {
15
+ if (!Object.prototype.hasOwnProperty.call(this, '_src')) {
22
16
  this._src = this.walk((node, src) => src += node.src || '', '', false);
23
17
  }
24
-
25
18
  return this._src;
26
19
  }
27
-
28
20
  get size() {
29
- if (!_lodash.default.has(this, '_size')) {
21
+ if (!Object.prototype.hasOwnProperty.call(this, '_size')) {
30
22
  this._size = this.walk((node, size) => size + node.size, 0, false);
31
23
  }
32
-
33
24
  return this._size;
34
25
  }
35
-
36
26
  getChild(name) {
37
27
  return this.children[name];
38
28
  }
39
-
40
29
  addChildModule(module) {
41
30
  const {
42
31
  name
43
32
  } = module;
44
- 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];
45
34
 
35
+ // For some reason we already have this node in children and it's a folder.
46
36
  if (currentChild && currentChild instanceof BaseFolder) return;
47
-
48
37
  if (currentChild) {
49
38
  // We already have this node in children and it's a module.
50
39
  // Merging it's data.
@@ -54,11 +43,9 @@ class BaseFolder extends _Node.default {
54
43
  module.parent = this;
55
44
  this.children[name] = module;
56
45
  }
57
-
58
46
  delete this._size;
59
47
  delete this._src;
60
48
  }
61
-
62
49
  addChildFolder(folder) {
63
50
  folder.parent = this;
64
51
  this.children[folder.name] = folder;
@@ -66,7 +53,6 @@ class BaseFolder extends _Node.default {
66
53
  delete this._src;
67
54
  return folder;
68
55
  }
69
-
70
56
  walk(walker, state = {}, deep = true) {
71
57
  let stopped = false;
72
58
  Object.values(this.children).forEach(child => {
@@ -75,25 +61,20 @@ class BaseFolder extends _Node.default {
75
61
  } else {
76
62
  state = walker(child, state, stop);
77
63
  }
78
-
79
64
  if (stopped) return false;
80
65
  });
81
66
  return state;
82
-
83
67
  function stop(finalState) {
84
68
  stopped = true;
85
69
  return finalState;
86
70
  }
87
71
  }
88
-
89
72
  mergeNestedFolders() {
90
73
  if (!this.isRoot) {
91
74
  let childNames;
92
-
93
75
  while ((childNames = Object.keys(this.children)).length === 1) {
94
76
  const childName = childNames[0];
95
77
  const onlyChild = this.children[childName];
96
-
97
78
  if (onlyChild instanceof this.constructor) {
98
79
  this.name += `/${onlyChild.name}`;
99
80
  this.children = onlyChild.children;
@@ -102,26 +83,21 @@ class BaseFolder extends _Node.default {
102
83
  }
103
84
  }
104
85
  }
105
-
106
86
  this.walk(child => {
107
87
  child.parent = this;
108
-
109
88
  if (child.mergeNestedFolders) {
110
89
  child.mergeNestedFolders();
111
90
  }
112
91
  }, null, false);
113
92
  }
114
-
115
93
  toChartData() {
116
94
  return {
117
95
  label: this.name,
118
96
  path: this.path,
119
97
  statSize: this.size,
120
- groups: _lodash.default.invokeMap(this.children, 'toChartData')
98
+ groups: Object.values(this.children).map(child => child.toChartData())
121
99
  };
122
100
  }
123
-
124
101
  }
125
-
126
102
  exports.default = BaseFolder;
127
103
  ;
@@ -4,101 +4,83 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash"));
9
-
10
7
  var _Module = _interopRequireDefault(require("./Module"));
11
-
12
8
  var _ContentModule = _interopRequireDefault(require("./ContentModule"));
13
-
14
9
  var _ContentFolder = _interopRequireDefault(require("./ContentFolder"));
15
-
16
10
  var _utils = require("./utils");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
12
  class ConcatenatedModule extends _Module.default {
21
- constructor(name, data, parent) {
22
- super(name, data, parent);
13
+ constructor(name, data, parent, opts) {
14
+ super(name, data, parent, opts);
23
15
  this.name += ' (concatenated)';
24
16
  this.children = Object.create(null);
25
17
  this.fillContentModules();
26
18
  }
27
-
28
19
  get parsedSize() {
29
- var _this$getParsedSize;
30
-
31
- return (_this$getParsedSize = this.getParsedSize()) !== null && _this$getParsedSize !== void 0 ? _this$getParsedSize : this.getEstimatedSize('parsedSize');
20
+ return this.getParsedSize() ?? this.getEstimatedSize('parsedSize');
32
21
  }
33
-
34
22
  get gzipSize() {
35
- var _this$getGzipSize;
36
-
37
- 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');
27
+ }
28
+ get zstdSize() {
29
+ return this.getZstdSize() ?? this.getEstimatedSize('zstdSize');
38
30
  }
39
-
40
31
  getEstimatedSize(sizeType) {
41
32
  const parentModuleSize = this.parent[sizeType];
42
-
43
33
  if (parentModuleSize !== undefined) {
44
34
  return Math.floor(this.size / this.parent.size * parentModuleSize);
45
35
  }
46
36
  }
47
-
48
37
  fillContentModules() {
49
38
  this.data.modules.forEach(moduleData => this.addContentModule(moduleData));
50
39
  }
51
-
52
40
  addContentModule(moduleData) {
53
41
  const pathParts = (0, _utils.getModulePathParts)(moduleData);
54
-
55
42
  if (!pathParts) {
56
43
  return;
57
44
  }
58
-
59
- const [folders, fileName] = [pathParts.slice(0, -1), _lodash.default.last(pathParts)];
45
+ const [folders, fileName] = [pathParts.slice(0, -1), pathParts[pathParts.length - 1]];
60
46
  let currentFolder = this;
61
47
  folders.forEach(folderName => {
62
48
  let childFolder = currentFolder.getChild(folderName);
63
-
64
49
  if (!childFolder) {
65
50
  childFolder = currentFolder.addChildFolder(new _ContentFolder.default(folderName, this));
66
51
  }
67
-
68
52
  currentFolder = childFolder;
69
53
  });
70
54
  const ModuleConstructor = moduleData.modules ? ConcatenatedModule : _ContentModule.default;
71
- const module = new ModuleConstructor(fileName, moduleData, this);
55
+ const module = new ModuleConstructor(fileName, moduleData, this, this.opts);
72
56
  currentFolder.addChildModule(module);
73
57
  }
74
-
75
58
  getChild(name) {
76
59
  return this.children[name];
77
60
  }
78
-
79
61
  addChildModule(module) {
80
62
  module.parent = this;
81
63
  this.children[module.name] = module;
82
64
  }
83
-
84
65
  addChildFolder(folder) {
85
66
  folder.parent = this;
86
67
  this.children[folder.name] = folder;
87
68
  return folder;
88
69
  }
89
-
90
70
  mergeNestedFolders() {
91
- _lodash.default.invokeMap(this.children, 'mergeNestedFolders');
71
+ Object.values(this.children).forEach(child => {
72
+ if (child.mergeNestedFolders) {
73
+ child.mergeNestedFolders();
74
+ }
75
+ });
92
76
  }
93
-
94
77
  toChartData() {
95
- return { ...super.toChartData(),
78
+ return {
79
+ ...super.toChartData(),
96
80
  concatenated: true,
97
- groups: _lodash.default.invokeMap(this.children, 'toChartData')
81
+ groups: Object.values(this.children).map(child => child.toChartData())
98
82
  };
99
83
  }
100
-
101
84
  }
102
-
103
85
  exports.default = ConcatenatedModule;
104
86
  ;
@@ -4,42 +4,41 @@ 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
+ }
23
+ get zstdSize() {
24
+ return this.getSize('zstdSize');
25
+ }
26
26
  getSize(sizeType) {
27
27
  const ownerModuleSize = this.ownerModule[sizeType];
28
-
29
28
  if (ownerModuleSize !== undefined) {
30
29
  return Math.floor(this.size / this.ownerModule.size * ownerModuleSize);
31
30
  }
32
31
  }
33
-
34
32
  toChartData() {
35
- return { ...super.toChartData(),
33
+ return {
34
+ ...super.toChartData(),
36
35
  parsedSize: this.parsedSize,
37
36
  gzipSize: this.gzipSize,
37
+ brotliSize: this.brotliSize,
38
+ zstdSize: this.zstdSize,
38
39
  inaccurateSizes: true
39
40
  };
40
41
  }
41
-
42
42
  }
43
-
44
43
  exports.default = ContentFolder;
45
44
  ;
@@ -4,40 +4,37 @@ 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
+ }
23
+ get zstdSize() {
24
+ return this.getSize('zstdSize');
25
+ }
26
26
  getSize(sizeType) {
27
27
  const ownerModuleSize = this.ownerModule[sizeType];
28
-
29
28
  if (ownerModuleSize !== undefined) {
30
29
  return Math.floor(this.size / this.ownerModule.size * ownerModuleSize);
31
30
  }
32
31
  }
33
-
34
32
  toChartData() {
35
- return { ...super.toChartData(),
33
+ return {
34
+ ...super.toChartData(),
36
35
  inaccurateSizes: true
37
36
  };
38
37
  }
39
-
40
38
  }
41
-
42
39
  exports.default = ContentModule;
43
40
  ;
@@ -4,70 +4,70 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash"));
9
-
10
- var _gzipSize = _interopRequireDefault(require("gzip-size"));
11
-
12
7
  var _Module = _interopRequireDefault(require("./Module"));
13
-
14
8
  var _BaseFolder = _interopRequireDefault(require("./BaseFolder"));
15
-
16
9
  var _ConcatenatedModule = _interopRequireDefault(require("./ConcatenatedModule"));
17
-
18
10
  var _utils = require("./utils");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
11
+ var _sizeUtils = require("../sizeUtils");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
13
  class Folder extends _BaseFolder.default {
14
+ constructor(name, opts) {
15
+ super(name);
16
+ this.opts = opts;
17
+ }
23
18
  get parsedSize() {
24
19
  return this.src ? this.src.length : 0;
25
20
  }
26
-
27
21
  get gzipSize() {
28
- if (!_lodash.default.has(this, '_gzipSize')) {
29
- 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
+ get zstdSize() {
28
+ return this.opts.compressionAlgorithm === 'zstd' ? this.getCompressedSize('zstd') : undefined;
29
+ }
30
+ getCompressedSize(compressionAlgorithm) {
31
+ const key = `_${compressionAlgorithm}Size`;
32
+ if (!Object.prototype.hasOwnProperty.call(this, key)) {
33
+ this[key] = this.src ? (0, _sizeUtils.getCompressedSize)(compressionAlgorithm, this.src) : 0;
30
34
  }
31
-
32
- return this._gzipSize;
35
+ return this[key];
33
36
  }
34
-
35
37
  addModule(moduleData) {
36
38
  const pathParts = (0, _utils.getModulePathParts)(moduleData);
37
-
38
39
  if (!pathParts) {
39
40
  return;
40
41
  }
41
-
42
- const [folders, fileName] = [pathParts.slice(0, -1), _lodash.default.last(pathParts)];
42
+ const [folders, fileName] = [pathParts.slice(0, -1), pathParts[pathParts.length - 1]];
43
43
  let currentFolder = this;
44
44
  folders.forEach(folderName => {
45
45
  let childNode = currentFolder.getChild(folderName);
46
-
47
- if ( // Folder is not created yet
48
- !childNode || // In some situations (invalid usage of dynamic `require()`) webpack generates a module with empty require
46
+ if (
47
+ // Folder is not created yet
48
+ !childNode ||
49
+ // In some situations (invalid usage of dynamic `require()`) webpack generates a module with empty require
49
50
  // context, but it's moduleId points to a directory in filesystem.
50
51
  // In this case we replace this `File` node with `Folder`.
51
52
  // See `test/stats/with-invalid-dynamic-require.json` as an example.
52
53
  !(childNode instanceof Folder)) {
53
- childNode = currentFolder.addChildFolder(new Folder(folderName));
54
+ childNode = currentFolder.addChildFolder(new Folder(folderName, this.opts));
54
55
  }
55
-
56
56
  currentFolder = childNode;
57
57
  });
58
58
  const ModuleConstructor = moduleData.modules ? _ConcatenatedModule.default : _Module.default;
59
- const module = new ModuleConstructor(fileName, moduleData, this);
59
+ const module = new ModuleConstructor(fileName, moduleData, this, this.opts);
60
60
  currentFolder.addChildModule(module);
61
61
  }
62
-
63
62
  toChartData() {
64
- return { ...super.toChartData(),
63
+ return {
64
+ ...super.toChartData(),
65
65
  parsedSize: this.parsedSize,
66
- gzipSize: this.gzipSize
66
+ gzipSize: this.gzipSize,
67
+ brotliSize: this.brotliSize,
68
+ zstdSize: this.zstdSize
67
69
  };
68
70
  }
69
-
70
71
  }
71
-
72
72
  exports.default = Folder;
73
73
  ;
@@ -4,68 +4,69 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash"));
9
-
10
- var _gzipSize = _interopRequireDefault(require("gzip-size"));
11
-
12
7
  var _Node = _interopRequireDefault(require("./Node"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
8
+ var _sizeUtils = require("../sizeUtils");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
10
  class Module extends _Node.default {
17
- constructor(name, data, parent) {
11
+ constructor(name, data, parent, opts) {
18
12
  super(name, parent);
19
13
  this.data = data;
14
+ this.opts = opts;
20
15
  }
21
-
22
16
  get src() {
23
17
  return this.data.parsedSrc;
24
18
  }
25
-
26
19
  set src(value) {
27
20
  this.data.parsedSrc = value;
28
21
  delete this._gzipSize;
22
+ delete this._brotliSize;
23
+ delete this._zstdSize;
29
24
  }
30
-
31
25
  get size() {
32
26
  return this.data.size;
33
27
  }
34
-
35
28
  set size(value) {
36
29
  this.data.size = value;
37
30
  }
38
-
39
31
  get parsedSize() {
40
32
  return this.getParsedSize();
41
33
  }
42
-
43
34
  get gzipSize() {
44
35
  return this.getGzipSize();
45
36
  }
46
-
37
+ get brotliSize() {
38
+ return this.getBrotliSize();
39
+ }
40
+ get zstdSize() {
41
+ return this.getZstdSize();
42
+ }
47
43
  getParsedSize() {
48
44
  return this.src ? this.src.length : undefined;
49
45
  }
50
-
51
46
  getGzipSize() {
52
- if (!_lodash.default.has(this, '_gzipSize')) {
53
- this._gzipSize = this.src ? _gzipSize.default.sync(this.src) : undefined;
47
+ return this.opts.compressionAlgorithm === 'gzip' ? this.getCompressedSize('gzip') : undefined;
48
+ }
49
+ getBrotliSize() {
50
+ return this.opts.compressionAlgorithm === 'brotli' ? this.getCompressedSize('brotli') : undefined;
51
+ }
52
+ getZstdSize() {
53
+ return this.opts.compressionAlgorithm === 'zstd' ? this.getCompressedSize('zstd') : undefined;
54
+ }
55
+ getCompressedSize(compressionAlgorithm) {
56
+ const key = `_${compressionAlgorithm}Size`;
57
+ if (!(key in this)) {
58
+ this[key] = this.src ? (0, _sizeUtils.getCompressedSize)(compressionAlgorithm, this.src) : undefined;
54
59
  }
55
-
56
- return this._gzipSize;
60
+ return this[key];
57
61
  }
58
-
59
62
  mergeData(data) {
60
63
  if (data.size) {
61
64
  this.size += data.size;
62
65
  }
63
-
64
66
  if (data.parsedSrc) {
65
67
  this.src = (this.src || '') + data.parsedSrc;
66
68
  }
67
69
  }
68
-
69
70
  toChartData() {
70
71
  return {
71
72
  id: this.data.id,
@@ -73,11 +74,11 @@ class Module extends _Node.default {
73
74
  path: this.path,
74
75
  statSize: this.size,
75
76
  parsedSize: this.parsedSize,
76
- gzipSize: this.gzipSize
77
+ gzipSize: this.gzipSize,
78
+ brotliSize: this.brotliSize,
79
+ zstdSize: this.zstdSize
77
80
  };
78
81
  }
79
-
80
82
  }
81
-
82
83
  exports.default = Module;
83
84
  ;
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
@@ -4,23 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getModulePathParts = getModulePathParts;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
7
  const MULTI_MODULE_REGEXP = /^multi /u;
13
-
14
8
  function getModulePathParts(moduleData) {
15
9
  if (MULTI_MODULE_REGEXP.test(moduleData.identifier)) {
16
10
  return [moduleData.identifier];
17
11
  }
18
-
19
- const parsedPath = _lodash.default // Removing loaders from module path: they're joined by `!` and the last part is a raw module path
20
- .last(moduleData.name.split('!')) // Splitting module path into parts
21
- .split('/') // Removing first `.`
22
- .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`
23
20
  .map(part => part === '~' ? 'node_modules' : part);
24
-
25
21
  return parsedPath.length ? parsedPath : null;
26
22
  }