bin-version-check
Advanced tools
Comparing version 4.0.0 to 5.0.0
31
index.js
@@ -1,22 +0,23 @@ | ||
'use strict'; | ||
const semver = require('semver'); | ||
const binVersion = require('bin-version'); | ||
const semverTruncate = require('semver-truncate'); | ||
import semver from 'semver'; | ||
import binaryVersion from 'bin-version'; | ||
import semverTruncate from 'semver-truncate'; | ||
module.exports = (binary, semverRange, options) => { | ||
export default async function binaryVersionCheck(binary, semverRange, options) { | ||
if (typeof binary !== 'string' || typeof semverRange !== 'string') { | ||
return Promise.reject(new Error('`binary` and `semverRange` arguments required')); | ||
throw new TypeError('`binary` and `semverRange` arguments required'); | ||
} | ||
if (!semver.validRange(semverRange)) { | ||
return Promise.reject(new Error('Invalid version range')); | ||
throw new Error('Invalid version range'); | ||
} | ||
return binVersion(binary, options).then(binaryVersion => { | ||
if (!semver.satisfies(semverTruncate(binaryVersion, 'patch'), semverRange)) { | ||
const error = new Error(`${binary} ${binaryVersion} doesn't satisfy the version requirement of ${semverRange}`); | ||
error.name = 'InvalidBinaryVersion'; | ||
throw error; | ||
} | ||
}); | ||
}; | ||
const version = await binaryVersion(binary, options); | ||
if (semver.satisfies(semverTruncate(version, 'patch'), semverRange)) { | ||
return; | ||
} | ||
const error = new Error(`${binary} ${version} doesn't satisfy the version requirement of ${semverRange}`); | ||
error.name = 'InvalidBinaryVersion'; | ||
throw error; | ||
} |
{ | ||
"name": "bin-version-check", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Check whether a binary version satisfies a semver range", | ||
"license": "MIT", | ||
"repository": "sindresorhus/bin-version-check", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=12" | ||
}, | ||
@@ -23,3 +26,2 @@ "scripts": { | ||
"cli", | ||
"bin", | ||
"binary", | ||
@@ -36,10 +38,10 @@ "executable", | ||
"dependencies": { | ||
"bin-version": "^3.0.0", | ||
"semver": "^5.6.0", | ||
"semver-truncate": "^1.1.2" | ||
"bin-version": "^6.0.0", | ||
"semver": "^7.3.5", | ||
"semver-truncate": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.0.0-rc.1", | ||
"xo": "^0.23.0" | ||
"ava": "^3.15.0", | ||
"xo": "^0.39.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# bin-version-check [![Build Status](https://travis-ci.org/sindresorhus/bin-version-check.svg?branch=master)](https://travis-ci.org/sindresorhus/bin-version-check) | ||
# bin-version-check | ||
@@ -7,3 +7,2 @@ > Check whether a binary version satisfies a [semver range](https://github.com/npm/node-semver#ranges) | ||
## Install | ||
@@ -15,3 +14,2 @@ | ||
## Usage | ||
@@ -25,18 +23,15 @@ | ||
```js | ||
const binVersionCheck = require('bin-version-check'); | ||
import binaryVersionCheck from 'bin-version-check'; | ||
(async () => { | ||
try { | ||
await binVersionCheck('curl', '>=8'); | ||
} catch (error) { | ||
console.log(error); | ||
//=> 'InvalidBinVersion: curl 7.30.0 doesn't satisfy the version requirement of >=8' | ||
} | ||
})(); | ||
try { | ||
await binaryVersionCheck('curl', '>=8'); | ||
} catch (error) { | ||
console.log(error); | ||
//=> 'InvalidBinaryVersion: curl 7.30.0 doesn't satisfy the version requirement of >=8' | ||
} | ||
``` | ||
## API | ||
### binVersionCheck(binary, semverRange, [options]) | ||
### binaryVersionCheck(binary, semverRange, options?) | ||
@@ -57,7 +52,7 @@ #### binary | ||
Type: `Object` | ||
Type: `object` | ||
##### args | ||
Type: `string[]` | ||
Type: `string[]`\ | ||
Default: `['--version']` | ||
@@ -67,10 +62,4 @@ | ||
## Related | ||
- [bin-version-check-cli](https://github.com/sindresorhus/bin-version-check-cli) - CLI for this module | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
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
Yes
3746
18
61
+ Addedbin-version@6.0.0(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addedexeca@5.1.1(transitive)
+ Addedfind-versions@5.1.0(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedhuman-signals@2.1.0(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednpm-run-path@4.0.1(transitive)
+ Addedonetime@5.1.2(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedsemver@6.3.17.6.3(transitive)
+ Addedsemver-regex@4.0.5(transitive)
+ Addedsemver-truncate@2.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedstrip-final-newline@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
- Removedbin-version@3.1.0(transitive)
- Removedcross-spawn@6.0.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedexeca@1.0.0(transitive)
- Removedfind-versions@3.2.0(transitive)
- Removedget-stream@4.1.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednice-try@1.0.5(transitive)
- Removednpm-run-path@2.0.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedpump@3.0.2(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsemver-regex@2.0.0(transitive)
- Removedsemver-truncate@1.1.2(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedwhich@1.3.1(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedbin-version@^6.0.0
Updatedsemver@^7.3.5
Updatedsemver-truncate@^2.0.0