diff --git a/src/which.js b/src/which.js index fadb96c..2822ecf 100644 --- a/src/which.js +++ b/src/which.js @@ -15,6 +15,10 @@ function splitPath(p) { return p.split(':'); } +function checkPath(path) { + return fs.existsSync(path) && fs.statSync(path).isDirectory() == false; +} + //@ //@ ### which(command) //@ @@ -42,7 +46,7 @@ function _which(options, cmd) { return; // already found it var attempt = path.resolve(dir + '/' + cmd); - if (fs.existsSync(attempt)) { + if (checkPath(attempt)) { where = attempt; return; } @@ -50,17 +54,17 @@ function _which(options, cmd) { if (common.platform === 'win') { var baseAttempt = attempt; attempt = baseAttempt + '.exe'; - if (fs.existsSync(attempt)) { + if (checkPath(attempt)) { where = attempt; return; } attempt = baseAttempt + '.cmd'; - if (fs.existsSync(attempt)) { + if (checkPath(attempt)) { where = attempt; return; } attempt = baseAttempt + '.bat'; - if (fs.existsSync(attempt)) { + if (checkPath(attempt)) { where = attempt; return; } @@ -69,7 +73,7 @@ function _which(options, cmd) { } // Command not found anywhere? - if (!fs.existsSync(cmd) && !where) + if (!checkPath(cmd) && !where) return null; where = where || path.resolve(cmd);