Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorForrest L Norvell <forrest@npmjs.com>2015-05-15 02:43:29 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-05-15 02:43:29 +0300
commitb527a7c2ba3c4002f443dd2c536ff4ff41a38b86 (patch)
tree5ef18afa8413e840b702a061ca5dcdb10070646a /node_modules/which
parentd9244cfb6f7ec4ab2e5b6a9761ba7354aba3442a (diff)
which@1.1.1
* path can be passed in instead of using process.env.PATH * better support for mingw and cygwin * better docs * tests
Diffstat (limited to 'node_modules/which')
-rw-r--r--node_modules/which/README.md31
-rw-r--r--node_modules/which/node_modules/is-absolute/LICENSE21
-rw-r--r--node_modules/which/node_modules/is-absolute/README.md53
-rw-r--r--node_modules/which/node_modules/is-absolute/index.js27
-rw-r--r--node_modules/which/node_modules/is-absolute/node_modules/is-relative/LICENSE-MIT21
-rw-r--r--node_modules/which/node_modules/is-absolute/node_modules/is-relative/README.md38
-rw-r--r--node_modules/which/node_modules/is-absolute/node_modules/is-relative/index.js21
-rw-r--r--node_modules/which/node_modules/is-absolute/node_modules/is-relative/package.json76
-rw-r--r--node_modules/which/node_modules/is-absolute/package.json76
-rw-r--r--node_modules/which/package.json41
-rw-r--r--node_modules/which/test/basic.js84
-rw-r--r--node_modules/which/which.js148
12 files changed, 564 insertions, 73 deletions
diff --git a/node_modules/which/README.md b/node_modules/which/README.md
index ff1eb531a..d5571528a 100644
--- a/node_modules/which/README.md
+++ b/node_modules/which/README.md
@@ -1,5 +1,34 @@
-The "which" util from npm's guts.
+# which
+
+Like the unix `which` utility.
Finds the first instance of a specified executable in the PATH
environment variable. Does not cache the results, so `hash -r` is not
needed when the PATH changes.
+
+## USAGE
+
+```javascript
+var which = require('which')
+
+// async usage
+which('node', function (er, resolvedPath) {
+ // er is returned if no "node" is found on the PATH
+ // if it is found, then the absolute path to the exec is returned
+})
+
+// sync usage
+// throws if not found
+var resolved = which.sync('node')
+
+// Pass options to override the PATH and PATHEXT environment vars.
+which('node', { path: someOtherPath }, function (er, resolved) {
+ if (er)
+ throw er
+ console.log('found at %j', resolved)
+})
+```
+
+## OPTIONS
+
+If you pass in options, then `path` and `pathExt` are relevant.
diff --git a/node_modules/which/node_modules/is-absolute/LICENSE b/node_modules/which/node_modules/is-absolute/LICENSE
new file mode 100644
index 000000000..904ab073b
--- /dev/null
+++ b/node_modules/which/node_modules/is-absolute/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014-2015, Jon Schlinkert.Copyright (c) 2009-2015, TJ Holowaychuk.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/node_modules/which/node_modules/is-absolute/README.md b/node_modules/which/node_modules/is-absolute/README.md
new file mode 100644
index 000000000..768f4b833
--- /dev/null
+++ b/node_modules/which/node_modules/is-absolute/README.md
@@ -0,0 +1,53 @@
+# is-absolute [![NPM version](https://badge.fury.io/js/is-absolute.svg)](http://badge.fury.io/js/is-absolute) [![Build Status](https://travis-ci.org/jonschlinkert/is-absolute.svg)](https://travis-ci.org/jonschlinkert/is-absolute)
+
+> Return true if a file path is absolute.
+
+Based on the `isAbsolute` utility method in [express](https://github.com/visionmedia/express).
+
+## Install with [npm](npmjs.org)
+
+```bash
+npm i is-absolute --save
+```
+
+## Usage
+
+```js
+var isAbsolute = require('is-absolute');
+console.log(isAbsolute('a/b/c.js'));
+//=> 'false';
+```
+
+## Running tests
+Install dev dependencies.
+
+```bash
+npm i -d && npm test
+```
+
+
+## Contributing
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-absolute/issues)
+
+
+## Other projects
+* [is-relative](https://github.com/jonschlinkert/is-relative): Returns `true` if the path appears to be relative.
+* [is-dotfile](https://github.com/regexps/is-dotfile): Return true if a file path is (or has) a dotfile.
+* [is-glob](https://github.com/jonschlinkert/is-glob): Returns `true` if the given string looks like a glob pattern.
+* [cwd](https://github.com/jonschlinkert/cwd): Node.js util for easily getting the current working directory of a project based on package.json or the given path.
+* [git-config-path](https://github.com/jonschlinkert/git-config-path): Resolve the path to the user's global .gitconfig.
+
+## Author
+
+**Jon Schlinkert**
+
++ [github/jonschlinkert](https://github.com/jonschlinkert)
++ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+
+## License
+Copyright (c) 2014-2015 Jon Schlinkert
+Released under the MIT license
+
+***
+
+_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 05, 2015._
diff --git a/node_modules/which/node_modules/is-absolute/index.js b/node_modules/which/node_modules/is-absolute/index.js
new file mode 100644
index 000000000..e7a40dd73
--- /dev/null
+++ b/node_modules/which/node_modules/is-absolute/index.js
@@ -0,0 +1,27 @@
+/*!
+ * is-absolute <https://github.com/jonschlinkert/is-absolute>
+ *
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+var isRelative = require('is-relative');
+
+module.exports = function isAbsolute(filepath) {
+ if ('/' === filepath[0]) {
+ return true;
+ }
+ if (':' === filepath[1] && '\\' === filepath[2]) {
+ return true;
+ }
+ // Microsoft Azure absolute filepath
+ if ('\\\\' == filepath.substring(0, 2)) {
+ return true;
+ }
+ if (!isRelative(filepath)) {
+ return true;
+ }
+};
+
diff --git a/node_modules/which/node_modules/is-absolute/node_modules/is-relative/LICENSE-MIT b/node_modules/which/node_modules/is-absolute/node_modules/is-relative/LICENSE-MIT
new file mode 100644
index 000000000..b576e8d48
--- /dev/null
+++ b/node_modules/which/node_modules/is-absolute/node_modules/is-relative/LICENSE-MIT
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Jon Schlinkert
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/node_modules/which/node_modules/is-absolute/node_modules/is-relative/README.md b/node_modules/which/node_modules/is-absolute/node_modules/is-relative/README.md
new file mode 100644
index 000000000..760be8d06
--- /dev/null
+++ b/node_modules/which/node_modules/is-absolute/node_modules/is-relative/README.md
@@ -0,0 +1,38 @@
+# is-relative [![NPM version](https://badge.fury.io/js/is-relative.svg)](http://badge.fury.io/js/is-relative)
+
+> Returns `true` if the path appears to be relative.
+
+## Install
+### Install with [npm](npmjs.org)
+
+```bash
+npm i is-relative --save
+```
+
+## Usage
+### [isRelative](index.js#L16)
+
+* `filepath` **{String}**: Path to test.
+* `returns`: {Boolean}
+
+```js
+var isRelative = require('is-relative');
+isRelative('README.md');
+//=> true
+```
+
+
+## Author
+
+**Jon Schlinkert**
+
++ [github/jonschlinkert](https://github.com/jonschlinkert)
++ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+
+## License
+Copyright (c) 2014 Jon Schlinkert
+Released under the MIT license
+
+***
+
+_This file was generated by [verb](https://github.com/assemble/verb) on November 17, 2014._ \ No newline at end of file
diff --git a/node_modules/which/node_modules/is-absolute/node_modules/is-relative/index.js b/node_modules/which/node_modules/is-absolute/node_modules/is-relative/index.js
new file mode 100644
index 000000000..ffc760a82
--- /dev/null
+++ b/node_modules/which/node_modules/is-absolute/node_modules/is-relative/index.js
@@ -0,0 +1,21 @@
+'use strict';
+
+/**
+ * ```js
+ * var isRelative = require('is-relative');
+ * isRelative('README.md');
+ * //=> true
+ * ```
+ *
+ * @name isRelative
+ * @param {String} `filepath` Path to test.
+ * @return {Boolean}
+ * @api public
+ */
+
+module.exports = function isRelative(filepath) {
+ if (typeof filepath !== 'string') {
+ throw new Error('isRelative expects a string.');
+ }
+ return !/^([a-z]+:)?[\\\/]/i.test(filepath);
+}; \ No newline at end of file
diff --git a/node_modules/which/node_modules/is-absolute/node_modules/is-relative/package.json b/node_modules/which/node_modules/is-absolute/node_modules/is-relative/package.json
new file mode 100644
index 000000000..d582081dd
--- /dev/null
+++ b/node_modules/which/node_modules/is-absolute/node_modules/is-relative/package.json
@@ -0,0 +1,76 @@
+{
+ "name": "is-relative",
+ "description": "Returns `true` if the path appears to be relative.",
+ "version": "0.1.3",
+ "homepage": "https://github.com/jonschlinkert/is-relative",
+ "author": {
+ "name": "Jon Schlinkert",
+ "url": "https://github.com/jonschlinkert"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jonschlinkert/is-relative.git"
+ },
+ "bugs": {
+ "url": "https://github.com/jonschlinkert/is-relative/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/jonschlinkert/is-relative/blob/master/LICENSE-MIT"
+ }
+ ],
+ "keywords": [
+ "absolute",
+ "check",
+ "file",
+ "filepath",
+ "is",
+ "normalize",
+ "path",
+ "path.relative",
+ "relative",
+ "resolve",
+ "slash",
+ "slashes",
+ "uri",
+ "url"
+ ],
+ "main": "index.js",
+ "files": [
+ "index.js",
+ "LICENSE-MIT"
+ ],
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "mocha -R spec"
+ },
+ "devDependencies": {
+ "mocha": "*",
+ "verb": ">= 0.2.6",
+ "verb-tag-jscomments": "^0.1.4"
+ },
+ "_id": "is-relative@0.1.3",
+ "_shasum": "905fee8ae86f45b3ec614bc3c15c869df0876e82",
+ "_from": "is-relative@>=0.1.0 <0.2.0",
+ "_npmVersion": "1.4.9",
+ "_npmUser": {
+ "name": "jonschlinkert",
+ "email": "github@sellside.com"
+ },
+ "maintainers": [
+ {
+ "name": "jonschlinkert",
+ "email": "github@sellside.com"
+ }
+ ],
+ "dist": {
+ "shasum": "905fee8ae86f45b3ec614bc3c15c869df0876e82",
+ "tarball": "http://registry.npmjs.org/is-relative/-/is-relative-0.1.3.tgz"
+ },
+ "directories": {},
+ "_resolved": "https://registry.npmjs.org/is-relative/-/is-relative-0.1.3.tgz",
+ "readme": "ERROR: No README data found!"
+}
diff --git a/node_modules/which/node_modules/is-absolute/package.json b/node_modules/which/node_modules/is-absolute/package.json
new file mode 100644
index 000000000..4f954b855
--- /dev/null
+++ b/node_modules/which/node_modules/is-absolute/package.json
@@ -0,0 +1,76 @@
+{
+ "name": "is-absolute",
+ "description": "Return true if a file path is absolute.",
+ "version": "0.1.7",
+ "homepage": "https://github.com/jonschlinkert/is-absolute",
+ "author": {
+ "name": "Jon Schlinkert",
+ "url": "https://github.com/jonschlinkert"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jonschlinkert/is-absolute.git"
+ },
+ "bugs": {
+ "url": "https://github.com/jonschlinkert/is-absolute/issues"
+ },
+ "license": {
+ "type": "MIT",
+ "url": "https://github.com/jonschlinkert/is-absolute/blob/master/LICENSE"
+ },
+ "files": [
+ "index.js"
+ ],
+ "main": "index.js",
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "mocha"
+ },
+ "dependencies": {
+ "is-relative": "^0.1.0"
+ },
+ "devDependencies": {
+ "mocha": "*"
+ },
+ "keywords": [
+ "absolute",
+ "check",
+ "file",
+ "filepath",
+ "is",
+ "normalize",
+ "path",
+ "path.relative",
+ "relative",
+ "resolve",
+ "slash",
+ "slashes",
+ "uri",
+ "url"
+ ],
+ "gitHead": "90cca7b671620bf28b778a61fddc8a986a2e1095",
+ "_id": "is-absolute@0.1.7",
+ "_shasum": "847491119fccb5fb436217cc737f7faad50f603f",
+ "_from": "is-absolute@>=0.1.7 <0.2.0",
+ "_npmVersion": "2.5.1",
+ "_nodeVersion": "0.12.0",
+ "_npmUser": {
+ "name": "jonschlinkert",
+ "email": "github@sellside.com"
+ },
+ "maintainers": [
+ {
+ "name": "jonschlinkert",
+ "email": "github@sellside.com"
+ }
+ ],
+ "dist": {
+ "shasum": "847491119fccb5fb436217cc737f7faad50f603f",
+ "tarball": "http://registry.npmjs.org/is-absolute/-/is-absolute-0.1.7.tgz"
+ },
+ "directories": {},
+ "_resolved": "https://registry.npmjs.org/is-absolute/-/is-absolute-0.1.7.tgz",
+ "readme": "ERROR: No README data found!"
+}
diff --git a/node_modules/which/package.json b/node_modules/which/package.json
index d2b7b166f..8cffb7986 100644
--- a/node_modules/which/package.json
+++ b/node_modules/which/package.json
@@ -6,7 +6,7 @@
},
"name": "which",
"description": "Like which(1) unix command. Find the first instance of an executable in the PATH.",
- "version": "1.0.9",
+ "version": "1.1.1",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/node-which.git"
@@ -16,20 +16,34 @@
"which": "./bin/which"
},
"license": "ISC",
- "gitHead": "df3d52a0ecd5f366d550e0f14d67ca4d5e621bad",
+ "dependencies": {
+ "is-absolute": "^0.1.7"
+ },
+ "devDependencies": {
+ "mkdirp": "^0.5.0",
+ "rimraf": "^2.3.3",
+ "tap": "^1.0.2"
+ },
+ "scripts": {
+ "test": "tap test/*.js"
+ },
+ "gitHead": "c80a08e9f8cf7a5c0f39c2e2f87f18f153b118a8",
"bugs": {
"url": "https://github.com/isaacs/node-which/issues"
},
- "homepage": "https://github.com/isaacs/node-which",
- "_id": "which@1.0.9",
- "scripts": {},
- "_shasum": "460c1da0f810103d0321a9b633af9e575e64486f",
- "_from": "which@>=1.0.9 <1.1.0",
- "_npmVersion": "2.6.0",
- "_nodeVersion": "1.1.0",
+ "homepage": "https://github.com/isaacs/node-which#readme",
+ "_id": "which@1.1.1",
+ "_shasum": "9ce512459946166e12c083f08ec073380fc8cbbb",
+ "_from": "which@>=1.1.1 <1.2.0",
+ "_npmVersion": "2.9.1",
+ "_nodeVersion": "2.0.1",
"_npmUser": {
"name": "isaacs",
- "email": "i@izs.me"
+ "email": "isaacs@npmjs.com"
+ },
+ "dist": {
+ "shasum": "9ce512459946166e12c083f08ec073380fc8cbbb",
+ "tarball": "http://registry.npmjs.org/which/-/which-1.1.1.tgz"
},
"maintainers": [
{
@@ -37,11 +51,6 @@
"email": "i@izs.me"
}
],
- "dist": {
- "shasum": "460c1da0f810103d0321a9b633af9e575e64486f",
- "tarball": "http://registry.npmjs.org/which/-/which-1.0.9.tgz"
- },
"directories": {},
- "_resolved": "https://registry.npmjs.org/which/-/which-1.0.9.tgz",
- "readme": "ERROR: No README data found!"
+ "_resolved": "https://registry.npmjs.org/which/-/which-1.1.1.tgz"
}
diff --git a/node_modules/which/test/basic.js b/node_modules/which/test/basic.js
new file mode 100644
index 000000000..189ca6d0a
--- /dev/null
+++ b/node_modules/which/test/basic.js
@@ -0,0 +1,84 @@
+var t = require('tap')
+var fs = require('fs')
+var rimraf = require('rimraf')
+var mkdirp = require('mkdirp')
+var fixture = __dirname + '/fixture'
+var which = require('../which.js')
+var path = require('path')
+
+var isWindows = process.platform === 'win32' ||
+ process.env.OSTYPE === 'cygwin' ||
+ process.env.OSTYPE === 'msys'
+
+var skip = { skip: isWindows ? 'not relevant on windows' : false }
+
+t.test('setup', function (t) {
+ rimraf.sync(fixture)
+ mkdirp.sync(fixture)
+ fs.writeFileSync(fixture + '/foo.sh', 'echo foo\n')
+ t.end()
+})
+
+t.test('does not find non-executable', skip, function (t) {
+ t.plan(2)
+
+ t.test('absolute', function (t) {
+ t.plan(2)
+ which(fixture + '/foo.sh', function (er) {
+ t.isa(er, Error)
+ })
+
+ t.throws(function () {
+ which.sync(fixture + '/foo.sh')
+ })
+ })
+
+ t.test('with path', function (t) {
+ t.plan(2)
+ which('foo.sh', { path: fixture }, function (er) {
+ t.isa(er, Error)
+ })
+
+ t.throws(function () {
+ which.sync('foo.sh', { path: fixture })
+ })
+ })
+})
+
+t.test('make executable', function (t) {
+ fs.chmodSync(fixture + '/foo.sh', '0755')
+ t.end()
+})
+
+t.test('find when executable', function (t) {
+ t.plan(2)
+ var opt = { pathExt: '.sh' }
+ var expect = path.resolve(fixture, 'foo.sh').toLowerCase()
+
+ t.test('absolute', function (t) {
+ t.plan(2)
+ runTest(t)
+ })
+
+ function runTest(t) {
+ which(fixture + '/foo.sh', opt, function (er, found) {
+ if (er)
+ throw er
+ t.equal(found.toLowerCase(), expect)
+ })
+
+ var found = which.sync(fixture + '/foo.sh', opt).toLowerCase()
+ t.equal(found, expect)
+ }
+
+ t.test('with path', function (t) {
+ t.plan(2)
+ opt.path = fixture
+ runTest(t)
+ })
+})
+
+t.test('clean', function (t) {
+ rimraf.sync(fixture)
+ t.end()
+})
diff --git a/node_modules/which/which.js b/node_modules/which/which.js
index 2a45417da..13fc26dcf 100644
--- a/node_modules/which/which.js
+++ b/node_modules/which/which.js
@@ -1,54 +1,83 @@
module.exports = which
which.sync = whichSync
-var path = require("path")
- , fs
- , COLON = process.platform === "win32" ? ";" : ":"
- , isExe
- , fs = require("fs")
+var isWindows = process.platform === 'win32' ||
+ process.env.OSTYPE === 'cygwin' ||
+ process.env.OSTYPE === 'msys'
-if (process.platform == "win32") {
+var path = require('path')
+var COLON = isWindows ? ';' : ':'
+var isExe
+var fs = require('fs')
+var isAbsolute = require('is-absolute')
+
+if (isWindows) {
// 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 & 0010) && process.getuid && 0 === process.getuid()
|| (mod & 0100) && process.getuid && uid === process.getuid()
- || (mod & 0100) && process.getuid && 0 === process.getuid()
- //console.error("isExe?", ret)
+ || (mod & 0110) && process.getuid && 0 === process.getuid()
+
+ if (process.getgroups && (mod & 0010)) {
+ var groups = process.getgroups()
+ for (var g = 0; g < groups.length; g++) {
+ if (groups[g] === gid)
+ return true
+ }
+ }
+
return ret
}
}
+function which (cmd, opt, cb) {
+ if (typeof opt === 'function') {
+ cb = opt
+ opt = {}
+ }
+ var colon = opt.colon || COLON
+ var pathEnv = opt.path || process.env.PATH || ''
+ var pathExt = ['']
-function which (cmd, cb) {
- 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("")
+ // 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
+ }
+ }
}
- //console.error("pathEnv", pathEnv)
+
+ 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 = ['']
+
;(function F (i, l) {
- if (i === l) return cb(new Error("not found: "+cmd))
+ if (i === l) return cb(new Error('not found: '+cmd))
var p = path.resolve(pathEnv[i], cmd)
;(function E (ii, ll) {
if (ii === ll) return F(i + 1, l)
var ext = pathExt[ii]
- //console.error(p + ext)
fs.stat(p + ext, function (er, stat) {
if (!er &&
- stat &&
stat.isFile() &&
isExe(stat.mode, stat.uid, stat.gid)) {
- //console.error("yes, exe!", p + ext)
return cb(null, p + ext)
}
return E(ii + 1, ll)
@@ -57,45 +86,52 @@ function which (cmd, cb) {
})(0, pathEnv.length)
}
-function whichSync (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("")
+function whichSync (cmd, opt) {
+ if (!opt)
+ opt = {}
+
+ var colon = opt.colon || COLON
+
+ 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 ++) {
var p = path.join(pathEnv[i], cmd)
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
+ try {
+ stat = fs.statSync(cur)
+ if (stat.isFile() && isExe(stat.mode, stat.uid, stat.gid))
+ return cur
+ } catch (ex) {}
}
}
- 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 === ""
+ throw new Error('not found: '+cmd)
}