Comparing version 1.1.1 to 1.1.2
@@ -5,3 +5,3 @@ { | ||
"description": "Like which(1) unix command. Find the first instance of an executable in the PATH.", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -54,27 +54,42 @@ var t = require('tap') | ||
t.test('find when executable', function (t) { | ||
t.plan(2) | ||
t.plan(4) | ||
var opt = { pathExt: '.sh' } | ||
var expect = path.resolve(fixture, 'foo.sh').toLowerCase() | ||
var PATH = process.env.PATH | ||
t.test('absolute', function (t) { | ||
t.plan(2) | ||
runTest(t) | ||
runTest(fixture + '/foo.sh', t) | ||
}) | ||
function runTest(t) { | ||
which(fixture + '/foo.sh', opt, function (er, found) { | ||
t.test('with process.env.PATH', function (t) { | ||
process.env.PATH = fixture | ||
runTest('foo.sh', t) | ||
}) | ||
t.test('with process.env.Path', { | ||
skip: isWindows ? false : 'Only for Windows' | ||
}, function (t) { | ||
process.env.PATH = "" | ||
process.env.Path = fixture | ||
runTest('foo.sh', t) | ||
}) | ||
t.test('with path opt', function (t) { | ||
opt.path = fixture | ||
runTest('foo.sh', t) | ||
}) | ||
function runTest(exec, t) { | ||
t.plan(2) | ||
which(exec, opt, function (er, found) { | ||
if (er) | ||
throw er | ||
t.equal(found.toLowerCase(), expect) | ||
process.env.PATH = PATH | ||
}) | ||
var found = which.sync(fixture + '/foo.sh', opt).toLowerCase() | ||
var found = which.sync(exec, opt).toLowerCase() | ||
t.equal(found, expect) | ||
} | ||
t.test('with path', function (t) { | ||
t.plan(2) | ||
opt.path = fixture | ||
runTest(t) | ||
}) | ||
}) | ||
@@ -81,0 +96,0 @@ |
80
which.js
@@ -14,2 +14,6 @@ module.exports = which | ||
var G = parseInt('0010', 8) | ||
var U = parseInt('0100', 8) | ||
var UG = parseInt('0110', 8) | ||
if (isWindows) { | ||
@@ -20,8 +24,8 @@ // On windows, there is no good way to check that a file is executable | ||
isExe = function isExe (mod, uid, gid) { | ||
var ret = (mod & 0001) | ||
|| (mod & 0010) && process.getgid && gid === process.getgid() | ||
|| (mod & 0100) && process.getuid && uid === process.getuid() | ||
|| (mod & 0110) && process.getuid && 0 === process.getuid() | ||
var ret = (mod & 1) | ||
|| (mod & U) && process.getgid && gid === process.getgid() | ||
|| (mod & G) && process.getuid && uid === process.getuid() | ||
|| (mod & UG) && process.getuid && 0 === process.getuid() | ||
if (process.getgroups && (mod & 0010)) { | ||
if (!ret && process.getgroups && (mod & G)) { | ||
var groups = process.getgroups() | ||
@@ -38,8 +42,3 @@ for (var g = 0; g < groups.length; g++) { | ||
function which (cmd, opt, cb) { | ||
if (typeof opt === 'function') { | ||
cb = opt | ||
opt = {} | ||
} | ||
function getPathInfo(cmd, opt) { | ||
var colon = opt.colon || COLON | ||
@@ -49,13 +48,2 @@ var pathEnv = opt.path || process.env.PATH || '' | ||
// On windows, env.Path is common. | ||
if (isWindows && !pathEnv) { | ||
var k = Object.keys(process.env) | ||
for (var p = 0; p < k.length; p++) { | ||
if (p.toLowerCase() === 'path') { | ||
pathEnv = process.env[p] | ||
break | ||
} | ||
} | ||
} | ||
pathEnv = pathEnv.split(colon) | ||
@@ -75,2 +63,15 @@ | ||
return {env: pathEnv, ext: pathExt} | ||
} | ||
function which (cmd, opt, cb) { | ||
if (typeof opt === 'function') { | ||
cb = opt | ||
opt = {} | ||
} | ||
var info = getPathInfo(cmd, opt) | ||
var pathEnv = info.env | ||
var pathExt = info.ext | ||
;(function F (i, l) { | ||
@@ -95,35 +96,8 @@ if (i === l) return cb(new Error('not found: '+cmd)) | ||
function whichSync (cmd, opt) { | ||
if (!opt) | ||
opt = {} | ||
opt = opt || {} | ||
var colon = opt.colon || COLON | ||
var info = getPathInfo(cmd, opt) | ||
var pathEnv = info.env | ||
var pathExt = info.ext | ||
var pathEnv = opt.path || process.env.PATH || '' | ||
var pathExt = [''] | ||
// On windows, env.Path is common. | ||
if (isWindows && !pathEnv) { | ||
var k = Object.keys(process.env) | ||
for (var p = 0; p < k.length; p++) { | ||
if (p.toLowerCase() === 'path') { | ||
pathEnv = process.env[p] | ||
break | ||
} | ||
} | ||
} | ||
pathEnv = pathEnv.split(colon) | ||
if (isWindows) { | ||
pathEnv.unshift(process.cwd()) | ||
pathExt = (opt.pathExt || process.env.PATHEXT || '.EXE').split(colon) | ||
if (cmd.indexOf('.') !== -1 && pathExt[0] !== '') | ||
pathExt.unshift('') | ||
} | ||
// If it's absolute, then we don't bother searching the pathenv. | ||
// just check the file itself, and that's it. | ||
if (isAbsolute(cmd)) | ||
pathEnv = [''] | ||
for (var i = 0, l = pathEnv.length; i < l; i ++) { | ||
@@ -130,0 +104,0 @@ var p = path.join(pathEnv[i], cmd) |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
7
13
7533
174