diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 1a630e9..0000000 --- a/.github/funding.yml +++ /dev/null @@ -1,3 +0,0 @@ -github: sindresorhus -open_collective: sindresorhus -custom: https://sindresorhus.com/donate diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1870cf..3b8aa86 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,12 +10,12 @@ jobs: fail-fast: false matrix: node-version: + - 16 - 14 - 12 - - 10 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index 8b9866e..92d4020 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,12 +1,10 @@ -declare namespace binVersion { - interface Options { - /** - The arguments to pass to `binary` so that it will print its version. - - If not specified, predefined arguments will be used for known binaries, or `['--version']` and `['version']` arguments will be tried. - */ - readonly args?: readonly string[]; - } +export interface Options { + /** + The arguments to pass to `binary` so that it will print its version. + + If not specified, predefined arguments will be used for known binaries, or `['--version']` and `['version']` arguments will be tried. + */ + readonly args?: readonly string[]; } /** @@ -17,29 +15,22 @@ Get the version of a binary in [semver](https://github.com/npm/node-semver) form @example ``` -import binVersion = require('bin-version'); +import binaryVersion from 'bin-version'; -(async () => { - // $ curl --version - // curl 7.30.0 (x86_64-apple-darwin13.0) +// $ curl --version +// curl 7.30.0 (x86_64-apple-darwin13.0) - console.log(await binVersion('curl')); - //=> '7.30.0' +console.log(await binaryVersion('curl')); +//=> '7.30.0' - // $ openssl version - // OpenSSL 1.0.2d 9 Jul 2015 +// $ openssl version +// OpenSSL 1.0.2d 9 Jul 2015 - console.log(await binVersion('openssl')); - //=> '1.0.2' +console.log(await binaryVersion('openssl')); +//=> '1.0.2' - console.log(await binVersion('openssl', {args: ['version']})); - //=> '1.0.2' -})(); +console.log(await binaryVersion('openssl', {args: ['version']})); +//=> '1.0.2' ``` */ -declare function binVersion( - binary: string, - options?: binVersion.Options -): Promise; - -export = binVersion; +export default function binaryVersion(binary: string, options?: Options): Promise; diff --git a/index.js b/index.js index 075e4da..8a09faa 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ -'use strict'; -const execa = require('execa'); -const findVersions = require('find-versions'); +import execa from 'execa'; +import findVersions from 'find-versions'; const oneMegabyte = 1000 * 1000; @@ -18,7 +17,7 @@ const defaultPossibleArguments = [ ['version'] ]; -module.exports = async (binary, options = {}) => { +export default async function binaryVersion(binary, options = {}) { let possibleArguments; if (options.args === undefined) { @@ -54,4 +53,4 @@ module.exports = async (binary, options = {}) => { } throw new Error(`Couldn't find version of \`${binary}\``); -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index f063a66..c1f5bb8 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import binVersion = require('.'); +import binaryVersion from './index.js'; -expectType>(binVersion('curl')); -expectType>(binVersion('openssl', {args: ['version']})); +expectType>(binaryVersion('curl')); +expectType>(binaryVersion('openssl', {args: ['version']})); diff --git a/package.json b/package.json index f85f73c..e0c70e8 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,10 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=10" + "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" @@ -21,7 +23,6 @@ "index.d.ts" ], "keywords": [ - "bin", "binary", "executable", "version", @@ -31,11 +32,11 @@ ], "dependencies": { "execa": "^5.0.0", - "find-versions": "^4.0.0" + "find-versions": "^5.0.0" }, "devDependencies": { - "ava": "^2.4.0", + "ava": "^3.15.0", "tsd": "^0.14.0", - "xo": "^0.37.1" + "xo": "^0.39.1" } } diff --git a/readme.md b/readme.md index d5dffd4..3b8ecfa 100644 --- a/readme.md +++ b/readme.md @@ -16,12 +16,10 @@ curl 7.30.0 (x86_64-apple-darwin13.0) ``` ```js -const binVersion = require('bin-version'); +import binaryVersion from 'bin-version'; -(async () => { - console.log(await binVersion('curl')); - //=> '7.30.0' -})(); +console.log(await binaryVersion('curl')); +//=> '7.30.0' ``` ``` @@ -30,12 +28,10 @@ OpenSSL 1.0.2d 9 Jul 2015 ``` ```js -const binVersion = require('bin-version'); +import binaryVersion from 'bin-version'; -(async () => { - console.log(await binVersion('openssl')); - //=> '1.0.2' -})(); +console.log(await binaryVersion('openssl')); +//=> '1.0.2' ``` ``` @@ -44,17 +40,15 @@ OpenSSL 1.0.2d 9 Jul 2015 ``` ```js -const binVersion = require('bin-version'); +import binaryVersion from 'bin-version'; -(async () => { - console.log(await binVersion('openssl', {args: ['version']})); - //=> '1.0.2' -})(); +console.log(await binaryVersion('openssl', {args: ['version']})); +//=> '1.0.2' ``` ## API -### binVersion(binary, options?) +### binaryVersion(binary, options?) Returns a `Promise` with the version of the `binary`. diff --git a/test.js b/test.js index 74551e8..fb2c04b 100644 --- a/test.js +++ b/test.js @@ -1,44 +1,44 @@ import test from 'ava'; -import binVersion from './index.js'; +import binaryVersion from './index.js'; const versionRegex = /\d+\.\d+\.\d+/; test('does-not-exist', async t => { - await t.throwsAsync(binVersion('does-not-exist'), /Couldn't find/); + await t.throwsAsync(binaryVersion('does-not-exist'), {message: /Couldn't find/}); }); test('non-executable', async t => { - await t.throwsAsync(binVersion('./fixture/non-executable.js')); + await t.throwsAsync(binaryVersion('./fixture/non-executable.js')); }); test('non-versioned', async t => { - await t.throwsAsync(binVersion('./fixture/non-versioned.js'), /Couldn't find version/); + await t.throwsAsync(binaryVersion('./fixture/non-versioned.js'), {message: /Couldn't find version/}); }); test('anything accepting `--version`', async t => { - t.is(await binVersion('./fixture/versioned-type1.js'), '1.2.3'); + t.is(await binaryVersion('./fixture/versioned-type1.js'), '1.2.3'); }); test('anything accepting `version`', async t => { - t.is(await binVersion('./fixture/versioned-type2.js'), '1.2.3'); + t.is(await binaryVersion('./fixture/versioned-type2.js'), '1.2.3'); }); test('curl', async t => { - t.regex(await binVersion('curl'), versionRegex); + t.regex(await binaryVersion('curl'), versionRegex); }); test('npm', async t => { - t.regex(await binVersion('npm'), versionRegex); + t.regex(await binaryVersion('npm'), versionRegex); }); test('openssl', async t => { - t.regex(await binVersion('openssl'), versionRegex); + t.regex(await binaryVersion('openssl'), versionRegex); }); test('custom args', async t => { - t.regex(await binVersion('./fixture/versioned-type1.js', {args: ['--version']}), versionRegex); + t.regex(await binaryVersion('./fixture/versioned-type1.js', {args: ['--version']}), versionRegex); }); test('php', async t => { - t.is(await binVersion('./fixture/php.js'), '7.0.0'); + t.is(await binaryVersion('./fixture/php.js'), '7.0.0'); });