2
2
import { resolve } from 'node:path'
3
3
import process from 'node:process'
4
4
import prompts from '@posva/prompts'
5
+ import type { Options as ExecaOptions } from 'execa'
5
6
import { execaCommand } from 'execa'
6
7
import c from 'kleur'
7
8
import { version } from '../package.json'
@@ -75,6 +76,32 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
75
76
if ( debug )
76
77
remove ( args , DEBUG_SIGN )
77
78
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
+
78
105
if ( args . length === 1 && ( args [ 0 ] === '--version' || args [ 0 ] === '-v' ) ) {
79
106
console . log ( `@antfu/ni v${ version } ` )
80
107
return
@@ -94,13 +121,6 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
94
121
return
95
122
}
96
123
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
-
104
124
let command = await getCliCommand ( fn , args , options , cwd )
105
125
106
126
if ( ! command )
0 commit comments