22import { resolve } from 'node:path'
33import process from 'node:process'
44import prompts from '@posva/prompts'
5+ import type { Options as ExecaOptions } from 'execa'
56import { execaCommand } from 'execa'
67import c from 'kleur'
78import { version } from '../package.json'
@@ -75,6 +76,32 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
7576 if ( debug )
7677 remove ( args , DEBUG_SIGN )
7778
79+ let cwd = options . cwd ?? process . cwd ( )
80+ if ( args [ 0 ] === '-C' ) {
81+ cwd = resolve ( cwd , args [ 1 ] )
82+ args . splice ( 0 , 2 )
83+ }
84+
85+ if ( args . length === 1 && ( args [ 0 ] ?. toLowerCase ( ) === '-v' ) ) {
86+ const getV = ( a : string , o ?: ExecaOptions ) => execaCommand ( `${ a } -v` , o ) . then ( e => e . stdout ) . then ( e => e . startsWith ( 'v' ) ? e : `v${ e } ` )
87+ const globalAgentPromise = getGlobalAgent ( )
88+ const globalAgentVersionPromise = globalAgentPromise . then ( getV )
89+ const agentPromise = detect ( { ...options , cwd } ) . then ( a => a || '' )
90+ const agentVersionPromise = agentPromise . then ( a => a && getV ( a , { cwd } ) )
91+ const nodeVersionPromise = getV ( 'node' , { cwd } )
92+
93+ console . log ( `@antfu/ni ${ c . cyan ( `v${ version } ` ) } ` )
94+ console . log ( `node ${ c . green ( await nodeVersionPromise ) } ` )
95+ const [ agent , agentVersion ] = await Promise . all ( [ agentPromise , agentVersionPromise ] )
96+ if ( agent )
97+ console . log ( `${ agent . padEnd ( 10 ) } ${ c . blue ( agentVersion ) } ` )
98+ else
99+ console . log ( 'agent no lock file' )
100+ const [ globalAgent , globalAgentVersion ] = await Promise . all ( [ globalAgentPromise , globalAgentVersionPromise ] )
101+ console . log ( `${ ( `${ globalAgent } -g` ) . padEnd ( 10 ) } ${ c . blue ( globalAgentVersion ) } ` )
102+ return
103+ }
104+
78105 if ( args . length === 1 && ( args [ 0 ] === '--version' || args [ 0 ] === '-v' ) ) {
79106 console . log ( `@antfu/ni v${ version } ` )
80107 return
@@ -94,13 +121,6 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
94121 return
95122 }
96123
97- let cwd = options . cwd ?? process . cwd ( )
98-
99- if ( args [ 0 ] === '-C' ) {
100- cwd = resolve ( cwd , args [ 1 ] )
101- args . splice ( 0 , 2 )
102- }
103-
104124 let command = await getCliCommand ( fn , args , options , cwd )
105125
106126 if ( ! command )
0 commit comments