@@ -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
0 commit comments