webpack-bundle-analyzer 2.9.2 → 2.11.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.
- package/CHANGELOG.md +25 -0
- package/README.md +4 -2
- package/lib/BundleAnalyzerPlugin.js +35 -12
- package/lib/Logger.js +4 -3
- package/lib/analyzer.js +4 -31
- package/lib/bin/analyzer.js +11 -4
- package/lib/parseUtils.js +18 -0
- package/lib/tree/BaseFolder.js +139 -0
- package/lib/tree/ConcatenatedModule.js +122 -0
- package/lib/tree/ContentFolder.js +69 -0
- package/lib/tree/ContentModule.js +67 -0
- package/lib/tree/Folder.js +114 -0
- package/lib/tree/Module.js +101 -0
- package/lib/tree/Node.js +38 -0
- package/lib/tree/utils.js +34 -0
- package/lib/viewer.js +1 -0
- package/package.json +32 -32
- package/public/viewer.js +1 -1
- package/public/viewer.js.map +1 -1
- package/src/BundleAnalyzerPlugin.js +26 -12
- package/src/Logger.js +4 -1
- package/src/analyzer.js +3 -28
- package/src/bin/analyzer.js +20 -13
- package/src/parseUtils.js +30 -0
- package/src/tree/BaseFolder.js +95 -0
- package/src/tree/ConcatenatedModule.js +68 -0
- package/src/tree/ContentFolder.js +35 -0
- package/src/tree/ContentModule.js +33 -0
- package/src/tree/Folder.js +64 -0
- package/src/tree/Module.js +63 -0
- package/src/tree/Node.js +20 -0
- package/src/tree/utils.js +21 -0
- package/src/viewer.js +1 -0
- package/lib/tree.js +0 -304
- package/src/tree.js +0 -248
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,31 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
|
|
|
14
14
|
|
|
15
15
|
<!-- Add changelog entries for new changes under this section -->
|
|
16
16
|
|
|
17
|
+
## 2.11.1
|
|
18
|
+
|
|
19
|
+
* **Improvement**
|
|
20
|
+
* Add support for parsing Webpack 4's chunked modules ([#159](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/159), [@jdelStrother](https://github.com/jdelStrother))
|
|
21
|
+
|
|
22
|
+
## 2.11.0
|
|
23
|
+
|
|
24
|
+
* **Improvement**
|
|
25
|
+
* Show contents of concatenated module (requires Webpack 4) ([#158](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/158), closes [#157](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/157))
|
|
26
|
+
|
|
27
|
+
## 2.10.1
|
|
28
|
+
|
|
29
|
+
* **Improvement**
|
|
30
|
+
* Support webpack 4 without deprecation warnings. @ai in [#156](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/156), fixes [#154](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/154)
|
|
31
|
+
|
|
32
|
+
## 2.10.0
|
|
33
|
+
|
|
34
|
+
* **Bug Fix**
|
|
35
|
+
* Fix "out of memory" crash when dealing with huge stats objects ([#129](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/129), [@ryan953](https://github.com/ryan953))
|
|
36
|
+
|
|
37
|
+
* **Internal**
|
|
38
|
+
* Update dependencies ([#146](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/146))
|
|
39
|
+
* Update gulp to v4 and simplify gulpfile ([#146](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/146), [#149](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/149))
|
|
40
|
+
* Simplify ESLint configs ([#148](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/148))
|
|
41
|
+
|
|
17
42
|
## 2.9.2
|
|
18
43
|
|
|
19
44
|
* **Bug Fix**
|
package/README.md
CHANGED
|
@@ -149,9 +149,11 @@ This is the size of running the parsed bundles/modules through gzip compression.
|
|
|
149
149
|
|
|
150
150
|
### I can't see all the dependencies in a chunk
|
|
151
151
|
|
|
152
|
-
This is a known caveat when `webpack.optimize.ModuleConcatenationPlugin` is used
|
|
152
|
+
This is a known caveat when `webpack.optimize.ModuleConcatenationPlugin` is used with `Webpack 3` or `webpack-bundle-analyzer < 2.11.0`.
|
|
153
|
+
The way `ModuleConcatenationPlugin` works is that it merges multiple modules into a single one, and so that resulting module doesn't have edges anymore.
|
|
154
|
+
`Webpack 3` didn't provide any information about concatenated modules, but `Webpack 4` started including it into a `stats` files and `webpack-bundle-analyzer 2.11.0` learned to show it.
|
|
153
155
|
|
|
154
|
-
If
|
|
156
|
+
If for some reason you can't update to the latest versions try analyzing your bundle without `ModuleConcatenationPlugin`. See [issue #115](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/115) for more discussion.
|
|
155
157
|
|
|
156
158
|
<h2 align="center">Maintainers</h2>
|
|
157
159
|
|
|
@@ -6,7 +6,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
|
|
|
6
6
|
|
|
7
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var bfj = require('bfj-node4');
|
|
10
10
|
var path = require('path');
|
|
11
11
|
var mkdir = require('mkdirp');
|
|
12
12
|
|
|
@@ -46,7 +46,7 @@ var BundleAnalyzerPlugin = function () {
|
|
|
46
46
|
|
|
47
47
|
this.compiler = compiler;
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
var done = function done(stats) {
|
|
50
50
|
stats = stats.toJson(_this.opts.statsOptions);
|
|
51
51
|
|
|
52
52
|
var actions = [];
|
|
@@ -80,23 +80,46 @@ var BundleAnalyzerPlugin = function () {
|
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
-
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
if (compiler.hooks) {
|
|
86
|
+
compiler.hooks.done.tap('webpack-bundle-analyzer', done);
|
|
87
|
+
} else {
|
|
88
|
+
compiler.plugin('done', done);
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
91
|
}, {
|
|
86
92
|
key: 'generateStatsFile',
|
|
87
|
-
value: function
|
|
88
|
-
var
|
|
93
|
+
value: function () {
|
|
94
|
+
var _ref = _asyncToGenerator(function* (stats) {
|
|
95
|
+
var statsFilepath = path.resolve(this.compiler.outputPath, this.opts.statsFilename);
|
|
96
|
+
mkdir.sync(path.dirname(statsFilepath));
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
yield bfj.write(statsFilepath, stats, {
|
|
100
|
+
promises: 'ignore',
|
|
101
|
+
buffers: 'ignore',
|
|
102
|
+
maps: 'ignore',
|
|
103
|
+
iterables: 'ignore',
|
|
104
|
+
circular: 'ignore'
|
|
105
|
+
});
|
|
89
106
|
|
|
90
|
-
|
|
107
|
+
this.logger.info(`${bold('Webpack Bundle Analyzer')} saved stats file to ${bold(statsFilepath)}`);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
this.logger.error(`${bold('Webpack Bundle Analyzer')} error saving stats file to ${bold(statsFilepath)}: ${error}`);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
91
112
|
|
|
92
|
-
|
|
113
|
+
function generateStatsFile(_x) {
|
|
114
|
+
return _ref.apply(this, arguments);
|
|
115
|
+
}
|
|
93
116
|
|
|
94
|
-
|
|
95
|
-
}
|
|
117
|
+
return generateStatsFile;
|
|
118
|
+
}()
|
|
96
119
|
}, {
|
|
97
120
|
key: 'startAnalyzerServer',
|
|
98
121
|
value: function () {
|
|
99
|
-
var
|
|
122
|
+
var _ref2 = _asyncToGenerator(function* (stats) {
|
|
100
123
|
if (this.server) {
|
|
101
124
|
(yield this.server).updateChartData(stats);
|
|
102
125
|
} else {
|
|
@@ -111,8 +134,8 @@ var BundleAnalyzerPlugin = function () {
|
|
|
111
134
|
}
|
|
112
135
|
});
|
|
113
136
|
|
|
114
|
-
function startAnalyzerServer(
|
|
115
|
-
return
|
|
137
|
+
function startAnalyzerServer(_x2) {
|
|
138
|
+
return _ref2.apply(this, arguments);
|
|
116
139
|
}
|
|
117
140
|
|
|
118
141
|
return startAnalyzerServer;
|
package/lib/Logger.js
CHANGED
|
@@ -6,13 +6,13 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
6
6
|
|
|
7
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
8
|
|
|
9
|
-
var LEVELS = ['info', 'warn', 'error', 'silent'];
|
|
9
|
+
var LEVELS = ['debug', 'info', 'warn', 'error', 'silent'];
|
|
10
10
|
|
|
11
|
-
var LEVEL_TO_CONSOLE_METHOD = new Map([['info', 'log'], ['warn', 'log']]);
|
|
11
|
+
var LEVEL_TO_CONSOLE_METHOD = new Map([['debug', 'log'], ['info', 'log'], ['warn', 'log']]);
|
|
12
12
|
|
|
13
13
|
var Logger = function () {
|
|
14
14
|
function Logger() {
|
|
15
|
-
var level = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
15
|
+
var level = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Logger.defaultLevel;
|
|
16
16
|
|
|
17
17
|
_classCallCheck(this, Logger);
|
|
18
18
|
|
|
@@ -76,6 +76,7 @@ var Logger = function () {
|
|
|
76
76
|
}();
|
|
77
77
|
|
|
78
78
|
Logger.levels = LEVELS;
|
|
79
|
+
Logger.defaultLevel = 'info';
|
|
79
80
|
;
|
|
80
81
|
|
|
81
82
|
LEVELS.forEach(function (level) {
|
package/lib/analyzer.js
CHANGED
|
@@ -7,15 +7,12 @@ var _ = require('lodash');
|
|
|
7
7
|
var gzipSize = require('gzip-size');
|
|
8
8
|
|
|
9
9
|
var Logger = require('./Logger');
|
|
10
|
+
var Folder = require('./tree/Folder').default;
|
|
10
11
|
|
|
11
|
-
var _require = require('
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _require2 = require('../lib/parseUtils'),
|
|
15
|
-
parseBundle = _require2.parseBundle;
|
|
12
|
+
var _require = require('./parseUtils'),
|
|
13
|
+
parseBundle = _require.parseBundle;
|
|
16
14
|
|
|
17
15
|
var FILENAME_QUERY_REGEXP = /\?.*$/;
|
|
18
|
-
var MULTI_MODULE_REGEXP = /^multi /;
|
|
19
16
|
|
|
20
17
|
module.exports = {
|
|
21
18
|
getViewerData,
|
|
@@ -142,32 +139,8 @@ function createModulesTree(modules) {
|
|
|
142
139
|
var root = new Folder('.');
|
|
143
140
|
|
|
144
141
|
_.each(modules, function (module) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (path) {
|
|
148
|
-
root.addModuleByPath(path, module);
|
|
149
|
-
}
|
|
142
|
+
return root.addModule(module);
|
|
150
143
|
});
|
|
151
144
|
|
|
152
145
|
return root;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function getModulePath(module) {
|
|
156
|
-
if (MULTI_MODULE_REGEXP.test(module.identifier)) {
|
|
157
|
-
return [module.identifier];
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
var parsedPath = _
|
|
161
|
-
// Removing loaders from module path: they're joined by `!` and the last part is a raw module path
|
|
162
|
-
.last(module.name.split('!'))
|
|
163
|
-
// Splitting module path into parts
|
|
164
|
-
.split('/')
|
|
165
|
-
// Removing first `.`
|
|
166
|
-
.slice(1)
|
|
167
|
-
// Replacing `~` with `node_modules`
|
|
168
|
-
.map(function (part) {
|
|
169
|
-
return part === '~' ? 'node_modules' : part;
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
return parsedPath.length ? parsedPath : null;
|
|
173
146
|
}
|
package/lib/bin/analyzer.js
CHANGED
|
@@ -17,6 +17,7 @@ var _require2 = require('chalk'),
|
|
|
17
17
|
|
|
18
18
|
var analyzer = require('../analyzer');
|
|
19
19
|
var viewer = require('../viewer');
|
|
20
|
+
var Logger = require('../Logger');
|
|
20
21
|
|
|
21
22
|
var SIZES = new Set(['stat', 'parsed', 'gzip']);
|
|
22
23
|
|
|
@@ -27,18 +28,21 @@ var program = commander.version(require('../../package.json').version).usage(`<b
|
|
|
27
28
|
bundleStatsFile Path to Webpack Stats JSON file.
|
|
28
29
|
bundleDir Directory containing all generated bundles.
|
|
29
30
|
You should provided it if you want analyzer to show you the real parsed module sizes.
|
|
30
|
-
By default a directory of stats file is used.`).option('-m, --mode <mode>', 'Analyzer mode. Should be `server` or `static`.' + br('In `server` mode analyzer will start HTTP server to show bundle report.') + br('In `static` mode single HTML file with bundle report will be generated.')
|
|
31
|
+
By default a directory of stats file is used.`).option('-m, --mode <mode>', 'Analyzer mode. Should be `server` or `static`.' + br('In `server` mode analyzer will start HTTP server to show bundle report.') + br('In `static` mode single HTML file with bundle report will be generated.'), 'server').option('-h, --host <host>', 'Host that will be used in `server` mode to start HTTP server.', '127.0.0.1').option('-p, --port <n>', 'Port that will be used in `server` mode to start HTTP server.', Number, 8888).option('-r, --report <file>', 'Path to bundle report file that will be generated in `static` mode.', 'report.html').option('-s, --default-sizes <type>', 'Module sizes to show in treemap by default.' + br(`Possible values: ${[].concat(_toConsumableArray(SIZES)).join(', ')}`), 'parsed').option('-O, --no-open', "Don't open report in default browser automatically.").option('-l, --log-level <level>', 'Log level.' + br(`Possible values: ${[].concat(_toConsumableArray(Logger.levels)).join(', ')}`), Logger.defaultLevel).parse(process.argv);
|
|
31
32
|
|
|
32
33
|
var mode = program.mode,
|
|
33
34
|
host = program.host,
|
|
34
35
|
port = program.port,
|
|
35
36
|
reportFilename = program.report,
|
|
36
37
|
defaultSizes = program.defaultSizes,
|
|
38
|
+
logLevel = program.logLevel,
|
|
37
39
|
openBrowser = program.open,
|
|
38
40
|
_program$args = _slicedToArray(program.args, 2),
|
|
39
41
|
bundleStatsFile = _program$args[0],
|
|
40
42
|
bundleDir = _program$args[1];
|
|
41
43
|
|
|
44
|
+
var logger = new Logger(logLevel);
|
|
45
|
+
|
|
42
46
|
if (!bundleStatsFile) showHelp('Provide path to Webpack Stats file as first argument');
|
|
43
47
|
if (mode !== 'server' && mode !== 'static') showHelp('Invalid mode. Should be either `server` or `static`.');
|
|
44
48
|
if (mode === 'server' && !host) showHelp('Invalid host name');
|
|
@@ -53,7 +57,8 @@ var bundleStats = void 0;
|
|
|
53
57
|
try {
|
|
54
58
|
bundleStats = analyzer.readStatsFromFile(bundleStatsFile);
|
|
55
59
|
} catch (err) {
|
|
56
|
-
|
|
60
|
+
logger.error(`Could't read webpack bundle stats from "${bundleStatsFile}":\n${err}`);
|
|
61
|
+
logger.debug(err.stack);
|
|
57
62
|
process.exit(1);
|
|
58
63
|
}
|
|
59
64
|
|
|
@@ -63,14 +68,16 @@ if (mode === 'server') {
|
|
|
63
68
|
port,
|
|
64
69
|
host,
|
|
65
70
|
defaultSizes,
|
|
66
|
-
bundleDir
|
|
71
|
+
bundleDir,
|
|
72
|
+
logger: new Logger(logLevel)
|
|
67
73
|
});
|
|
68
74
|
} else {
|
|
69
75
|
viewer.generateReport(bundleStats, {
|
|
70
76
|
openBrowser,
|
|
71
77
|
reportFilename: resolve(reportFilename),
|
|
72
78
|
defaultSizes,
|
|
73
|
-
bundleDir
|
|
79
|
+
bundleDir,
|
|
80
|
+
logger: new Logger(logLevel)
|
|
74
81
|
});
|
|
75
82
|
}
|
|
76
83
|
|
package/lib/parseUtils.js
CHANGED
|
@@ -55,6 +55,13 @@ function parseBundle(bundlePath) {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// Additional bundles with webpack 4 are loaded with:
|
|
59
|
+
// (window.webpackJsonp=window.webpackJsonp||[]).push([[chunkId], [<module>, <module>], [[optional_entries]]]);
|
|
60
|
+
if (isWindowPropertyPushExpression(node) && args.length === 1 && isArgumentContainingChunkIdsAndModulesList(args[0])) {
|
|
61
|
+
state.locations = getModulesLocationFromFunctionArgument(args[0].elements[1]);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
58
65
|
// Walking into arguments because some of plugins (e.g. `DedupePlugin`) or some Webpack
|
|
59
66
|
// features (e.g. `umd` library output) can wrap modules list into additional IIFE.
|
|
60
67
|
_.each(args, function (arg) {
|
|
@@ -99,6 +106,13 @@ function isArgumentContainsModulesList(arg) {
|
|
|
99
106
|
return false;
|
|
100
107
|
}
|
|
101
108
|
|
|
109
|
+
function isArgumentContainingChunkIdsAndModulesList(arg) {
|
|
110
|
+
if (arg.type === 'ArrayExpression' && arg.elements.length >= 2 && isArgumentContainsChunkIds(arg.elements[0]) && isArgumentContainsModulesList(arg.elements[1])) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
102
116
|
function isArgumentArrayConcatContainingChunks(arg) {
|
|
103
117
|
if (arg.type === 'CallExpression' && arg.callee.type === 'MemberExpression' &&
|
|
104
118
|
// Make sure the object called is `Array(<some number>)`
|
|
@@ -116,6 +130,10 @@ function isArgumentArrayConcatContainingChunks(arg) {
|
|
|
116
130
|
return false;
|
|
117
131
|
}
|
|
118
132
|
|
|
133
|
+
function isWindowPropertyPushExpression(node) {
|
|
134
|
+
return node.callee.type === 'MemberExpression' && node.callee.property.name === 'push' && node.callee.object.type === 'AssignmentExpression' && node.callee.object.left.object.name === 'window';
|
|
135
|
+
}
|
|
136
|
+
|
|
119
137
|
function isModuleWrapper(node) {
|
|
120
138
|
return (
|
|
121
139
|
// It's an anonymous function expression that wraps module
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
+
|
|
9
|
+
var _lodash = require('lodash');
|
|
10
|
+
|
|
11
|
+
var _lodash2 = _interopRequireDefault(_lodash);
|
|
12
|
+
|
|
13
|
+
var _Node2 = require('./Node');
|
|
14
|
+
|
|
15
|
+
var _Node3 = _interopRequireDefault(_Node2);
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
+
|
|
21
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
22
|
+
|
|
23
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
24
|
+
|
|
25
|
+
var BaseFolder = function (_Node) {
|
|
26
|
+
_inherits(BaseFolder, _Node);
|
|
27
|
+
|
|
28
|
+
function BaseFolder(name, parent) {
|
|
29
|
+
_classCallCheck(this, BaseFolder);
|
|
30
|
+
|
|
31
|
+
var _this = _possibleConstructorReturn(this, (BaseFolder.__proto__ || Object.getPrototypeOf(BaseFolder)).call(this, name, parent));
|
|
32
|
+
|
|
33
|
+
_this.children = Object.create(null);
|
|
34
|
+
return _this;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_createClass(BaseFolder, [{
|
|
38
|
+
key: 'getChild',
|
|
39
|
+
value: function getChild(name) {
|
|
40
|
+
return this.children[name];
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: 'addChildModule',
|
|
44
|
+
value: function addChildModule(module) {
|
|
45
|
+
var name = module.name;
|
|
46
|
+
|
|
47
|
+
var currentChild = this.children[name];
|
|
48
|
+
|
|
49
|
+
// For some reason we already have this node in children and it's a folder.
|
|
50
|
+
if (currentChild && currentChild instanceof BaseFolder) return;
|
|
51
|
+
|
|
52
|
+
if (currentChild) {
|
|
53
|
+
// We already have this node in children and it's a module.
|
|
54
|
+
// Merging it's data.
|
|
55
|
+
currentChild.mergeData(module.data);
|
|
56
|
+
} else {
|
|
57
|
+
// Pushing new module
|
|
58
|
+
module.parent = this;
|
|
59
|
+
this.children[name] = module;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
delete this._size;
|
|
63
|
+
delete this._src;
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
key: 'addChildFolder',
|
|
67
|
+
value: function addChildFolder(folder) {
|
|
68
|
+
folder.parent = this;
|
|
69
|
+
this.children[folder.name] = folder;
|
|
70
|
+
delete this._size;
|
|
71
|
+
delete this._src;
|
|
72
|
+
|
|
73
|
+
return folder;
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: 'walk',
|
|
77
|
+
value: function walk(walker) {
|
|
78
|
+
var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
79
|
+
var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
80
|
+
|
|
81
|
+
var stopped = false;
|
|
82
|
+
|
|
83
|
+
_lodash2.default.each(this.children, function (child) {
|
|
84
|
+
if (deep && child.walk) {
|
|
85
|
+
state = child.walk(walker, state, stop);
|
|
86
|
+
} else {
|
|
87
|
+
state = walker(child, state, stop);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (stopped) return false;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return state;
|
|
94
|
+
|
|
95
|
+
function stop(finalState) {
|
|
96
|
+
stopped = true;
|
|
97
|
+
return finalState;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: 'toChartData',
|
|
102
|
+
value: function toChartData() {
|
|
103
|
+
return {
|
|
104
|
+
label: this.name,
|
|
105
|
+
path: this.path,
|
|
106
|
+
statSize: this.size,
|
|
107
|
+
groups: _lodash2.default.invokeMap(this.children, 'toChartData')
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: 'src',
|
|
112
|
+
get: function get() {
|
|
113
|
+
if (!_lodash2.default.has(this, '_src')) {
|
|
114
|
+
this._src = this.walk(function (node, src, stop) {
|
|
115
|
+
if (node.src === undefined) return stop(undefined);
|
|
116
|
+
return src += node.src;
|
|
117
|
+
}, '', false);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return this._src;
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: 'size',
|
|
124
|
+
get: function get() {
|
|
125
|
+
if (!_lodash2.default.has(this, '_size')) {
|
|
126
|
+
this._size = this.walk(function (node, size) {
|
|
127
|
+
return size + node.size;
|
|
128
|
+
}, 0, false);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return this._size;
|
|
132
|
+
}
|
|
133
|
+
}]);
|
|
134
|
+
|
|
135
|
+
return BaseFolder;
|
|
136
|
+
}(_Node3.default);
|
|
137
|
+
|
|
138
|
+
exports.default = BaseFolder;
|
|
139
|
+
;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
+
|
|
9
|
+
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
|
10
|
+
|
|
11
|
+
var _lodash = require('lodash');
|
|
12
|
+
|
|
13
|
+
var _lodash2 = _interopRequireDefault(_lodash);
|
|
14
|
+
|
|
15
|
+
var _Module2 = require('./Module');
|
|
16
|
+
|
|
17
|
+
var _Module3 = _interopRequireDefault(_Module2);
|
|
18
|
+
|
|
19
|
+
var _ContentModule = require('./ContentModule');
|
|
20
|
+
|
|
21
|
+
var _ContentModule2 = _interopRequireDefault(_ContentModule);
|
|
22
|
+
|
|
23
|
+
var _ContentFolder = require('./ContentFolder');
|
|
24
|
+
|
|
25
|
+
var _ContentFolder2 = _interopRequireDefault(_ContentFolder);
|
|
26
|
+
|
|
27
|
+
var _utils = require('./utils');
|
|
28
|
+
|
|
29
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
+
|
|
31
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
32
|
+
|
|
33
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
34
|
+
|
|
35
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
36
|
+
|
|
37
|
+
var ConcatenatedModule = function (_Module) {
|
|
38
|
+
_inherits(ConcatenatedModule, _Module);
|
|
39
|
+
|
|
40
|
+
function ConcatenatedModule(name, data, parent) {
|
|
41
|
+
_classCallCheck(this, ConcatenatedModule);
|
|
42
|
+
|
|
43
|
+
var _this = _possibleConstructorReturn(this, (ConcatenatedModule.__proto__ || Object.getPrototypeOf(ConcatenatedModule)).call(this, name, data, parent));
|
|
44
|
+
|
|
45
|
+
_this.name += ' (concatenated)';
|
|
46
|
+
_this.children = Object.create(null);
|
|
47
|
+
_this.fillContentModules();
|
|
48
|
+
return _this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_createClass(ConcatenatedModule, [{
|
|
52
|
+
key: 'fillContentModules',
|
|
53
|
+
value: function fillContentModules() {
|
|
54
|
+
var _this2 = this;
|
|
55
|
+
|
|
56
|
+
_lodash2.default.each(this.data.modules, function (moduleData) {
|
|
57
|
+
return _this2.addContentModule(moduleData);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: 'addContentModule',
|
|
62
|
+
value: function addContentModule(moduleData) {
|
|
63
|
+
var _this3 = this;
|
|
64
|
+
|
|
65
|
+
var pathParts = (0, _utils.getModulePathParts)(moduleData);
|
|
66
|
+
|
|
67
|
+
if (!pathParts) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var _ref = [pathParts.slice(0, -1), _lodash2.default.last(pathParts)],
|
|
72
|
+
folders = _ref[0],
|
|
73
|
+
fileName = _ref[1];
|
|
74
|
+
|
|
75
|
+
var currentFolder = this;
|
|
76
|
+
|
|
77
|
+
_lodash2.default.each(folders, function (folderName) {
|
|
78
|
+
var childFolder = currentFolder.getChild(folderName);
|
|
79
|
+
|
|
80
|
+
if (!childFolder) {
|
|
81
|
+
childFolder = currentFolder.addChildFolder(new _ContentFolder2.default(folderName, _this3));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
currentFolder = childFolder;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
var module = new _ContentModule2.default(fileName, moduleData, this);
|
|
88
|
+
currentFolder.addChildModule(module);
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: 'getChild',
|
|
92
|
+
value: function getChild(name) {
|
|
93
|
+
return this.children[name];
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: 'addChildModule',
|
|
97
|
+
value: function addChildModule(module) {
|
|
98
|
+
module.parent = this;
|
|
99
|
+
this.children[module.name] = module;
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: 'addChildFolder',
|
|
103
|
+
value: function addChildFolder(folder) {
|
|
104
|
+
folder.parent = this;
|
|
105
|
+
this.children[folder.name] = folder;
|
|
106
|
+
return folder;
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
key: 'toChartData',
|
|
110
|
+
value: function toChartData() {
|
|
111
|
+
return Object.assign({}, _get(ConcatenatedModule.prototype.__proto__ || Object.getPrototypeOf(ConcatenatedModule.prototype), 'toChartData', this).call(this), {
|
|
112
|
+
concatenated: true,
|
|
113
|
+
groups: _lodash2.default.invokeMap(this.children, 'toChartData')
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}]);
|
|
117
|
+
|
|
118
|
+
return ConcatenatedModule;
|
|
119
|
+
}(_Module3.default);
|
|
120
|
+
|
|
121
|
+
exports.default = ConcatenatedModule;
|
|
122
|
+
;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
+
|
|
9
|
+
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
|
10
|
+
|
|
11
|
+
var _BaseFolder2 = require('./BaseFolder');
|
|
12
|
+
|
|
13
|
+
var _BaseFolder3 = _interopRequireDefault(_BaseFolder2);
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
|
+
|
|
19
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
20
|
+
|
|
21
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
22
|
+
|
|
23
|
+
var ContentFolder = function (_BaseFolder) {
|
|
24
|
+
_inherits(ContentFolder, _BaseFolder);
|
|
25
|
+
|
|
26
|
+
function ContentFolder(name, ownerModule, parent) {
|
|
27
|
+
_classCallCheck(this, ContentFolder);
|
|
28
|
+
|
|
29
|
+
var _this = _possibleConstructorReturn(this, (ContentFolder.__proto__ || Object.getPrototypeOf(ContentFolder)).call(this, name, parent));
|
|
30
|
+
|
|
31
|
+
_this.ownerModule = ownerModule;
|
|
32
|
+
return _this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_createClass(ContentFolder, [{
|
|
36
|
+
key: 'getSize',
|
|
37
|
+
value: function getSize(sizeType) {
|
|
38
|
+
var ownerModuleSize = this.ownerModule[sizeType];
|
|
39
|
+
|
|
40
|
+
if (ownerModuleSize !== undefined) {
|
|
41
|
+
return Math.floor(this.size / this.ownerModule.size * ownerModuleSize);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: 'toChartData',
|
|
46
|
+
value: function toChartData() {
|
|
47
|
+
return Object.assign({}, _get(ContentFolder.prototype.__proto__ || Object.getPrototypeOf(ContentFolder.prototype), 'toChartData', this).call(this), {
|
|
48
|
+
parsedSize: this.parsedSize,
|
|
49
|
+
gzipSize: this.gzipSize,
|
|
50
|
+
inaccurateSizes: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: 'parsedSize',
|
|
55
|
+
get: function get() {
|
|
56
|
+
return this.getSize('parsedSize');
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: 'gzipSize',
|
|
60
|
+
get: function get() {
|
|
61
|
+
return this.getSize('gzipSize');
|
|
62
|
+
}
|
|
63
|
+
}]);
|
|
64
|
+
|
|
65
|
+
return ContentFolder;
|
|
66
|
+
}(_BaseFolder3.default);
|
|
67
|
+
|
|
68
|
+
exports.default = ContentFolder;
|
|
69
|
+
;
|