From 3eb50ca946ee29f25dc9083d0210ffc9556b3237 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Fri, 8 Jul 2016 07:40:57 -0700 Subject: [PATCH] plugins: detect location of `npm` --- plugins.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plugins.js b/plugins.js index c6841d3e..965f5343 100644 --- a/plugins.js +++ b/plugins.js @@ -166,22 +166,24 @@ function toDependencies (plugins) { } function install (fn) { - exec('npm prune && npm install --production', { - cwd: path - }, (err, stdout, stderr) => { + which('npm', (err, bin) => { if (err) { - if (/(command not found|not recognized as an)/.test(err.stack)) { - if (plugins.plugins.length) { - alert('We found `plugins` in `.hyperterm.js`, but `npm` is ' + - 'not installed or not in $PATH!\nPlease head to ' + - 'https://nodejs.org and install the Node.js runtime.'); - } else { - console.log('npm not found, but no plugins defined'); - } + if (plugins.plugins.length) { + alert('We found `plugins` in `.hyperterm.js`, but `npm` is ' + + 'not installed or not in $PATH!\nPlease head to ' + + 'https://nodejs.org and install the Node.js runtime.'); + } else { + console.log('npm not found, but no plugins defined'); } return fn(err); } - fn(null); + + exec(`${bin} prune && ${bin} install --production`, { + cwd: path + }, (err, stdout, stderr) => { + if (err) return fn(err); + fn(null); + }); }); }