diff --git a/lib/support/cli.js b/lib/support/cli.js index 40873deee..0f72133ed 100644 --- a/lib/support/cli.js +++ b/lib/support/cli.js @@ -5,7 +5,6 @@ import { hideBin } from 'yargs/helpers'; import { findUpSync } from 'find-up'; import get from 'lodash.get'; import set from 'lodash.set'; -import hasbin from 'hasbin'; import { framerate, crf, @@ -16,6 +15,8 @@ import { import { screenshotDefaults } from '../screenshot/defaults.js'; import { geckoProfilerDefaults } from '../firefox/settings/geckoProfilerDefaults.js'; +import { execaSync } from 'execa'; + const configPath = findUpSync(['.browsertime.json']); let config; @@ -33,6 +34,16 @@ try { throw error; } +function hasbin(bin) { + try { + const cmd = process.platform === 'win32' ? 'where' : 'which'; + execaSync(cmd, bin); + return true; + } catch { + return false; + } +} + function validateInput(argv) { // Check NodeJS major version const fullVersion = process.versions.node; @@ -70,7 +81,7 @@ function validateInput(argv) { } } - if ((argv.video || argv.visualMetrics) && !hasbin.sync(['ffmpeg'])) { + if ((argv.video || argv.visualMetrics) && !hasbin(['ffmpeg'])) { return 'You need to have ffmpeg in your path to be able to record a video.'; } @@ -90,11 +101,11 @@ function validateInput(argv) { return 'There is no benefit running debug mode inside a Docker container.'; } - if (argv.tcpdump && !hasbin.sync(['tcpdump'])) { + if (argv.tcpdump && !hasbin(['tcpdump'])) { return 'You need to have tcpdump in your path to be able to record a tcpdump.'; } - if (argv.gnirehtet && !hasbin.sync(['gnirehtet'])) { + if (argv.gnirehtet && !hasbin(['gnirehtet'])) { return 'You need to have gnirehtet in your path to be able to use it. If you run on a Mac you can install it using Homebrew: brew install gnirehtet'; } diff --git a/package-lock.json b/package-lock.json index 650cae254..afe05c822 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,6 @@ "ff-test-bidi-har-export": "0.0.17", "find-up": "7.0.0", "get-port": "7.1.0", - "hasbin": "1.2.3", "intel": "1.2.0", "lodash.get": "4.4.2", "lodash.groupby": "4.6.0", @@ -4073,22 +4072,6 @@ "node": ">=8" } }, - "node_modules/hasbin": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/hasbin/-/hasbin-1.2.3.tgz", - "integrity": "sha1-eMWSaJPIAhXCtWiuH9P8q3omlrA=", - "dependencies": { - "async": "~1.5" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/hasbin/node_modules/async": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", - "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" - }, "node_modules/hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -10493,21 +10476,6 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, - "hasbin": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/hasbin/-/hasbin-1.2.3.tgz", - "integrity": "sha1-eMWSaJPIAhXCtWiuH9P8q3omlrA=", - "requires": { - "async": "~1.5" - }, - "dependencies": { - "async": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", - "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" - } - } - }, "hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", diff --git a/package.json b/package.json index e483bd082..fb9db992d 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "ff-test-bidi-har-export": "0.0.17", "find-up": "7.0.0", "get-port": "7.1.0", - "hasbin": "1.2.3", "intel": "1.2.0", "lodash.get": "4.4.2", "lodash.groupby": "4.6.0",