Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hasbin #2234

Merged
merged 4 commits into from
Dec 30, 2024
Merged
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
19 changes: 15 additions & 4 deletions lib/support/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.';
}

Expand All @@ -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';
}

Expand Down
32 changes: 0 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading