Skip to content

Commit 71cf49a

Browse files
committed
add depth to module
add depth to stats fix stats spacing (fixes webpack#3541) add maxModules to stats, default to 15 (fixes webpack#3540)
1 parent 8059be6 commit 71cf49a

File tree

8 files changed

+146
-35
lines changed

8 files changed

+146
-35
lines changed

bin/webpack.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ yargs.options({
7373
group: DISPLAY_GROUP,
7474
describe: "Display even excluded modules in the output"
7575
},
76+
"display-max-modules": {
77+
type: "number",
78+
group: DISPLAY_GROUP,
79+
describe: "Sets the maximum number of visible modules in output"
80+
},
7681
"display-chunks": {
7782
type: "boolean",
7883
group: DISPLAY_GROUP,
@@ -103,6 +108,11 @@ yargs.options({
103108
group: DISPLAY_GROUP,
104109
describe: "Display reasons about module inclusion in the output"
105110
},
111+
"display-depth": {
112+
type: "boolean",
113+
group: DISPLAY_GROUP,
114+
describe: "Display distance from entry point for each module"
115+
},
106116
"display-used-exports": {
107117
type: "boolean",
108118
group: DISPLAY_GROUP,
@@ -129,6 +139,7 @@ var argv = yargs.argv;
129139

130140
if(argv.verbose) {
131141
argv["display-reasons"] = true;
142+
argv["display-depth"] = true;
132143
argv["display-entrypoints"] = true;
133144
argv["display-used-exports"] = true;
134145
argv["display-provided-exports"] = true;
@@ -214,6 +225,10 @@ function processOptions(options) {
214225
outputOptions.reasons = bool;
215226
});
216227

228+
ifArg("display-depth", function(bool) {
229+
outputOptions.depth = bool;
230+
});
231+
217232
ifArg("display-used-exports", function(bool) {
218233
outputOptions.usedExports = bool;
219234
});
@@ -230,6 +245,10 @@ function processOptions(options) {
230245
outputOptions.chunkOrigins = bool;
231246
});
232247

248+
ifArg("display-max-modules", function(value) {
249+
outputOptions.maxModules = value;
250+
});
251+
233252
ifArg("display-cached", function(bool) {
234253
if(bool)
235254
outputOptions.cached = true;
@@ -240,8 +259,13 @@ function processOptions(options) {
240259
outputOptions.cachedAssets = true;
241260
});
242261

243-
if(!outputOptions.exclude && !argv["display-modules"])
262+
if(!outputOptions.exclude)
244263
outputOptions.exclude = ["node_modules", "bower_components", "jam", "components"];
264+
265+
if(argv["display-modules"]) {
266+
outputOptions.maxModules = Infinity;
267+
outputOptions.exclude = undefined;
268+
}
245269
} else {
246270
if(typeof outputOptions.chunks === "undefined")
247271
outputOptions.chunks = true;

lib/Compilation.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ Compilation.prototype.seal = function seal(callback) {
534534
module.addChunk(chunk);
535535
chunk.entryModule = module;
536536
self.assignIndex(module);
537+
self.assignDepth(module);
537538
self.processDependenciesBlockForChunk(module, chunk);
538539
}, self);
539540
self.sortModules(self.modules);
@@ -738,6 +739,58 @@ Compilation.prototype.assignIndex = function assignIndex(module) {
738739
}
739740
};
740741

742+
Compilation.prototype.assignDepth = function assignDepth(module) {
743+
var _this = this;
744+
745+
function assignDepthToModule(module, depth) {
746+
// enter module
747+
if(typeof module.depth === "number" && module.depth <= depth) return;
748+
module.depth = depth;
749+
750+
// enter it as block
751+
assignDepthToDependencyBlock(module, depth + 1);
752+
}
753+
754+
function assignDepthToDependency(dependency, depth) {
755+
if(dependency.module) {
756+
queue.push(function() {
757+
assignDepthToModule(dependency.module, depth);
758+
});
759+
}
760+
}
761+
762+
function assignDepthToDependencyBlock(block, depth) {
763+
var allDependencies = [];
764+
765+
function iteratorDependency(d) {
766+
assignDepthToDependency(d, depth);
767+
}
768+
769+
function iteratorBlock(b) {
770+
assignDepthToDependencyBlock(b, depth);
771+
}
772+
773+
if(block.variables) {
774+
block.variables.forEach(function(v) {
775+
v.dependencies.forEach(iteratorDependency);
776+
});
777+
}
778+
if(block.dependencies) {
779+
block.dependencies.forEach(iteratorDependency);
780+
}
781+
if(block.blocks) {
782+
block.blocks.forEach(iteratorBlock, this);
783+
}
784+
}
785+
786+
var queue = [function() {
787+
assignDepthToModule(module, 0);
788+
}];
789+
while(queue.length) {
790+
queue.pop()();
791+
}
792+
};
793+
741794
Compilation.prototype.processDependenciesBlockForChunk = function processDependenciesBlockForChunk(block, chunk) {
742795
var queue = [
743796
[block, chunk]

lib/Module.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function Module() {
1919
this.portableId = null;
2020
this.index = null;
2121
this.index2 = null;
22+
this.depth = null;
2223
this.used = null;
2324
this.usedExports = null;
2425
this.providedExports = null;
@@ -51,6 +52,7 @@ Module.prototype.disconnect = function() {
5152
this.id = null;
5253
this.index = null;
5354
this.index2 = null;
55+
this.depth = null;
5456
this.used = null;
5557
this.usedExports = null;
5658
this.providedExports = null;
@@ -63,6 +65,7 @@ Module.prototype.unseal = function() {
6365
this.id = null;
6466
this.index = null;
6567
this.index2 = null;
68+
this.depth = null;
6669
this.chunks.length = 0;
6770
DependenciesBlock.prototype.unseal.call(this);
6871
};

lib/Stats.js

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
4141
var showChunkModules = d(options.chunkModules, !!forToString);
4242
var showChunkOrigins = d(options.chunkOrigins, !forToString);
4343
var showModules = d(options.modules, !forToString);
44+
var showDepth = d(options.depth, !forToString);
4445
var showCachedModules = d(options.cached, true);
4546
var showCachedAssets = d(options.cachedAssets, true);
4647
var showReasons = d(options.reasons, !forToString);
@@ -56,20 +57,27 @@ Stats.prototype.toJson = function toJson(options, forToString) {
5657
if(typeof str !== "string") return str;
5758
return new RegExp("[\\\\/]" + str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "([\\\\/]|$|!|\\?)");
5859
});
60+
var maxModules = d(options.maxModules, forToString ? 15 : Infinity);
5961
var sortModules = d(options.modulesSort, "id");
6062
var sortChunks = d(options.chunksSort, "id");
6163
var sortAssets = d(options.assetsSort, "");
6264

63-
function moduleFilter(module) {
64-
if(!showCachedModules && !module.built) {
65-
return false;
66-
}
67-
if(excludeModules.length === 0)
68-
return true;
69-
var ident = module.resource;
70-
return !excludeModules.some(function(regExp) {
71-
return regExp.test(ident);
72-
});
65+
function createModuleFilter() {
66+
var i = 0;
67+
return function(module) {
68+
if(!showCachedModules && !module.built) {
69+
return false;
70+
}
71+
if(excludeModules.length > 0) {
72+
var ident = requestShortener.shorten(module.resource);
73+
var excluded = excludeModules.some(function(regExp) {
74+
return regExp.test(ident);
75+
});
76+
if(excluded)
77+
return false;
78+
}
79+
return i++ < maxModules;
80+
};
7381
}
7482

7583
function sortByField(field) {
@@ -79,11 +87,17 @@ Stats.prototype.toJson = function toJson(options, forToString) {
7987
if(field[0] === "!") {
8088
field = field.substr(1);
8189
return function(a, b) {
90+
if(a[field] === null && b[field] === null) return 0;
91+
if(a[field] === null) return 1;
92+
if(b[field] === null) return -1;
8293
if(a[field] === b[field]) return 0;
8394
return a[field] < b[field] ? 1 : -1;
8495
};
8596
}
8697
return function(a, b) {
98+
if(a[field] === null && b[field] === null) return 0;
99+
if(a[field] === null) return 1;
100+
if(b[field] === null) return -1;
87101
if(a[field] === b[field]) return 0;
88102
return a[field] < b[field] ? -1 : 1;
89103
};
@@ -272,6 +286,9 @@ Stats.prototype.toJson = function toJson(options, forToString) {
272286
if(showProvidedExports) {
273287
obj.providedExports = Array.isArray(module.providedExports) ? module.providedExports : null;
274288
}
289+
if(showDepth) {
290+
obj.depth = module.depth;
291+
}
275292
if(showSource && module._source) {
276293
obj.source = module._source.source();
277294
}
@@ -297,7 +314,11 @@ Stats.prototype.toJson = function toJson(options, forToString) {
297314
})
298315
};
299316
if(showChunkModules) {
300-
obj.modules = chunk.modules.filter(moduleFilter).map(fnModule);
317+
obj.modules = chunk.modules
318+
.slice()
319+
.sort(sortByField("depth"))
320+
.filter(createModuleFilter())
321+
.map(fnModule);
301322
obj.filteredModules = chunk.modules.length - obj.modules.length;
302323
obj.modules.sort(sortByField(sortModules));
303324
}
@@ -320,7 +341,11 @@ Stats.prototype.toJson = function toJson(options, forToString) {
320341
obj.chunks.sort(sortByField(sortChunks));
321342
}
322343
if(showModules) {
323-
obj.modules = compilation.modules.filter(moduleFilter).map(fnModule);
344+
obj.modules = compilation.modules
345+
.slice()
346+
.sort(sortByField("depth"))
347+
.filter(createModuleFilter())
348+
.map(fnModule);
324349
obj.filteredModules = compilation.modules.length - obj.modules.length;
325350
obj.modules.sort(sortByField(sortModules));
326351
}
@@ -417,13 +442,10 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
417442
var colSizes = new Array(cols);
418443
var value;
419444
for(col = 0; col < cols; col++)
420-
colSizes[col] = 3;
445+
colSizes[col] = 0;
421446
for(row = 0; row < rows; row++) {
422447
for(col = 0; col < cols; col++) {
423448
value = getText(array, row, col) + "";
424-
if(value.length === 0) {
425-
colSizes[col] = 0;
426-
}
427449
if(value.length > colSizes[col]) {
428450
colSizes[col] = value.length;
429451
}
@@ -440,7 +462,7 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
440462
colors.normal(" ");
441463
if(align[col] === "r")
442464
format(value);
443-
if(col + 1 < cols && colSizes[col] != 0)
465+
if(col + 1 < cols && colSizes[col] !== 0)
444466
colors.normal(splitter || " ");
445467
}
446468
newline();
@@ -564,6 +586,9 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
564586
colors.normal("}");
565587
});
566588
}
589+
if(typeof module.depth === "number") {
590+
colors.normal(" [depth " + module.depth + "]");
591+
}
567592
if(!module.cacheable) {
568593
colors.red(" [not cacheable]");
569594
}
@@ -799,8 +824,10 @@ Stats.presetToOptions = function(name) {
799824
assets: false,
800825
entrypoints: false,
801826
chunks: false,
827+
chunkModules: false,
802828
modules: false,
803829
reasons: false,
830+
depth: false,
804831
usedExports: false,
805832
providedExports: false,
806833
children: false,
@@ -822,6 +849,7 @@ Stats.presetToOptions = function(name) {
822849
//warnings: pn !== "errors-only",
823850
errorDetails: pn !== "errors-only" && pn !== "minimal",
824851
reasons: pn === "verbose",
852+
depth: pn === "verbose",
825853
usedExports: pn === "verbose",
826854
providedExports: pn === "verbose",
827855
colors: true

test/Stats.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ describe("Stats", function() {
163163
chunkModules: false,
164164
errorDetails: true,
165165
reasons: false,
166+
depth: false,
166167
usedExports: false,
167168
providedExports: false,
168169
colors: true
@@ -185,8 +186,10 @@ describe("Stats", function() {
185186
assets: false,
186187
entrypoints: false,
187188
chunks: false,
189+
chunkModules: false,
188190
modules: false,
189191
reasons: false,
192+
depth: false,
190193
usedExports: false,
191194
providedExports: false,
192195
children: false,

test/browsertest/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ var library1 = cp.spawn("node", join(["../../bin/webpack.js", "--output-pathinfo
3434
bindOutput(library1);
3535
library1.on("exit", function(code) {
3636
if(code === 0) {
37-
// node ../../bin/webpack --output-pathinfo --color --resolve-alias vm=vm-browserify --output-public-path js/ --output-chunk-filename [name].web.js --module-bind json --module-bind css=style!css --module-bind less=style-loader!css-loader!less-loader --module-bind coffee --module-bind jade --prefetch ./lib/stylesheet.less ./lib/index "js/web.js?h=[hash]"
37+
// node ../../bin/webpack --output-pathinfo --color --resolve-alias vm=vm-browserify --output-public-path js/ --output-chunk-filename [name].web.js --module-bind css=style!css --module-bind less=style-loader!css-loader!less-loader --module-bind coffee --module-bind jade --prefetch ./lib/stylesheet.less ./lib/index "js/web.js?h=[hash]"
3838
var main = cp.spawn("node", join(["../../bin/webpack.js", "--output-pathinfo", "--color", "--resolve-alias", "vm=vm-browserify",
3939
"--output-public-path", "js/", "--output-chunk-filename", "[name].web.js",
40-
"--module-bind", "json", "--module-bind", "css=style-loader!css-loader", "--module-bind", "less=style-loader/url!file-loader?postfix=.css&string!less-loader", "--module-bind", "coffee", "--module-bind", "jade", "--prefetch", "./lib/stylesheet.less", "./lib/index", "js/web.js?h=[hash]", "--progress"], extraArgs));
40+
"--module-bind", "css=style-loader!css-loader", "--module-bind", "less=style-loader/url!file-loader?postfix=.css&string!less-loader", "--module-bind", "coffee", "--module-bind", "jade", "--prefetch", "./lib/stylesheet.less", "./lib/index", "js/web.js?h=[hash]", "--progress"], extraArgs));
4141
bindOutput(main);
4242
}
4343
});

test/statsCases/preset-normal-performance-ensure-filter-sourcemaps/expected.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Time: <CLR=BOLD>X</CLR>ms
2-
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22><CLR=BOLD>Chunk Names</CLR>
3-
<CLR=32,BOLD>0.js</CLR> 257 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
4-
<CLR=32,BOLD>1.js</CLR> 136 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
5-
<CLR=32,BOLD>2.js</CLR> 230 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
6-
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR>main
7-
<CLR=32,BOLD>0.js.map</CLR> 291 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
8-
<CLR=32,BOLD>1.js.map</CLR> 250 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
9-
<CLR=32,BOLD>2.js.map</CLR> 405 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
10-
<CLR=32,BOLD>main.js.map</CLR> 1.81 MB <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> main
2+
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
3+
<CLR=32,BOLD>0.js</CLR> 257 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
4+
<CLR=32,BOLD>1.js</CLR> 136 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
5+
<CLR=32,BOLD>2.js</CLR> 230 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
6+
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
7+
<CLR=32,BOLD>0.js.map</CLR> 291 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
8+
<CLR=32,BOLD>1.js.map</CLR> 250 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
9+
<CLR=32,BOLD>2.js.map</CLR> 405 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
10+
<CLR=32,BOLD>main.js.map</CLR> 1.81 MB <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> main
1111
chunk {<CLR=33,BOLD>0</CLR>} <CLR=32,BOLD>0.js, 0.js.map</CLR> 54 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [rendered]</CLR>
1212
[2] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance-ensure-filter-sourcemaps/c.js</CLR> 54 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [built]</CLR>
1313
chunk {<CLR=33,BOLD>1</CLR>} <CLR=32,BOLD>1.js, 1.js.map</CLR> 22 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [rendered]</CLR>

test/statsCases/preset-verbose/expected.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ Time: Xms
77
main.js 5.83 kB 3 [emitted] main
88
Entrypoint main = main.js
99
chunk {0} 0.js 54 bytes {3} [rendered]
10-
[2] (webpack)/test/statsCases/preset-verbose/c.js 54 bytes {0} [built]
10+
[2] (webpack)/test/statsCases/preset-verbose/c.js 54 bytes {0} [depth 1] [built]
1111
amd require ./c [5] (webpack)/test/statsCases/preset-verbose/index.js 3:0-16
1212
[] -> factory:Xms building:Xms = Xms
1313
chunk {1} 1.js 22 bytes {3} [rendered]
14-
[1] (webpack)/test/statsCases/preset-verbose/b.js 22 bytes {1} [built]
14+
[1] (webpack)/test/statsCases/preset-verbose/b.js 22 bytes {1} [depth 1] [built]
1515
amd require ./b [5] (webpack)/test/statsCases/preset-verbose/index.js 2:0-16
1616
[] -> factory:Xms building:Xms = Xms
1717
chunk {2} 2.js 44 bytes {0} [rendered]
18-
[3] (webpack)/test/statsCases/preset-verbose/d.js 22 bytes {2} [built]
18+
[3] (webpack)/test/statsCases/preset-verbose/d.js 22 bytes {2} [depth 2] [built]
1919
require.ensure item ./d [2] (webpack)/test/statsCases/preset-verbose/c.js 1:0-52
2020
[] -> factory:Xms building:Xms = Xms
21-
[4] (webpack)/test/statsCases/preset-verbose/e.js 22 bytes {2} [built]
21+
[4] (webpack)/test/statsCases/preset-verbose/e.js 22 bytes {2} [depth 2] [built]
2222
require.ensure item ./e [2] (webpack)/test/statsCases/preset-verbose/c.js 1:0-52
2323
[] -> factory:Xms building:Xms = Xms
2424
chunk {3} main.js (main) 73 bytes [entry] [rendered]
25-
[0] (webpack)/test/statsCases/preset-verbose/a.js 22 bytes {3} [built]
25+
[0] (webpack)/test/statsCases/preset-verbose/a.js 22 bytes {3} [depth 1] [built]
2626
cjs require ./a [5] (webpack)/test/statsCases/preset-verbose/index.js 1:0-14
2727
[] -> factory:Xms building:Xms = Xms
28-
[5] (webpack)/test/statsCases/preset-verbose/index.js 51 bytes {3} [built]
28+
[5] (webpack)/test/statsCases/preset-verbose/index.js 51 bytes {3} [depth 0] [built]
2929
factory:Xms building:Xms = Xms

0 commit comments

Comments
 (0)