diff options
Diffstat (limited to 'deps/npm/node_modules/which/which.js')
-rw-r--r-- | deps/npm/node_modules/which/which.js | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/deps/npm/node_modules/which/which.js b/deps/npm/node_modules/which/which.js index b124ead672f..634e3af6e90 100644 --- a/deps/npm/node_modules/which/which.js +++ b/deps/npm/node_modules/which/which.js @@ -4,6 +4,7 @@ which.sync = whichSync var path = require("path") , fs , COLON = process.platform === "win32" ? ";" : ":" + , isExe try { fs = require("graceful-fs") @@ -11,17 +12,21 @@ try { fs = require("fs") } -// console.log(process.execPath) -// console.log(process.argv) - -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 +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 which (cmd, cb) { if (cmd.charAt(0) === "/") return cb(null, cmd) var pathEnv = (process.env.PATH || "").split(COLON) @@ -56,12 +61,21 @@ function which (cmd, cb) { function whichSync (cmd) { if (cmd.charAt(0) === "/") return 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) } |