Skip to content

Commit 4debd10

Browse files
committed
Attempt to switch to Node.js 22 via fnm or nvm when version is below 20
├── install.ps1 └── install.sh
1 parent f3d3564 commit 4debd10

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

‎install.ps1‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,42 @@ if (!(Get-Command git -ErrorAction SilentlyContinue)) {
77
exit 1
88
}
99

10-
# Validate Node.js version
11-
if (!(Get-Command node -ErrorAction SilentlyContinue)) {
12-
Write-Host "Error: Node.js version 20 or higher is required." -ForegroundColor Red
13-
Pause
14-
exit 1
10+
# Validate Node.js version and attempt to switch if necessary
11+
$nodeIsGood = $false
12+
if (Get-Command node -ErrorAction SilentlyContinue) {
13+
$nodeVersion = (node -v) -replace '^v',''
14+
$major = [int]($nodeVersion -split '\.')[0]
15+
if ($major -ge 20) {
16+
$nodeIsGood = $true
17+
}
1518
}
1619

17-
$nodeVersion = (node -v) -replace '^v',''
18-
$major = [int]($nodeVersion -split '\.')[0]
19-
if ($major -lt 20) {
20-
Write-Host "Error: Node.js version 20 or higher is required (Node.js 22.x is recommended)." -ForegroundColor Red
21-
Pause
22-
exit 1
20+
if (!$nodeIsGood) {
21+
Write-Host "Node.js version 20 or higher is required (Node.js 22.x is recommended)."
22+
Write-Host "Attempting to switch to Node.js 22 using a version manager..."
23+
24+
$switched = $false
25+
26+
# Try fnm
27+
if (!$switched -and (Get-Command fnm -ErrorAction SilentlyContinue)) {
28+
fnm env --shell powershell | Out-String | Invoke-Expression
29+
fnm install 22
30+
fnm use 22
31+
$switched = $true
32+
}
33+
34+
# Try nvm
35+
if (!$switched -and (Get-Command nvm -ErrorAction SilentlyContinue)) {
36+
nvm install 22
37+
nvm use 22
38+
$switched = $true
39+
}
40+
41+
if (!$switched) {
42+
Write-Host "Error: Failed to find a compatible Node.js version and no supported version manager (fnm, nvm) could switch it." -ForegroundColor Red
43+
Pause
44+
exit 1
45+
}
2346
}
2447

2548
# Detect available editors in the system

0 commit comments

Comments
 (0)