Skip to content

Commit 9e3c9a7

Browse files
Dimavaantfu
authored andcommittedSep 11, 2023
fix: -v flag not working for yarn@berry (#175)
1 parent a3fc4d4 commit 9e3c9a7

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed
 

‎src/runner.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getDefaultAgent, getGlobalAgent } from './config'
1212
import type { DetectOptions } from './detect'
1313
import { detect } from './detect'
1414
import { getVoltaPrefix, remove } from './utils'
15-
import { UnsupportedCommand } from './parse'
15+
import { UnsupportedCommand, getCommand } from './parse'
1616

1717
const DEBUG_SIGN = '?'
1818

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.