mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-25 16:07:37 +00:00
Merge pull request #110 from panrafal/fix/which
which() should only find files, not directories
This commit is contained in:
commit
ab7bf59b4b
14
src/which.js
14
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user