File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { describe , expect , test } from 'vitest'
2
+ import { checkNodeVersion } from '../cli'
3
+
4
+ describe ( 'CLI Node.js version checking' , ( ) => {
5
+ test . each ( [
6
+ // Unsupported versions
7
+ [ '18.20.0' , false ] ,
8
+ [ '20.18.5' , false ] ,
9
+ [ '22.11.0' , false ] ,
10
+ // Supported versions
11
+ [ '20.19.0' , true ] ,
12
+ [ '20.20.1' , true ] ,
13
+ [ '22.12.0' , true ] ,
14
+ [ '22.13.1' , true ] ,
15
+ [ '23.0.0' , true ] ,
16
+ ] ) ( 'should return %1 for Node.js version %0' , ( version , expected ) => {
17
+ const result = checkNodeVersion ( version )
18
+ expect ( result ) . toBe ( expected )
19
+ } )
20
+ } )
Original file line number Diff line number Diff line change @@ -11,6 +11,26 @@ import type { LogLevel } from './logger'
11
11
import { createLogger } from './logger'
12
12
import type { InlineConfig } from './config'
13
13
14
+ export function checkNodeVersion ( nodeVersion : string ) : boolean {
15
+ const currentVersion = nodeVersion . split ( '.' )
16
+ const major = parseInt ( currentVersion [ 0 ] , 10 )
17
+ const minor = parseInt ( currentVersion [ 1 ] , 10 )
18
+ const isSupported =
19
+ ( major === 20 && minor >= 19 ) || ( major === 22 && minor >= 12 ) || major > 22
20
+ return isSupported
21
+ }
22
+
23
+ if ( ! checkNodeVersion ( process . versions . node ) ) {
24
+ // eslint-disable-next-line no-console
25
+ console . warn (
26
+ colors . yellow (
27
+ `You are using Node.js ${ process . versions . node } . ` +
28
+ `Vite requires Node.js version 20.19+ or 22.12+. ` +
29
+ `Please upgrade your Node.js version.` ,
30
+ ) ,
31
+ )
32
+ }
33
+
14
34
const cli = cac ( 'vite' )
15
35
16
36
// global options
You can’t perform that action at this time.
0 commit comments