Permalink
Browse files

Abstract out 'which'

  • Loading branch information...
1 parent 1192141 commit 6d7a8aabe31d4a828cd8490501ef89d49e17b117 @isaacs isaacs committed Aug 7, 2011
Showing with 9 additions and 46 deletions.
  1. +3 −0 .gitmodules
  2. +0 −43 lib/utils/which.js
  3. +1 −0 node_modules/which
  4. +1 −1 npm.js
  5. +4 −2 package.json
View
@@ -28,3 +28,6 @@
[submodule "node_modules/ini"]
path = node_modules/ini
url = https://github.com/isaacs/ini.git
+[submodule "node_modules/which"]
+ path = node_modules/which
+ url = https://github.com/isaacs/node-which.git
View
@@ -1,43 +0,0 @@
-module.exports = which
-which.sync = whichSync
-
-var path = require("path")
- , fs = require("graceful-fs")
-
-// console.log(process.execPath)
-// console.log(process.argv)
-
-function isExe (mod, uid, gid) {
- return (mod & 0001)
- || (mod & 0010) && gid === process.getgid()
- || (mod & 0100) && uid === process.getuid()
-}
-function which (cmd, cb) {
- if (cmd.charAt(0) === "/") return cb(null, cmd)
- var pathEnv = (process.env.PATH || "").split(":")
- ;(function F (i, l) {
- if (i === l) return cb(new Error("not found: "+cmd))
- var p = path.join(pathEnv[i], cmd)
- if (p === process.execPath) return cb(null, p)
- fs.stat(p, function (er, stat) {
- if (!er && stat && isExe(stat.mode, stat.uid, stat.gid)) {
- return cb(null, p)
- }
- return F(i+1, l)
- })
- })(0, pathEnv.length)
-}
-
-
-function whichSync (cmd) {
- if (cmd.charAt(0) === "/") return cmd
- var pathEnv = (process.env.PATH || "").split(":")
- 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
- }
- throw new Error("not found: "+cmd)
-}
Submodule which added at 3a6bbd
View
2 npm.js
@@ -19,7 +19,7 @@ var EventEmitter = require("events").EventEmitter
, fs = require("graceful-fs")
, path = require("path")
, abbrev = require("abbrev")
- , which = require("./lib/utils/which")
+ , which = require("which")
, semver = require("semver")
, findPrefix = require("./lib/utils/find-prefix")
, getUid = require("./lib/utils/uid-number")
View
@@ -33,7 +33,8 @@
, "nopt" : "1"
, "node-uuid" : "1.2"
, "proto-list": "1"
- , "rimraf" : "1" }
+ , "rimraf" : "1"
+ , "which" : "1" }
, "bundleDependencies" :
[ "slide"
, "ini"
@@ -44,7 +45,8 @@
, "nopt"
, "node-uuid"
, "rimraf"
- , "proto-list" ]
+ , "proto-list"
+ , "which" ]
, "devDependencies" : { "ronn" : "" }
, "engines" : { "node" : "0.4 || 0.5", "npm" : "1" }
, "scripts" : { "test" : "./test/run.sh"

0 comments on commit 6d7a8aa

Please sign in to comment.