npm / node-which

Like which(1) unix command. Find the first instance of an executable in the PATH.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returns a directory if it is in path and executable bit is set

ptierno opened this issue · comments

I ran into an issue where i had a directory in my path which contained a subdirectory. While using which to find an actual executable, it returned the path to the directory instead since it was first in the path:

➜  which ls -l
total 0
drwxr-xr-x  2 ptierno  staff  68 Aug 25 19:02 directory
➜  which export PATH=`pwd`:$PATH
➜  which node
> var which = require('which');
undefined
>
> which.sync('directory')
'/Users/ptierno/which/directory'                                                                                                                                                    

If I remove the executable bit from the directory then the directory doesnt get returned (which is what I would expect).

➜  which chmod -x directory
➜  which node
> var which = require('which');
undefined
> which.sync('directory')
Error: not found: directory
    at getNotFoundError (/Users/ptierno/node_modules/which/which.js:14:12)
    at Function.whichSync [as sync] (/Users/ptierno/node_modules/which/which.js:132:9)
    at repl:1:7
    at REPLServer.defaultEval (repl.js:272:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:441:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:188:7)
    at REPLServer.Interface._onLine (readline.js:224:10)
>

Might be a good idea to do a check to ensure the value being returned is an actual executable file and not a directory.

Updating isexe made which's tests break on Windows, so this isn't quite finished or ready to ship yet. I'll try to investigate this soon.

Fixed. Not sure how or if the tests ever passed on Windows, without d24dc05.