@@ -5,6 +5,7 @@ exports.makeEnv = makeEnv
55exports . _incorrectWorkingDirectory = _incorrectWorkingDirectory
66
77const spawn = require ( './lib/spawn' )
8+ const { execute } = require ( '@yarnpkg/shell' )
89const path = require ( 'path' )
910const Stream = require ( 'stream' ) . Stream
1011const fs = require ( 'graceful-fs' )
@@ -14,6 +15,7 @@ const umask = require('umask')
1415const which = require ( 'which' )
1516const byline = require ( 'byline' )
1617const resolveFrom = require ( 'resolve-from' )
18+ const { PassThrough } = require ( 'stream' )
1719
1820const DEFAULT_NODE_GYP_PATH = resolveFrom ( __dirname , 'node-gyp/bin/node-gyp' )
1921const hookStatCache = new Map ( )
@@ -296,6 +298,33 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {
296298 opts . log . verbose ( 'lifecycle' , logid ( pkg , stage ) , 'CWD:' , wd )
297299 opts . log . silly ( 'lifecycle' , logid ( pkg , stage ) , 'Args:' , [ shFlag , cmd ] )
298300
301+ if ( opts . shellEmulator ) {
302+ const execOpts = { cwd : wd , env }
303+ if ( opts . stdio === 'pipe' ) {
304+ const stdout = new PassThrough ( )
305+ const stderr = new PassThrough ( )
306+ byline ( stdout ) . on ( 'data' , data => {
307+ opts . log . verbose ( 'lifecycle' , logid ( pkg , stage ) , 'stdout' , data . toString ( ) )
308+ } )
309+ byline ( stderr ) . on ( 'data' , data => {
310+ opts . log . verbose ( 'lifecycle' , logid ( pkg , stage ) , 'stderr' , data . toString ( ) )
311+ } )
312+ execOpts . stdout = stdout
313+ execOpts . stderr = stderr
314+ }
315+ execute ( cmd , [ ] , execOpts )
316+ . then ( ( code ) => {
317+ opts . log . silly ( 'lifecycle' , logid ( pkg , stage ) , 'Returned: code:' , code )
318+ if ( code ) {
319+ var er = new Error ( `Exit status ${ code } ` )
320+ er . errno = code
321+ }
322+ procError ( er )
323+ } )
324+ . catch ( ( err ) => procError ( err ) )
325+ return
326+ }
327+
299328 const proc = spawn ( sh , [ shFlag , cmd ] , conf , opts . log )
300329
301330 proc . on ( 'error' , procError )
0 commit comments