Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 27, 2024
1 parent 571d519 commit 4514af5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export interface DetectOptions {
autoInstall?: boolean
programmatic?: boolean
cwd?: string
/**
* Should use Volta when present
*
* @see https://volta.sh/
* @default true
*/
detectVolta?: boolean
}

export async function detect({ autoInstall, programmatic, cwd }: DetectOptions = {}) {
Expand Down
8 changes: 6 additions & 2 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { version } from '../package.json'
import { getDefaultAgent, getGlobalAgent } from './config'
import type { DetectOptions } from './detect'
import { detect } from './detect'
import { isVoltaExists, remove } from './utils'
import { cmdExists, remove } from './utils'
import { UnsupportedCommand, getCommand } from './parse'

const DEBUG_SIGN = '?'
Expand Down Expand Up @@ -74,6 +74,10 @@ export async function getCliCommand(
}

export async function run(fn: Runner, args: string[], options: DetectOptions = {}) {
const {
detectVolta = true,
} = options

const debug = args.includes(DEBUG_SIGN)
if (debug)
remove(args, DEBUG_SIGN)
Expand Down Expand Up @@ -144,7 +148,7 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
if (!command)
return

if (isVoltaExists()) {
if (detectVolta && cmdExists('volta')) {
command.args = ['run', command.command, ...command.args]
command.command = 'volta'
}
Expand Down
4 changes: 0 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export function cmdExists(cmd: string) {
return which.sync(cmd, { nothrow: true }) !== null
}

export function isVoltaExists(): boolean {
return cmdExists('volta')
}

interface TempFile {
path: string
fd: fs.FileHandle
Expand Down

0 comments on commit 4514af5

Please sign in to comment.