bin-version-check
Advanced tools
Comparing version 2.1.0 to 3.0.0
30
index.js
'use strict'; | ||
var semver = require('semver'); | ||
var binVersion = require('bin-version'); | ||
var semverTruncate = require('semver-truncate'); | ||
const semver = require('semver'); | ||
const binVersion = require('bin-version'); | ||
const semverTruncate = require('semver-truncate'); | ||
module.exports = function (bin, versionRange, cb) { | ||
if (typeof bin !== 'string' || typeof versionRange !== 'string') { | ||
throw new Error('`binary` and `versionRange` required'); | ||
module.exports = (bin, semverRange, opts) => { | ||
if (typeof bin !== 'string' || typeof semverRange !== 'string') { | ||
return Promise.reject('`binary` and `semverRange` required'); | ||
} | ||
if (!semver.validRange(versionRange)) { | ||
return cb(new Error('Invalid version range')); | ||
if (!semver.validRange(semverRange)) { | ||
return Promise.reject(new Error('Invalid version range')); | ||
} | ||
binVersion(bin, function (err, binVersion) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (!semver.satisfies(semverTruncate(binVersion, 'patch'), versionRange)) { | ||
err = new Error(bin + ' ' + binVersion + ' does not satisfy the version requirement of ' + versionRange); | ||
return binVersion(bin, opts).then(binVersion => { | ||
if (!semver.satisfies(semverTruncate(binVersion, 'patch'), semverRange)) { | ||
const err = new Error(`${bin} ${binVersion} doesn't satisfy the version requirement of ${semverRange}`); | ||
err.name = 'InvalidBinVersion'; | ||
return cb(err); | ||
throw err; | ||
} | ||
cb(); | ||
}); | ||
}; |
{ | ||
"name": "bin-version-check", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Check whether a binary version satisfies a semver range", | ||
@@ -10,16 +10,12 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "http://sindresorhus.com" | ||
"url": "sindresorhus.com" | ||
}, | ||
"bin": { | ||
"bin-version-check": "cli.js" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"cli.js" | ||
"index.js" | ||
], | ||
@@ -40,10 +36,13 @@ "keywords": [ | ||
"dependencies": { | ||
"bin-version": "^1.0.0", | ||
"minimist": "^1.1.0", | ||
"semver": "^4.0.3", | ||
"bin-version": "^2.0.0", | ||
"semver": "^5.1.0", | ||
"semver-truncate": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
} |
# bin-version-check [![Build Status](https://travis-ci.org/sindresorhus/bin-version-check.svg?branch=master)](https://travis-ci.org/sindresorhus/bin-version-check) | ||
> Check whether a binary version satisfies a [semver range](https://github.com/isaacs/node-semver#ranges) | ||
> Check whether a binary version satisfies a [semver range](https://github.com/npm/node-semver#ranges) | ||
@@ -10,3 +10,3 @@ Useful when you have a thing that only works with specific versions of a binary. | ||
```sh | ||
``` | ||
$ npm install --save bin-version-check | ||
@@ -18,3 +18,3 @@ ``` | ||
```sh | ||
``` | ||
$ curl --version | ||
@@ -25,9 +25,7 @@ curl 7.30.0 (x86_64-apple-darwin13.0) | ||
```js | ||
var binVersionCheck = require('bin-version-check'); | ||
const binVersionCheck = require('bin-version-check'); | ||
binVersionCheck('curl', '>=8', function (err) { | ||
if (err) { | ||
binVersionCheck('curl', '>=8').catch(err => { | ||
throw err; | ||
//=> InvalidBinVersion: curl 7.30.0 does not satisfy the version requirement of >=8 | ||
} | ||
//=> 'InvalidBinVersion: curl 7.30.0 doesn't satisfy the version requirement of >=8' | ||
}); | ||
@@ -37,26 +35,35 @@ ``` | ||
## CLI | ||
## API | ||
```sh | ||
$ npm install --global bin-version-check | ||
``` | ||
### binVersionCheck(binary, semverRange, [options]) | ||
``` | ||
$ bin-version-check --help | ||
#### binary | ||
Usage | ||
bin-version-check <binary> <semver-range> | ||
Type: `string` | ||
Example | ||
$ curl --version | ||
curl 7.30.0 (x86_64-apple-darwin13.0) | ||
$ bin-version-check curl '>=8' | ||
curl 7.30.0 does not satisfy the version requirement of >=8 | ||
Name or path of the binary to check. | ||
Exits with code 0 if the semver range is satisfied and 1 if not | ||
``` | ||
#### semverRange | ||
Type: `string` | ||
[Semver range](https://github.com/npm/node-semver#ranges) to check against. | ||
#### options | ||
##### args | ||
Type: `array` | ||
Default: `['--version']` | ||
CLI arguments used to get the binary version. | ||
## Related | ||
- [bin-version-check-cli](https://github.com/sindresorhus/bin-version-check-cli) - CLI for this module | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3894
3
66
2
19
+ Addedbin-version@2.0.0(transitive)
+ Addedcross-spawn-async@2.2.5(transitive)
+ Addedexeca@0.1.1(transitive)
+ Addedfind-versions@2.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedyallist@2.1.2(transitive)
- Removedminimist@^1.1.0
- Removedarray-find-index@1.0.2(transitive)
- Removedbin-version@1.0.4(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfind-versions@1.2.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@4.3.6(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
Updatedbin-version@^2.0.0
Updatedsemver@^5.1.0