Skip to content

Commit

Permalink
fix: -v flag not working for yarn@berry (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimava authored and antfu committed Sep 11, 2023
1 parent a3fc4d4 commit 9e3c9a7
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getDefaultAgent, getGlobalAgent } from './config'
import type { DetectOptions } from './detect'
import { detect } from './detect'
import { getVoltaPrefix, remove } from './utils'
import { UnsupportedCommand } from './parse'
import { UnsupportedCommand, getCommand } from './parse'

const DEBUG_SIGN = '?'

Expand Down Expand Up @@ -84,8 +84,9 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
args.splice(0, 2)
}

if (args.length === 1 && (args[0]?.toLowerCase() === '-v')) {
const getV = (a: string, o?: ExecaOptions) => execaCommand(`${a} -v`, o).then(e => e.stdout).then(e => e.startsWith('v') ? e : `v${e}`)
if (args.length === 1 && (args[0]?.toLowerCase() === '-v' || args[0] === '--version')) {
const getCmd = (a: Agent) => agents.includes(a) ? getCommand(a, 'agent', ['-v']) : `${a} -v`
const getV = (a: string, o?: ExecaOptions) => execaCommand(getCmd(a as Agent), o).then(e => e.stdout).then(e => e.startsWith('v') ? e : `v${e}`)
const globalAgentPromise = getGlobalAgent()
const globalAgentVersionPromise = globalAgentPromise.then(getV)
const agentPromise = detect({ ...options, cwd }).then(a => a || '')
Expand All @@ -112,13 +113,14 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
if (args.length === 1 && ['-h', '--help'].includes(args[0])) {
const dash = c.dim('-')
console.log(c.green(c.bold('@antfu/ni')) + c.dim(` use the right package manager v${version}\n`))
console.log(`ni ${dash} install`)
console.log(`nr ${dash} run`)
console.log(`nlx ${dash} execute`)
console.log(`nu ${dash} upgrade`)
console.log(`nun ${dash} uninstall`)
console.log(`nci ${dash} clean install`)
console.log(`na ${dash} agent alias`)
console.log(`ni ${dash} install`)
console.log(`nr ${dash} run`)
console.log(`nlx ${dash} execute`)
console.log(`nu ${dash} upgrade`)
console.log(`nun ${dash} uninstall`)
console.log(`nci ${dash} clean install`)
console.log(`na ${dash} agent alias`)
console.log(`ni -v ${dash} show used agent`)
console.log(c.yellow('\ncheck https://github.com/antfu/ni for more documentation.'))
return
}
Expand Down

0 comments on commit 9e3c9a7

Please sign in to comment.