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

Commit 0fe8fbf

Browse files
committed
fix(npm): manually look up npm path for Windows compat
Fixes: #8
1 parent 9668c83 commit 0fe8fbf

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

index.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ function getExistingPath (command, opts) {
7979
}
8080

8181
function getNpmCache (opts) {
82-
return BB.fromNode(cb => {
83-
cp.exec(`npm config get cache${
84-
opts.userconfig ? ` --userconfig ${opts.userconfig}` : ''
85-
}`, {}, cb)
86-
}).then(cache => cache.trim())
82+
return which('npm').then(npmPath => {
83+
return BB.fromNode(cb => {
84+
cp.exec(`${npmPath} config get cache${
85+
opts.userconfig ? ` --userconfig ${opts.userconfig}` : ''
86+
}`, {}, cb)
87+
}).then(cache => cache.trim())
88+
})
8789
}
8890

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

109111
function installPackage (spec, prefix, npmOpts) {
110112
const args = buildArgs(spec, prefix, npmOpts)
111-
return BB.fromNode(cb => {
112-
const child = cp.spawn('npm', args, {
113-
stdio: [0, 2, 2] // pipe npm's output to stderr
114-
})
115-
child.on('error', cb)
116-
child.on('close', code => {
117-
if (code === 0) {
118-
cb()
119-
} else {
120-
cb(new Error(`Install for ${spec} failed with code ${code}`))
121-
}
113+
return which('npm').then(npmPath => {
114+
return BB.fromNode(cb => {
115+
const child = cp.spawn(npmPath, args, {
116+
stdio: [0, 2, 2] // pipe npm's output to stderr
117+
})
118+
child.on('error', cb)
119+
child.on('close', code => {
120+
if (code === 0) {
121+
cb()
122+
} else {
123+
cb(new Error(`Install for ${spec} failed with code ${code}`))
124+
}
125+
})
122126
})
123127
})
124128
}

0 commit comments

Comments
 (0)