Skip to content
This repository was archived by the owner on Apr 7, 2021. It is now read-only.

Commit ade03f7

Browse files
zkochanzkat
authored andcommitted
feat(child): add opts.installerStdio (#126)
This is needed because pnpm prints its logging to stdout. Fixes: #121
1 parent f80a970 commit ade03f7

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ function installPackages (specs, prefix, opts) {
235235
return process.platform === 'win32' ? child.escapeArg(npmPath, true) : npmPath
236236
}).then(npmPath => {
237237
return child.spawn(npmPath, args, {
238-
stdio: [0, 'pipe', opts.q ? 'ignore' : 2]
238+
stdio: opts.installerStdio
239+
? opts.installerStdio
240+
: [0, 'pipe', opts.q ? 'ignore' : 2]
239241
}).then(deets => {
240242
try {
241243
return deets.stdout ? JSON.parse(deets.stdout) : null

test/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,18 @@ test('findNodeScript', t => {
255255
})
256256
})
257257
})
258+
259+
test('npx with custom installer stdio', t => {
260+
const NPX_PATH = path.resolve(__dirname, 'util', 'npx-bin-inherit-stdio.js')
261+
const NPX_ESC = isWindows ? child.escapeArg(NPX_PATH) : NPX_PATH
262+
263+
return child.spawn('node', [
264+
NPX_ESC, 'say-shalom@1.2.7'
265+
], {stdio: 'pipe'}).then(res => {
266+
t.equal(res.code, 0, 'command succeeded')
267+
t.match(
268+
res.stdout.toString(), /"added":/, 'installer output printed directly to console'
269+
)
270+
t.end()
271+
})
272+
})

test/util/npx-bin-inherit-stdio.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
3+
const npx = require('../../index.js')
4+
const path = require('path')
5+
6+
const NPM_PATH = path.join(__dirname, '../..', 'node_modules', 'npm', 'bin', 'npm-cli.js')
7+
8+
const npxOpts = Object.assign({}, npx.parseArgs(process.argv, NPM_PATH), {
9+
installerStdio: 'inherit'
10+
})
11+
npx(npxOpts)

0 commit comments

Comments
 (0)