webpack-bundle-analyzer 2.13.1 → 3.0.2

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.
@@ -1,7 +1,7 @@
1
- const bfj = require('bfj-node4');
1
+ const bfj = require('bfj');
2
2
  const path = require('path');
3
3
  const mkdir = require('mkdirp');
4
- const { bold } = require('chalk');
4
+ const {bold} = require('chalk');
5
5
 
6
6
  const Logger = require('./Logger');
7
7
  const viewer = require('./viewer');
package/src/analyzer.js CHANGED
@@ -6,8 +6,8 @@ const gzipSize = require('gzip-size');
6
6
 
7
7
  const Logger = require('./Logger');
8
8
  const Folder = require('./tree/Folder').default;
9
- const { parseBundle } = require('./parseUtils');
10
- const { createAssetsFilter } = require('./utils');
9
+ const {parseBundle} = require('./parseUtils');
10
+ const {createAssetsFilter} = require('./utils');
11
11
 
12
12
  const FILENAME_QUERY_REGEXP = /\?.*$/;
13
13
 
@@ -132,6 +132,7 @@ function createModulesTree(modules) {
132
132
  const root = new Folder('.');
133
133
 
134
134
  _.each(modules, module => root.addModule(module));
135
+ root.mergeNestedFolders();
135
136
 
136
137
  return root;
137
138
  }
@@ -1,10 +1,10 @@
1
1
  #! /usr/bin/env node
2
2
 
3
- const { resolve, dirname } = require('path');
3
+ const {resolve, dirname} = require('path');
4
4
 
5
5
  const _ = require('lodash');
6
6
  const commander = require('commander');
7
- const { magenta } = require('chalk');
7
+ const {magenta} = require('chalk');
8
8
 
9
9
  const analyzer = require('../analyzer');
10
10
  const viewer = require('../viewer');
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const { start } = require('./viewer');
1
+ const {start} = require('./viewer');
2
2
 
3
3
  module.exports = {
4
4
  start,
@@ -30,7 +30,7 @@ export default class BaseFolder extends Node {
30
30
  }
31
31
 
32
32
  addChildModule(module) {
33
- const { name } = module;
33
+ const {name} = module;
34
34
  const currentChild = this.children[name];
35
35
 
36
36
  // For some reason we already have this node in children and it's a folder.
@@ -80,6 +80,32 @@ export default class BaseFolder extends Node {
80
80
  }
81
81
  }
82
82
 
83
+ mergeNestedFolders() {
84
+ if (!this.isRoot) {
85
+ let childNames;
86
+
87
+ while ((childNames = Object.keys(this.children)).length === 1) {
88
+ const childName = childNames[0];
89
+ const onlyChild = this.children[childName];
90
+
91
+ if (onlyChild instanceof this.constructor) {
92
+ this.name += `/${onlyChild.name}`;
93
+ this.children = onlyChild.children;
94
+ } else {
95
+ break;
96
+ }
97
+ }
98
+ }
99
+
100
+ this.walk(child => {
101
+ child.parent = this;
102
+
103
+ if (child.mergeNestedFolders) {
104
+ child.mergeNestedFolders();
105
+ }
106
+ }, null, false);
107
+ }
108
+
83
109
  toChartData() {
84
110
  return {
85
111
  label: this.name,
@@ -3,7 +3,7 @@ import _ from 'lodash';
3
3
  import Module from './Module';
4
4
  import ContentModule from './ContentModule';
5
5
  import ContentFolder from './ContentFolder';
6
- import { getModulePathParts } from './utils';
6
+ import {getModulePathParts} from './utils';
7
7
 
8
8
  export default class ConcatenatedModule extends Module {
9
9
 
@@ -57,6 +57,10 @@ export default class ConcatenatedModule extends Module {
57
57
  return folder;
58
58
  }
59
59
 
60
+ mergeNestedFolders() {
61
+ _.invokeMap(this.children, 'mergeNestedFolders');
62
+ }
63
+
60
64
  toChartData() {
61
65
  return {
62
66
  ...super.toChartData(),
@@ -4,7 +4,7 @@ import gzipSize from 'gzip-size';
4
4
  import Module from './Module';
5
5
  import BaseFolder from './BaseFolder';
6
6
  import ConcatenatedModule from './ConcatenatedModule';
7
- import { getModulePathParts } from './utils';
7
+ import {getModulePathParts} from './utils';
8
8
 
9
9
  export default class Folder extends BaseFolder {
10
10
 
package/src/tree/Node.js CHANGED
@@ -17,4 +17,8 @@ export default class Node {
17
17
  return path.reverse().join('/');
18
18
  }
19
19
 
20
+ get isRoot() {
21
+ return !this.parent;
22
+ }
23
+
20
24
  };
package/src/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- const { inspect } = require('util');
1
+ const {inspect} = require('util');
2
2
  const _ = require('lodash');
3
3
 
4
4
  exports.createAssetsFilter = createAssetsFilter;
@@ -18,7 +18,7 @@ function createAssetsFilter(excludePatterns) {
18
18
 
19
19
  if (!_.isFunction(pattern)) {
20
20
  throw new TypeError(
21
- `Pattern should be either string, RegExp or a function, but "${inspect(pattern, { depth: 0 })}" got.`
21
+ `Pattern should be either string, RegExp or a function, but "${inspect(pattern, {depth: 0})}" got.`
22
22
  );
23
23
  }
24
24
 
package/src/viewer.js CHANGED
@@ -8,7 +8,7 @@ const express = require('express');
8
8
  const ejs = require('ejs');
9
9
  const opener = require('opener');
10
10
  const mkdir = require('mkdirp');
11
- const { bold } = require('chalk');
11
+ const {bold} = require('chalk');
12
12
 
13
13
  const Logger = require('./Logger');
14
14
  const analyzer = require('./analyzer');
@@ -33,7 +33,7 @@ async function startServer(bundleStats, opts) {
33
33
  excludeAssets = null
34
34
  } = opts || {};
35
35
 
36
- const analyzerOpts = { logger, excludeAssets };
36
+ const analyzerOpts = {logger, excludeAssets};
37
37
 
38
38
  let chartData = getChartData(analyzerOpts, bundleStats, bundleDir);
39
39
 
@@ -75,7 +75,7 @@ async function startServer(bundleStats, opts) {
75
75
  });
76
76
  });
77
77
 
78
- const wss = new WebSocket.Server({ server });
78
+ const wss = new WebSocket.Server({server});
79
79
 
80
80
  wss.on('connection', ws => {
81
81
  ws.on('error', err => {
@@ -120,7 +120,7 @@ function generateReport(bundleStats, opts) {
120
120
  excludeAssets = null
121
121
  } = opts || {};
122
122
 
123
- const chartData = getChartData({ logger, excludeAssets }, bundleStats, bundleDir);
123
+ const chartData = getChartData({logger, excludeAssets}, bundleStats, bundleDir);
124
124
 
125
125
  if (!chartData) return;
126
126
 
@@ -157,7 +157,7 @@ function getAssetContent(filename) {
157
157
 
158
158
  function getChartData(analyzerOpts, ...args) {
159
159
  let chartData;
160
- const { logger } = analyzerOpts;
160
+ const {logger} = analyzerOpts;
161
161
 
162
162
  try {
163
163
  chartData = analyzer.getViewerData(...args, analyzerOpts);