blob: 303e996f84acb89890174b094107a293a8c42a1a [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2const execa = require('execa');
3const findVersions = require('find-versions');
4
5module.exports = (binary, options = {}) => {
6 return execa(binary, options.args || ['--version'])
7 .then(result => findVersions(result.stdout || result.stderr, {loose: true})[0])
8 .catch(error => {
9 if (error.code === 'ENOENT') {
10 error.message = `Couldn't find the \`${binary}\` binary. Make sure it's installed and in your $PATH.`;
11 }
12
13 throw error;
14 });
15};