which
Advanced tools
Comparing version 2.0.0 to 2.0.1
# Changes | ||
## 2.0.1 | ||
* generate changelog and publish on version bump | ||
* enforce 100% test coverage | ||
* Promise interface | ||
## 2.0.0 | ||
@@ -5,0 +11,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Like which(1) unix command. Find the first instance of an executable in the PATH.", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"repository": { | ||
@@ -23,5 +23,10 @@ "type": "git", | ||
"scripts": { | ||
"test": "tap test/*.js --cov", | ||
"changelog": "bash gen-changelog.sh", | ||
"postversion": "npm run changelog && git add CHANGELOG.md && git commit -m 'update changelog - '${npm_package_version}" | ||
"test": "tap", | ||
"preversion": "npm test", | ||
"postversion": "npm publish", | ||
"prepublish": "npm run changelog", | ||
"prechangelog": "bash gen-changelog.sh", | ||
"changelog": "git add CHANGELOG.md", | ||
"postchangelog": "git commit -m 'update changelog - '${npm_package_version}", | ||
"postpublish": "git push origin --follow-tags" | ||
}, | ||
@@ -32,2 +37,5 @@ "files": [ | ||
], | ||
"tap": { | ||
"check-coverage": true | ||
}, | ||
"engines": { | ||
@@ -34,0 +42,0 @@ "node": ">= 8" |
@@ -20,2 +20,5 @@ # which | ||
// or promise | ||
which('node').then(resolvedPath => { ... }).catch(er => { ... not found ... }) | ||
// sync usage | ||
@@ -22,0 +25,0 @@ // throws if not found |
49
which.js
@@ -48,2 +48,4 @@ const isWindows = process.platform === 'win32' || | ||
} | ||
if (!opt) | ||
opt = {} | ||
@@ -53,9 +55,6 @@ const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt) | ||
const F = i => { | ||
if (i === pathEnv.length) { | ||
if (opt.all && found.length) | ||
return cb(null, found) | ||
else | ||
return cb(getNotFoundError(cmd)) | ||
} | ||
const step = i => new Promise((resolve, reject) => { | ||
if (i === pathEnv.length) | ||
return opt.all && found.length ? resolve(found) | ||
: reject(getNotFoundError(cmd)) | ||
@@ -69,19 +68,21 @@ const ppRaw = pathEnv[i] | ||
const E = (ii) => { | ||
if (ii === pathExt.length) | ||
return F(i + 1) | ||
const ext = pathExt[ii] | ||
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => { | ||
if (!er && is) { | ||
if (opt.all) | ||
found.push(p + ext) | ||
else | ||
return cb(null, p + ext) | ||
} | ||
return E(ii + 1, pathExt.length) | ||
}) | ||
} | ||
return E(0) | ||
} | ||
return F(0) | ||
resolve(subStep(p, i, 0)) | ||
}) | ||
const subStep = (p, i, ii) => new Promise((resolve, reject) => { | ||
if (ii === pathExt.length) | ||
return resolve(step(i + 1)) | ||
const ext = pathExt[ii] | ||
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => { | ||
if (!er && is) { | ||
if (opt.all) | ||
found.push(p + ext) | ||
else | ||
return resolve(p + ext) | ||
} | ||
return resolve(subStep(p, i, ii + 1)) | ||
}) | ||
}) | ||
return cb ? step(0).then(res => cb(null, res), cb) : step(0) | ||
} | ||
@@ -88,0 +89,0 @@ |
9901
55
102