Skip to content

Commit 4b1a3db

Browse files
committed
feat: opts.shellEmulator
ref pnpm/pnpm#2621
1 parent 5055bff commit 4b1a3db

File tree

3 files changed

+176
-16
lines changed

3 files changed

+176
-16
lines changed

index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ exports.makeEnv = makeEnv
55
exports._incorrectWorkingDirectory = _incorrectWorkingDirectory
66

77
const spawn = require('./lib/spawn')
8+
const { execute } = require('@yarnpkg/shell')
89
const path = require('path')
910
const Stream = require('stream').Stream
1011
const fs = require('graceful-fs')
@@ -14,6 +15,7 @@ const umask = require('umask')
1415
const which = require('which')
1516
const byline = require('byline')
1617
const resolveFrom = require('resolve-from')
18+
const { PassThrough } = require('stream')
1719

1820
const DEFAULT_NODE_GYP_PATH = resolveFrom(__dirname, 'node-gyp/bin/node-gyp')
1921
const 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)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
"author": "Mike Sherov",
2626
"license": "Artistic-2.0",
2727
"engines": {
28-
"node": ">=10.13"
28+
"node": ">=10.19"
2929
},
3030
"bugs": {
3131
"url": "https://github.com/npm/lifecycle/issues"
3232
},
3333
"homepage": "https://github.com/npm/lifecycle#readme",
3434
"dependencies": {
35+
"@yarnpkg/shell": "^2.2.0",
3536
"byline": "^5.0.0",
3637
"graceful-fs": "^4.1.15",
3738
"node-gyp": "^7.0.0",

0 commit comments

Comments
 (0)