33 Author Tobias Koppers @sokra
44*/
55var RequestShortener = require ( "./RequestShortener" ) ;
6+ var formatSize = require ( "./SizeFormatHelpers" ) . formatSize ;
67
78function Stats ( compilation ) {
89 this . compilation = compilation ;
@@ -30,6 +31,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
3031 }
3132 var compilation = this . compilation ;
3233 var requestShortener = new RequestShortener ( d ( options . context , process . cwd ( ) ) ) ;
34+ var showPerformance = d ( options . performance , true ) ;
3335 var showHash = d ( options . hash , true ) ;
3436 var showVersion = d ( options . version , true ) ;
3537 var showTimings = d ( options . timings , true ) ;
@@ -170,6 +172,11 @@ Stats.prototype.toJson = function toJson(options, forToString) {
170172 chunkNames : [ ] ,
171173 emitted : compilation . assets [ asset ] . emitted
172174 } ;
175+
176+ if ( showPerformance ) {
177+ obj . isOverSizeLimit = compilation . assets [ asset ] . isOverSizeLimit ;
178+ }
179+
173180 assetsByFile [ asset ] = obj ;
174181 return obj ;
175182 } ) . filter ( function ( asset ) {
@@ -323,6 +330,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
323330 return obj ;
324331 } ) ;
325332 }
333+
326334 return obj ;
327335} ;
328336
@@ -394,7 +402,11 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
394402 buf . push ( "\n" ) ;
395403 }
396404
397- function table ( array , formats , align , splitter ) {
405+ function getText ( arr , row , col ) {
406+ return arr [ row ] [ col ] . value ;
407+ }
408+
409+ function table ( array , align , splitter ) {
398410 var row ;
399411 var rows = array . length ;
400412 var col ;
@@ -405,38 +417,39 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
405417 colSizes [ col ] = 3 ;
406418 for ( row = 0 ; row < rows ; row ++ ) {
407419 for ( col = 0 ; col < cols ; col ++ ) {
408- value = array [ row ] [ col ] + "" ;
420+ value = getText ( array , row , col ) + "" ;
421+ if ( value . length === 0 ) {
422+ colSizes [ col ] = 0 ;
423+ }
409424 if ( value . length > colSizes [ col ] ) {
410425 colSizes [ col ] = value . length ;
411426 }
412427 }
413428 }
414429 for ( row = 0 ; row < rows ; row ++ ) {
415430 for ( col = 0 ; col < cols ; col ++ ) {
416- var format = row === 0 ? colors . bold : formats [ col ] ;
417- value = array [ row ] [ col ] + "" ;
431+ var format = array [ row ] [ col ] . color ;
432+ value = getText ( array , row , col ) + "" ;
418433 var l = value . length ;
419434 if ( align [ col ] === "l" )
420435 format ( value ) ;
421436 for ( ; l < colSizes [ col ] && col !== cols - 1 ; l ++ )
422437 colors . normal ( " " ) ;
423438 if ( align [ col ] === "r" )
424439 format ( value ) ;
425- if ( col + 1 < cols )
440+ if ( col + 1 < cols && colSizes [ col ] != 0 )
426441 colors . normal ( splitter || " " ) ;
427442 }
428443 newline ( ) ;
429444 }
430445 }
431446
432- function formatSize ( size ) {
433- if ( size <= 0 ) return "0 bytes" ;
434-
435- var abbreviations = [ "bytes" , "kB" , "MB" , "GB" ] ;
436- var index = Math . floor ( Math . log ( size ) / Math . log ( 1000 ) ) ;
447+ function getAssetColor ( asset , defaultColor ) {
448+ if ( asset . isOverSizeLimit ) {
449+ return colors . yellow ;
450+ }
437451
438- return + ( size / Math . pow ( 1000 , index ) )
439- . toPrecision ( 3 ) + " " + abbreviations [ index ] ;
452+ return defaultColor ;
440453 }
441454
442455 if ( obj . hash ) {
@@ -460,20 +473,51 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
460473 colors . bold ( obj . publicPath ) ;
461474 newline ( ) ;
462475 }
476+
463477 if ( obj . assets && obj . assets . length > 0 ) {
464478 var t = [
465- [ "Asset" , "Size" , "Chunks" , "" , "Chunk Names" ]
479+ [ {
480+ value : "Asset" ,
481+ color : colors . bold
482+ } , {
483+ value : "Size" ,
484+ color : colors . bold
485+ } , {
486+ value : "Chunks" ,
487+ color : colors . bold
488+ } , {
489+ value : "" ,
490+ color : colors . bold
491+ } , {
492+ value : "" ,
493+ color : colors . bold
494+ } , {
495+ value : "Chunk Names" ,
496+ color : colors . bold
497+ } ]
466498 ] ;
467499 obj . assets . forEach ( function ( asset ) {
468- t . push ( [
469- asset . name ,
470- formatSize ( asset . size ) ,
471- asset . chunks . join ( ", " ) ,
472- asset . emitted ? "[emitted]" : "" ,
473- asset . chunkNames . join ( ", " )
474- ] ) ;
500+ t . push ( [ {
501+ value : asset . name ,
502+ color : getAssetColor ( asset , colors . green )
503+ } , {
504+ value : formatSize ( asset . size ) ,
505+ color : getAssetColor ( asset , colors . normal )
506+ } , {
507+ value : asset . chunks . join ( ", " ) ,
508+ color : colors . bold
509+ } , {
510+ value : asset . emitted ? "[emitted]" : "" ,
511+ color : colors . green
512+ } , {
513+ value : asset . isOverSizeLimit ? "[big]" : "" ,
514+ color : getAssetColor ( asset , colors . normal )
515+ } , {
516+ value : asset . chunkNames . join ( ", " ) ,
517+ color : colors . normal
518+ } ] ) ;
475519 } ) ;
476- table ( t , [ colors . green , colors . normal , colors . bold , colors . green , colors . normal ] , "rrrll ") ;
520+ table ( t , "rrrlll ") ;
477521 }
478522 if ( obj . entrypoints ) {
479523 Object . keys ( obj . entrypoints ) . forEach ( function ( name ) {
0 commit comments