Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
};
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "https://github.com/kevva"
},
"engines": {
"node": ">=4"
"node": ">=7.6.0"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -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"
]
}
}
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand All @@ -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.`});
});