@@ -137,7 +137,11 @@ 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 : [ ] ,
@@ -153,15 +157,29 @@ function puts(error, stdout, stderr) {
153157 }
154158}
155159
156- function putsThrow ( error , stdout , stderr ) {
157- if ( error ) {
158- throw error ;
160+ function serializeScript ( script ) {
161+ if ( typeof script === 'string' ) {
162+ var _script$split = script . split ( ' ' ) ,
163+ _script$split2 = toArray ( _script$split ) ,
164+ _command = _script$split2 [ 0 ] ,
165+ _args = _script$split2 . slice ( 1 ) ;
166+
167+ return { command : _command , args : _args } ;
159168 }
169+ var command = script . command ,
170+ args = script . args ;
171+
172+ return { command : command , args : args } ;
160173}
161174
162- function spreadStdoutAndStdErr ( proc ) {
163- proc . stdout . pipe ( process . stdout ) ;
164- proc . stderr . pipe ( process . stdout ) ;
175+ function handleScript ( script ) {
176+ var _serializeScript = serializeScript ( script ) ,
177+ command = _serializeScript . command ,
178+ args = _serializeScript . args ;
179+
180+ var proc = spawn ( command , args , { stdio : 'inherit' } ) ;
181+
182+ proc . on ( 'close' , puts ) ;
165183}
166184
167185function validateInput ( options ) {
@@ -204,13 +222,7 @@ var WebpackShellPlugin = function () {
204222 }
205223 if ( _this . options . onBuildStart . length ) {
206224 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- } ) ;
225+ _this . options . onBuildStart . forEach ( handleScript ) ;
214226 if ( _this . options . dev ) {
215227 _this . options . onBuildStart = [ ] ;
216228 }
@@ -220,13 +232,7 @@ var WebpackShellPlugin = function () {
220232 compiler . plugin ( 'emit' , function ( compilation , callback ) {
221233 if ( _this . options . onBuildEnd . length ) {
222234 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- } ) ;
235+ _this . options . onBuildEnd . forEach ( handleScript ) ;
230236 if ( _this . options . dev ) {
231237 _this . options . onBuildEnd = [ ] ;
232238 }
@@ -237,13 +243,7 @@ var WebpackShellPlugin = function () {
237243 compiler . plugin ( 'done' , function ( ) {
238244 if ( _this . options . onBuildExit . length ) {
239245 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- } ) ;
246+ _this . options . onBuildExit . forEach ( handleScript ) ;
247247 }
248248 } ) ;
249249 }
0 commit comments