From 16c0c4dcdc290e08a54bb3412c585a0e07be45a4 Mon Sep 17 00:00:00 2001 From: Rafal Lindemann Date: Wed, 5 Mar 2014 23:16:58 +0100 Subject: [PATCH] which should only find files, not directories --- src/which.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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);