@@ -76,7 +76,7 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
76
76
var watch = ! ! options . watch ,
77
77
silent = ! ! options . json ;
78
78
if ( expectedConfigLength !== 1 && ! Array . isArray ( config )
79
- || ( Array . isArray ( config ) && config . length !== expectedConfigLength ) ) {
79
+ || ( Array . isArray ( config ) && config . length !== expectedConfigLength ) ) {
80
80
if ( config . length !== expectedConfigLength ) {
81
81
var errorMessage = '[WEBPACK] There is a difference between the amount of the'
82
82
+ ' provided configs. Maybe you where expecting command line'
@@ -105,11 +105,25 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
105
105
} ) ;
106
106
process . exit ( 0 ) ;
107
107
} ,
108
+ exitCallback = function ( code ) {
109
+ if ( code === 0 ) {
110
+ return ;
111
+ }
112
+ if ( watcher ) {
113
+ watcher . close ( done ) ;
114
+ }
115
+ done ( {
116
+ message : chalk . red ( '[WEBPACK]' )
117
+ + ' Exit ' + chalk . yellow ( getAppName ( webpackConfig ) )
118
+ + ' with code ' + code
119
+ } ) ;
120
+ } ,
108
121
finishedCallback = function ( err , stats ) {
109
122
if ( err ) {
110
123
console . error ( '%s fatal error occured' , chalk . red ( '[WEBPACK]' ) ) ;
111
124
console . error ( err ) ;
112
125
process . removeListener ( 'SIGINT' , shutdownCallback ) ;
126
+ process . removeListener ( 'exit' , exitCallback ) ;
113
127
return done ( err ) ;
114
128
}
115
129
if ( stats . compilation . errors && stats . compilation . errors . length ) {
@@ -121,6 +135,7 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
121
135
console . log ( message ) ;
122
136
} else {
123
137
process . removeListener ( 'SIGINT' , shutdownCallback ) ;
138
+ process . removeListener ( 'exit' , exitCallback ) ;
124
139
return done ( {
125
140
message : message ,
126
141
stats : JSON . stringify ( stats . toJson ( outputOptions ) , null , 2 )
@@ -138,6 +153,7 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
138
153
}
139
154
if ( ! watch ) {
140
155
process . removeListener ( 'SIGINT' , shutdownCallback ) ;
156
+ process . removeListener ( 'exit' , exitCallback ) ;
141
157
done ( null , options . stats ? JSON . stringify ( stats . toJson ( outputOptions ) , null , 2 ) : '' ) ;
142
158
} else if ( ! hasCompletedOneCompile ) {
143
159
notifyIPCWatchCompileDone ( index ) ;
@@ -155,5 +171,6 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
155
171
}
156
172
157
173
process . on ( 'SIGINT' , shutdownCallback ) ;
174
+ process . on ( 'exit' , exitCallback ) ;
158
175
} ) ;
159
176
} ;
0 commit comments