@@ -79,11 +79,13 @@ function getExistingPath (command, opts) {
79
79
}
80
80
81
81
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
+ } )
87
89
}
88
90
89
91
function buildArgs ( spec , prefix , opts ) {
@@ -108,17 +110,19 @@ function buildArgs (spec, prefix, opts) {
108
110
109
111
function installPackage ( spec , prefix , npmOpts ) {
110
112
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
+ } )
122
126
} )
123
127
} )
124
128
}
0 commit comments