@@ -55,49 +55,38 @@ class Compiler {
5555 } ) ;
5656 }
5757
58- generateOutput ( outputOptions , stats ) {
59- logger . raw ( `${ stats . toString ( this . compilerOptions . stats ) } \n` ) ;
60- if ( outputOptions . watch ) {
61- logger . info ( 'watching files for updates...' ) ;
62- }
63- }
64-
65- compilerCallback ( err , stats , lastHash , options , outputOptions ) {
66- const statsErrors = [ ] ;
67-
68- if ( ! outputOptions . watch || err ) {
69- // Do not keep cache anymore
70- this . compiler . purgeInputFileSystem ( ) ;
71- }
72- if ( err ) {
58+ compilerCallback ( error , stats , lastHash , options , outputOptions ) {
59+ if ( error ) {
7360 lastHash = null ;
74- logger . error ( err . stack || err ) ;
61+ logger . error ( error ) ;
7562 process . exit ( 1 ) ;
7663 }
64+
7765 if ( ! outputOptions . watch && stats . hasErrors ( ) ) {
7866 process . exitCode = 1 ;
7967 }
80- if ( outputOptions . json === true ) {
81- process . stdout . write ( JSON . stringify ( stats . toJson ( outputOptions ) , null , 2 ) + '\n' ) ;
82- } else if ( stats . hash !== lastHash ) {
68+
69+ if ( stats . hash !== lastHash ) {
8370 lastHash = stats . hash ;
84- if ( stats . compilation && stats . compilation . errors . length !== 0 ) {
85- const errors = stats . compilation . errors ;
86- errors . forEach ( ( statErr ) => {
87- const errLoc = statErr . module ? statErr . module . resource : null ;
88- statsErrors . push ( { name : statErr . message , loc : errLoc } ) ;
89- } ) ;
90- }
91- const JSONStats = JSON . stringify ( stats . toJson ( outputOptions ) , null , 2 ) ;
92- if ( typeof outputOptions . json === 'string' ) {
71+
72+ if ( outputOptions . json === true ) {
73+ process . stdout . write ( JSON . stringify ( stats . toJson ( outputOptions ) , null , 2 ) + '\n' ) ;
74+ } else if ( typeof outputOptions . json === 'string' ) {
75+ const JSONStats = JSON . stringify ( stats . toJson ( outputOptions ) , null , 2 ) ;
76+
9377 try {
9478 writeFileSync ( outputOptions . json , JSONStats ) ;
9579 logger . success ( `stats are successfully stored as json to ${ outputOptions . json } ` ) ;
9680 } catch ( err ) {
9781 logger . error ( err ) ;
9882 }
83+ } else {
84+ logger . raw ( `${ stats . toString ( this . compilerOptions . stats ) } \n` ) ;
85+ }
86+
87+ if ( outputOptions . watch ) {
88+ logger . info ( 'watching files for updates...' ) ;
9989 }
100- return this . generateOutput ( outputOptions , stats , statsErrors ) ;
10190 }
10291 }
10392
@@ -107,20 +96,22 @@ class Compiler {
10796 await this . compiler . run ( ( err , stats ) => {
10897 if ( this . compiler . close ) {
10998 this . compiler . close ( ( ) => {
110- const content = this . compilerCallback ( err , stats , lastHash , options , outputOptions ) ;
111- resolve ( content ) ;
99+ this . compilerCallback ( err , stats , lastHash , options , outputOptions ) ;
100+
101+ resolve ( ) ;
112102 } ) ;
113103 } else {
114- const content = this . compilerCallback ( err , stats , lastHash , options , outputOptions ) ;
115- resolve ( content ) ;
104+ this . compilerCallback ( err , stats , lastHash , options , outputOptions ) ;
105+
106+ resolve ( ) ;
116107 }
117108 } ) ;
118109 } ) ;
119110 }
120111
121112 async invokeWatchInstance ( lastHash , options , outputOptions , watchOptions ) {
122113 return this . compiler . watch ( watchOptions , ( err , stats ) => {
123- return this . compilerCallback ( err , stats , lastHash , options , outputOptions ) ;
114+ this . compilerCallback ( err , stats , lastHash , options , outputOptions ) ;
124115 } ) ;
125116 }
126117
0 commit comments