diff --git a/index.js b/index.js index 49100bd..682413d 100644 --- a/index.js +++ b/index.js @@ -2,20 +2,22 @@ const execa = require('execa'); const executable = require('executable'); -module.exports = (bin, args) => { +module.exports = async (bin, args) => { if (!Array.isArray(args)) { args = ['--help']; } - return executable(bin) - .then(works => { - if (!works) { - throw new Error(`Couldn't execute the \`${bin}\` binary. Make sure it has the right permissions.`); - } + try { + const works = await executable(bin); + if (!works) { + throw new Error(`Couldn't execute the \`${bin}\` binary. Make sure it has the right permissions.`); + } - return execa(bin, args); - }) - .then(res => res.code === 0); + const result = await execa(bin, args); + return Promise.resolve(result.exitCode === 0); + } catch (error) { + return Promise.reject(error); + } }; module.exports.sync = (bin, args) => { @@ -27,5 +29,5 @@ module.exports.sync = (bin, args) => { throw new Error(`Couldn't execute the \`${bin}\` binary. Make sure it has the right permissions.`); } - return execa.sync(bin, args).status === 0; + return execa.sync(bin, args).exitCode === 0; }; diff --git a/package.json b/package.json index 279b342..ae6a3ee 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "https://github.com/kevva" }, "engines": { - "node": ">=4" + "node": ">=7.6.0" }, "scripts": { "test": "xo && ava" @@ -25,11 +25,17 @@ "test" ], "dependencies": { - "execa": "^0.7.0", - "executable": "^4.1.0" + "execa": "^5.0.0", + "executable": "^4.1.1" }, "devDependencies": { - "ava": "*", - "xo": "*" + "ava": "^3.15.0", + "esm": "^3.2.25", + "xo": "^0.37.1" + }, + "ava": { + "require": [ + "esm" + ] } } diff --git a/test.js b/test.js index 0349902..872e1a0 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,6 @@ import path from 'path'; import test from 'ava'; -import m from '.'; +import m from './index.js'; const bin = { darwin: path.join(__dirname, 'fixtures/optipng-osx'), @@ -10,10 +10,10 @@ const bin = { test('async', async t => { t.true(await m(bin[process.platform])); - await t.throws(m(__filename), `Couldn't execute the \`${__filename}\` binary. Make sure it has the right permissions.`); + await t.throwsAsync(m(__filename), {message: `Couldn't execute the \`${__filename}\` binary. Make sure it has the right permissions.`}); }); test('sync', t => { t.true(m.sync(bin[process.platform])); - t.throws(m.sync.bind(null, __filename), `Couldn't execute the \`${__filename}\` binary. Make sure it has the right permissions.`); + t.throws(m.sync.bind(null, __filename), {message: `Couldn't execute the \`${__filename}\` binary. Make sure it has the right permissions.`}); });