Comparing version 1.2.1 to 1.2.4
@@ -5,3 +5,3 @@ { | ||
"description": "Like which(1) unix command. Find the first instance of an executable in the PATH.", | ||
"version": "1.2.1", | ||
"version": "1.2.4", | ||
"repository": { | ||
@@ -15,3 +15,4 @@ "type": "git", | ||
"dependencies": { | ||
"is-absolute": "^0.1.7" | ||
"is-absolute": "^0.1.7", | ||
"isexe": "^1.1.1" | ||
}, | ||
@@ -21,7 +22,7 @@ "devDependencies": { | ||
"rimraf": "^2.3.3", | ||
"tap": "^2.0.0" | ||
"tap": "^5.1.1" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
"test": "tap test/*.js --cov" | ||
} | ||
} |
@@ -54,6 +54,5 @@ var t = require('tap') | ||
t.test('find when executable', function (t) { | ||
t.plan(4) | ||
var opt = { pathExt: '.sh' } | ||
var expect = path.resolve(fixture, 'foo.sh').toLowerCase() | ||
var PATH = process.env.PATH | ||
var PATH = process.env.PATH || process.env.Path | ||
@@ -65,3 +64,3 @@ t.test('absolute', function (t) { | ||
t.test('with process.env.PATH', function (t) { | ||
process.env.PATH = fixture | ||
process.env.PATH = process.env.Path = fixture | ||
runTest('foo.sh', t) | ||
@@ -78,2 +77,21 @@ }) | ||
t.test('with pathExt', { | ||
skip: isWindows ? false : 'Only for Windows' | ||
}, function (t) { | ||
var pe = process.env.PATHEXT | ||
process.env.PATHEXT = '.SH' | ||
t.test('foo.sh', function (t) { | ||
runTest('foo.sh', t) | ||
}) | ||
t.test('foo', function (t) { | ||
runTest('foo', t) | ||
}) | ||
t.test('replace', function (t) { | ||
process.env.PATHEXT = pe | ||
t.end() | ||
}) | ||
t.end() | ||
}) | ||
t.test('with path opt', function (t) { | ||
@@ -86,2 +104,6 @@ opt.path = fixture | ||
t.plan(2) | ||
var found = which.sync(exec, opt).toLowerCase() | ||
t.equal(found, expect) | ||
which(exec, opt, function (er, found) { | ||
@@ -91,9 +113,8 @@ if (er) | ||
t.equal(found.toLowerCase(), expect) | ||
t.end() | ||
process.env.PATH = PATH | ||
}) | ||
var found = which.sync(exec, opt).toLowerCase() | ||
t.equal(found, expect) | ||
} | ||
t.end() | ||
}) | ||
@@ -100,0 +121,0 @@ |
58
which.js
@@ -10,35 +10,9 @@ module.exports = which | ||
var COLON = isWindows ? ';' : ':' | ||
var isExe | ||
var isexe = require('isexe') | ||
var fs = require('fs') | ||
var isAbsolute = require('is-absolute') | ||
var G = parseInt('0010', 8) | ||
var U = parseInt('0100', 8) | ||
var UG = parseInt('0110', 8) | ||
if (isWindows) { | ||
// On windows, there is no good way to check that a file is executable | ||
isExe = function isExe () { return true } | ||
} else { | ||
isExe = function isExe (mod, uid, gid) { | ||
var ret = (mod & 1) | ||
|| (mod & G) && process.getgid && gid === process.getgid() | ||
|| (mod & U) && process.getuid && uid === process.getuid() | ||
|| (mod & UG) && process.getuid && 0 === process.getuid() | ||
if (!ret && process.getgroups && (mod & G)) { | ||
var groups = process.getgroups() | ||
for (var g = 0; g < groups.length; g++) { | ||
if (groups[g] === gid) | ||
return true | ||
} | ||
} | ||
return ret | ||
} | ||
} | ||
function getPathInfo(cmd, opt) { | ||
var colon = opt.colon || COLON | ||
var pathEnv = opt.path || process.env.PATH || '' | ||
var pathEnv = opt.path || process.env.Path || process.env.PATH || '' | ||
var pathExt = [''] | ||
@@ -48,5 +22,11 @@ | ||
var pathExtExe = '' | ||
if (isWindows) { | ||
pathEnv.unshift(process.cwd()) | ||
pathExt = (opt.pathExt || process.env.PATHEXT || '.EXE').split(colon) | ||
pathExtExe = (opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM') | ||
pathExt = pathExtExe.split(colon) | ||
// Always test the cmd itself first. isexe will check to make sure | ||
// it's found in the pathExt set. | ||
if (cmd.indexOf('.') !== -1 && pathExt[0] !== '') | ||
@@ -61,3 +41,7 @@ pathExt.unshift('') | ||
return {env: pathEnv, ext: pathExt} | ||
return { | ||
env: pathEnv, | ||
ext: pathExt, | ||
extExe: pathExtExe | ||
} | ||
} | ||
@@ -74,2 +58,3 @@ | ||
var pathExt = info.ext | ||
var pathExtExe = info.extExe | ||
var found = [] | ||
@@ -93,6 +78,4 @@ | ||
var ext = pathExt[ii] | ||
fs.stat(p + ext, function (er, stat) { | ||
if (!er && | ||
stat.isFile() && | ||
isExe(stat.mode, stat.uid, stat.gid)) { | ||
isexe(p + ext, { pathExt: pathExtExe }, function (er, is) { | ||
if (!er && is) { | ||
if (opt.all) | ||
@@ -115,2 +98,3 @@ found.push(p + ext) | ||
var pathExt = info.ext | ||
var pathExtExe = info.extExe | ||
var found = [] | ||
@@ -126,6 +110,6 @@ | ||
var cur = p + pathExt[j] | ||
var stat | ||
var is | ||
try { | ||
stat = fs.statSync(cur) | ||
if (stat.isFile() && isExe(stat.mode, stat.uid, stat.gid)) { | ||
is = isexe.sync(cur, { pathExt: pathExtExe }) | ||
if (is) { | ||
if (opt.all) | ||
@@ -132,0 +116,0 @@ found.push(cur) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12397
10
318
2
25
+ Addedisexe@^1.1.1
+ Addedisexe@1.1.2(transitive)