@@ -137,14 +137,17 @@ var createClass = function () {
137137 } ;
138138} ( ) ;
139139
140- var exec = require ( 'child_process' ) . exec ;
140+ var toArray = function ( arr ) {
141+ return Array . isArray ( arr ) ? arr : Array . from ( arr ) ;
142+ } ;
143+
144+ var spawn = require ( 'child_process' ) . spawn ;
141145var defaultOptions = {
142146 onBuildStart : [ ] ,
143147 onBuildEnd : [ ] ,
144148 onBuildExit : [ ] ,
145149 dev : true ,
146- verbose : false ,
147- throwOnExecError : false
150+ verbose : false
148151} ;
149152
150153function puts ( error , stdout , stderr ) {
@@ -153,15 +156,29 @@ function puts(error, stdout, stderr) {
153156 }
154157}
155158
156- function putsThrow ( error , stdout , stderr ) {
157- if ( error ) {
158- throw error ;
159+ function serializeScript ( script ) {
160+ if ( typeof script === 'string' ) {
161+ var _script$split = script . split ( ' ' ) ,
162+ _script$split2 = toArray ( _script$split ) ,
163+ _command = _script$split2 [ 0 ] ,
164+ _args = _script$split2 . slice ( 1 ) ;
165+
166+ return { command : _command , args : _args } ;
159167 }
168+ var command = script . command ,
169+ args = script . args ;
170+
171+ return { command : command , args : args } ;
160172}
161173
162- function spreadStdoutAndStdErr ( proc ) {
163- proc . stdout . pipe ( process . stdout ) ;
164- proc . stderr . pipe ( process . stdout ) ;
174+ function handleScript ( script ) {
175+ var _serializeScript = serializeScript ( script ) ,
176+ command = _serializeScript . command ,
177+ args = _serializeScript . args ;
178+
179+ var proc = spawn ( command , args , { stdio : 'inherit' } ) ;
180+
181+ proc . on ( 'close' , puts ) ;
165182}
166183
167184function validateInput ( options ) {
@@ -204,13 +221,7 @@ var WebpackShellPlugin = function () {
204221 }
205222 if ( _this . options . onBuildStart . length ) {
206223 console . log ( 'Executing pre-build scripts' ) ;
207- _this . options . onBuildStart . forEach ( function ( script ) {
208- if ( _this . options . throwOnExecError ) {
209- spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
210- } else {
211- spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
212- }
213- } ) ;
224+ _this . options . onBuildStart . forEach ( handleScript ) ;
214225 if ( _this . options . dev ) {
215226 _this . options . onBuildStart = [ ] ;
216227 }
@@ -220,13 +231,7 @@ var WebpackShellPlugin = function () {
220231 compiler . plugin ( 'emit' , function ( compilation , callback ) {
221232 if ( _this . options . onBuildEnd . length ) {
222233 console . log ( 'Executing post-build scripts' ) ;
223- _this . options . onBuildEnd . forEach ( function ( script ) {
224- if ( _this . options . throwOnExecError ) {
225- spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
226- } else {
227- spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
228- }
229- } ) ;
234+ _this . options . onBuildEnd . forEach ( handleScript ) ;
230235 if ( _this . options . dev ) {
231236 _this . options . onBuildEnd = [ ] ;
232237 }
@@ -237,13 +242,7 @@ var WebpackShellPlugin = function () {
237242 compiler . plugin ( 'done' , function ( ) {
238243 if ( _this . options . onBuildExit . length ) {
239244 console . log ( 'Executing additional scripts before exit' ) ;
240- _this . options . onBuildExit . forEach ( function ( script ) {
241- if ( _this . options . throwOnExecError ) {
242- spreadStdoutAndStdErr ( exec ( script , putsThrow ) ) ;
243- } else {
244- spreadStdoutAndStdErr ( exec ( script , puts ) ) ;
245- }
246- } ) ;
245+ _this . options . onBuildExit . forEach ( handleScript ) ;
247246 }
248247 } ) ;
249248 }
0 commit comments