Skip to content

Commit

Permalink
perf: optimize code performance (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklin committed Mar 26, 2023
1 parent d28d42d commit 4cd9e65
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/utils.ts
@@ -1,5 +1,3 @@
import os from 'os'
import { execSync } from 'child_process'
import which from 'which'

export function remove<T>(arr: T[], v: T) {
Expand All @@ -11,27 +9,16 @@ export function remove<T>(arr: T[], v: T) {
}

export function exclude<T>(arr: T[], v: T) {
return remove(arr.slice(), v)
return arr.slice().filter(item => item !== v)
}

export function cmdExists(cmd: string) {
try {
// #8
execSync(
os.platform() === 'win32'
? `where ${cmd} > nul 2> nul"`
: `command -v ${cmd}`,
)
return true
}
catch {
return false
}
return which.sync(cmd, { nothrow: true }) !== null
}

export function getVoltaPrefix(): string {
// https://blog.volta.sh/2020/11/25/command-spotlight-volta-run/
const VOLTA_PREFIX = 'volta run'
const hasVoltaCommand = which.sync('volta', { nothrow: true }) !== null
const hasVoltaCommand = cmdExists('volta')
return hasVoltaCommand ? VOLTA_PREFIX : ''
}

0 comments on commit 4cd9e65

Please sign in to comment.