Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Commit

Permalink
fix(npm): manually look up npm path for Windows compat
Browse files Browse the repository at this point in the history
Fixes: #8
  • Loading branch information
zkat committed May 31, 2017
1 parent 9668c83 commit 0fe8fbf
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ function getExistingPath (command, opts) {
}

function getNpmCache (opts) {
return BB.fromNode(cb => {
cp.exec(`npm config get cache${
opts.userconfig ? ` --userconfig ${opts.userconfig}` : ''
}`, {}, cb)
}).then(cache => cache.trim())
return which('npm').then(npmPath => {
return BB.fromNode(cb => {
cp.exec(`${npmPath} config get cache${
opts.userconfig ? ` --userconfig ${opts.userconfig}` : ''
}`, {}, cb)
}).then(cache => cache.trim())
})
}

function buildArgs (spec, prefix, opts) {
Expand All @@ -108,17 +110,19 @@ function buildArgs (spec, prefix, opts) {

function installPackage (spec, prefix, npmOpts) {
const args = buildArgs(spec, prefix, npmOpts)
return BB.fromNode(cb => {
const child = cp.spawn('npm', args, {
stdio: [0, 2, 2] // pipe npm's output to stderr
})
child.on('error', cb)
child.on('close', code => {
if (code === 0) {
cb()
} else {
cb(new Error(`Install for ${spec} failed with code ${code}`))
}
return which('npm').then(npmPath => {
return BB.fromNode(cb => {
const child = cp.spawn(npmPath, args, {
stdio: [0, 2, 2] // pipe npm's output to stderr
})
child.on('error', cb)
child.on('close', code => {
if (code === 0) {
cb()
} else {
cb(new Error(`Install for ${spec} failed with code ${code}`))
}
})
})
})
}
Expand Down

0 comments on commit 0fe8fbf

Please sign in to comment.