Socket
Socket
Sign inDemoInstall

bin-version-check

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bin-version-check - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

license

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();
});
};

25

package.json
{
"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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc