diff --git a/node_modules/which/package.json b/node_modules/which/package.json index ea26853..b8d0dfa 100644 --- a/node_modules/which/package.json +++ b/node_modules/which/package.json @@ -2,7 +2,7 @@ "author": "Isaac Z. Schlueter (http://blog.izs.me)", "name": "which", "description": "Like which(1) unix command. Find the first instance of an executable in the PATH.", - "version": "1.0.3", + "version": "1.0.5", "repository": { "type": "git", "url": "git://github.com/isaacs/node-which.git" diff --git a/node_modules/which/which.js b/node_modules/which/which.js index 634e3af..db7e8f7 100644 --- a/node_modules/which/which.js +++ b/node_modules/which/which.js @@ -27,13 +27,16 @@ if (process.platform == "win32") { } } + + function which (cmd, cb) { - if (cmd.charAt(0) === "/") return cb(null, cmd) + if (isAbsolute(cmd)) 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) + if (cmd.indexOf(".") !== -1) pathExt.unshift("") } //console.error("pathEnv", pathEnv) ;(function F (i, l) { @@ -57,14 +60,14 @@ function which (cmd, cb) { })(0, pathEnv.length) } - function whichSync (cmd) { - if (cmd.charAt(0) === "/") return cmd + if (isAbsolute(cmd)) 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) + if (cmd.indexOf(".") !== -1) pathExt.unshift("") } for (var i = 0, l = pathEnv.length; i < l; i ++) { var p = path.join(pathEnv[i], cmd) @@ -79,3 +82,23 @@ function whichSync (cmd) { } throw new Error("not found: "+cmd) } + +var isAbsolute = process.platform === "win32" ? absWin : absUnix + +function absWin (p) { + if (absUnix(p)) return true + // pull off the device/UNC bit from a windows path. + // from node's lib/path.js + var splitDeviceRe = + /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?([\\\/])?/ + , result = splitDeviceRe.exec(p) + , device = result[1] || '' + , isUnc = device && device.charAt(1) !== ':' + , isAbsolute = !!result[2] || isUnc // UNC paths are always absolute + + return isAbsolute +} + +function absUnix (p) { + return p.charAt(0) === "/" || p === "" +}