| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | const execa = require('execa'); |
| 3 | const findVersions = require('find-versions'); |
| 4 | |
| 5 | module.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 | }; |