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

Commit

Permalink
feat(child): add opts.installerStdio (#126)
Browse files Browse the repository at this point in the history
This is needed because pnpm prints its logging to stdout.

Fixes:  #121
  • Loading branch information
zkochan authored and zkat committed Oct 19, 2017
1 parent f80a970 commit ade03f7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ function installPackages (specs, prefix, opts) {
return process.platform === 'win32' ? child.escapeArg(npmPath, true) : npmPath
}).then(npmPath => {
return child.spawn(npmPath, args, {
stdio: [0, 'pipe', opts.q ? 'ignore' : 2]
stdio: opts.installerStdio
? opts.installerStdio
: [0, 'pipe', opts.q ? 'ignore' : 2]
}).then(deets => {
try {
return deets.stdout ? JSON.parse(deets.stdout) : null
Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,18 @@ test('findNodeScript', t => {
})
})
})

test('npx with custom installer stdio', t => {
const NPX_PATH = path.resolve(__dirname, 'util', 'npx-bin-inherit-stdio.js')
const NPX_ESC = isWindows ? child.escapeArg(NPX_PATH) : NPX_PATH

return child.spawn('node', [
NPX_ESC, '[email protected]'
], {stdio: 'pipe'}).then(res => {
t.equal(res.code, 0, 'command succeeded')
t.match(
res.stdout.toString(), /"added":/, 'installer output printed directly to console'
)
t.end()
})
})
11 changes: 11 additions & 0 deletions test/util/npx-bin-inherit-stdio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node

const npx = require('../../index.js')
const path = require('path')

const NPM_PATH = path.join(__dirname, '../..', 'node_modules', 'npm', 'bin', 'npm-cli.js')

const npxOpts = Object.assign({}, npx.parseArgs(process.argv, NPM_PATH), {
installerStdio: 'inherit'
})
npx(npxOpts)

0 comments on commit ade03f7

Please sign in to comment.