@@ -5,6 +5,7 @@ exports.makeEnv = makeEnv
5
5
exports . _incorrectWorkingDirectory = _incorrectWorkingDirectory
6
6
7
7
const spawn = require ( './lib/spawn' )
8
+ const { execute } = require ( '@yarnpkg/shell' )
8
9
const path = require ( 'path' )
9
10
const Stream = require ( 'stream' ) . Stream
10
11
const fs = require ( 'graceful-fs' )
@@ -14,6 +15,7 @@ const umask = require('umask')
14
15
const which = require ( 'which' )
15
16
const byline = require ( 'byline' )
16
17
const resolveFrom = require ( 'resolve-from' )
18
+ const { PassThrough } = require ( 'stream' )
17
19
18
20
const DEFAULT_NODE_GYP_PATH = resolveFrom ( __dirname , 'node-gyp/bin/node-gyp' )
19
21
const hookStatCache = new Map ( )
@@ -296,6 +298,33 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {
296
298
opts . log . verbose ( 'lifecycle' , logid ( pkg , stage ) , 'CWD:' , wd )
297
299
opts . log . silly ( 'lifecycle' , logid ( pkg , stage ) , 'Args:' , [ shFlag , cmd ] )
298
300
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
+
299
328
const proc = spawn ( sh , [ shFlag , cmd ] , conf , opts . log )
300
329
301
330
proc . on ( 'error' , procError )
0 commit comments