Comparing version 1.0.2 to 1.0.3
@@ -5,3 +5,3 @@ { | ||
"description": "Like which(1) unix command. Find the first instance of an executable in the PATH.", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
42
which.js
@@ -7,2 +7,3 @@ module.exports = which | ||
, COLON = process.platform === "win32" ? ";" : ":" | ||
, isExe | ||
@@ -15,13 +16,17 @@ try { | ||
// console.log(process.execPath) | ||
// console.log(process.argv) | ||
if (process.platform == "win32") { | ||
// 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) { | ||
//console.error(mod, uid, gid); | ||
//console.error("isExe?", (mod & 0111).toString(8)) | ||
var ret = (mod & 0001) | ||
|| (mod & 0010) && process.getgid && gid === process.getgid() | ||
|| (mod & 0100) && process.getuid && uid === process.getuid() | ||
//console.error("isExe?", ret) | ||
return ret | ||
} | ||
} | ||
function isExe (mod, uid, gid) { | ||
//console.error("isExe?", (mod & 0111).toString(8)) | ||
var ret = (mod & 0001) | ||
|| (mod & 0010) && process.getgid && gid === process.getgid() | ||
|| (mod & 0100) && process.getuid && uid === process.getuid() | ||
//console.error("isExe?", ret) | ||
return ret | ||
} | ||
function which (cmd, cb) { | ||
@@ -61,10 +66,19 @@ if (cmd.charAt(0) === "/") return cb(null, cmd) | ||
var pathEnv = (process.env.PATH || "").split(COLON) | ||
, pathExt = [""] | ||
if (process.platform === "win32") { | ||
pathEnv.push(process.cwd()) | ||
pathExt = (process.env.PATHEXT || ".EXE").split(COLON) | ||
} | ||
for (var i = 0, l = pathEnv.length; i < l; i ++) { | ||
var p = path.join(pathEnv[i], cmd) | ||
if (p === process.execPath) return p | ||
var stat | ||
try { stat = fs.statSync(p) } catch (ex) {} | ||
if (stat && isExe(stat.mode, stat.uid, stat.gid)) return p | ||
for (var j = 0, ll = pathExt.length; j < ll; j ++) { | ||
var cur = p + pathExt[j] | ||
var stat | ||
try { stat = fs.statSync(cur) } catch (ex) {} | ||
if (stat && | ||
stat.isFile() && | ||
isExe(stat.mode, stat.uid, stat.gid)) return cur | ||
} | ||
} | ||
throw new Error("not found: "+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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
4353
5
0
75
0
5
1