Skip to content

Commit 3619d9d

Browse files
committed
Check for executability & improve perf in $PATH command detection
Switching to lookpath should speed things up by not actually spawning anything, and make some of these checks a bit more rigorous.
1 parent 0443cac commit 3619d9d

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

package-lock.json

Lines changed: 18 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@
3737
"@oclif/plugin-update": "^1.3.8",
3838
"@sentry/integrations": "^5.29.2",
3939
"@sentry/node": "^5.29.2",
40-
"@types/command-exists": "^1.2.0",
4140
"@types/cors": "^2.8.7",
4241
"@types/node-fetch": "^2.5.4",
4342
"@types/tmp": "0.0.33",
4443
"async-mutex": "^0.1.3",
4544
"chrome-remote-interface": "^0.28.0",
46-
"command-exists": "^1.2.8",
4745
"cors": "^2.8.5",
4846
"cors-gate": "^1.1.3",
4947
"env-paths": "^1.0.0",
@@ -54,6 +52,7 @@
5452
"graphql": "^14.7.0",
5553
"iconv-lite": "^0.4.24",
5654
"lodash": "^4.17.21",
55+
"lookpath": "^1.2.1",
5756
"mime-types": "^2.1.27",
5857
"mockttp": "^1.2.1",
5958
"node-fetch": "^2.6.1",

src/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { promisify } from 'util';
22
import * as fs from 'fs';
33
import * as tmp from 'tmp';
44
import * as rimraf from 'rimraf';
5-
import * as ensureCommandExists from 'command-exists';
5+
import { lookpath } from 'lookpath';
66

77
export function delay(durationMs: number): Promise<void> {
88
return new Promise((resolve) => setTimeout(resolve, durationMs));
@@ -63,7 +63,7 @@ export const ensureDirectoryExists = (path: string) =>
6363
checkAccess(path).catch(() => mkDir(path, { recursive: true }));
6464

6565
export const commandExists = (path: string): Promise<boolean> =>
66-
ensureCommandExists(path).then(() => true).catch(() => false);
66+
lookpath(path).then((result) => result !== undefined);
6767

6868
export const createTmp = (options: tmp.Options = {}) => new Promise<{
6969
path: string,

0 commit comments

Comments
 (0)