@anvil-works/anvil-cli 0.8.0-dev.1 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +32 -4
  2. package/dist/CLILogger.d.ts.map +1 -1
  3. package/dist/SavePathRouter.d.ts +4 -2
  4. package/dist/SavePathRouter.d.ts.map +1 -1
  5. package/dist/WatchSession.d.ts +5 -2
  6. package/dist/WatchSession.d.ts.map +1 -1
  7. package/dist/api.d.ts +5 -3
  8. package/dist/api.d.ts.map +1 -1
  9. package/dist/appRoot.d.ts +11 -0
  10. package/dist/appRoot.d.ts.map +1 -0
  11. package/dist/cli.d.ts +1 -1
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +18833 -17931
  14. package/dist/cliProgram.d.ts +4 -0
  15. package/dist/cliProgram.d.ts.map +1 -0
  16. package/dist/cliReporting.d.ts +4 -0
  17. package/dist/cliReporting.d.ts.map +1 -0
  18. package/dist/commands/db.d.ts.map +1 -1
  19. package/dist/commands/deps.d.ts.map +1 -1
  20. package/dist/commands/env.d.ts.map +1 -1
  21. package/dist/commands/secret.d.ts.map +1 -1
  22. package/dist/commands/test.d.ts +0 -11
  23. package/dist/commands/test.d.ts.map +1 -1
  24. package/dist/commands/validate.d.ts +11 -0
  25. package/dist/commands/validate.d.ts.map +1 -0
  26. package/dist/commands/watch.d.ts.map +1 -1
  27. package/dist/index.js +443 -317
  28. package/dist/logger.d.ts +2 -2
  29. package/dist/program.d.ts +2 -9
  30. package/dist/program.d.ts.map +1 -1
  31. package/dist/programBase.d.ts +5 -0
  32. package/dist/programBase.d.ts.map +1 -0
  33. package/dist/reporting.d.ts +24 -0
  34. package/dist/reporting.d.ts.map +1 -0
  35. package/dist/serviceSources.d.ts.map +1 -1
  36. package/dist/services/db.d.ts.map +1 -1
  37. package/dist/services/deps.d.ts +4 -24
  38. package/dist/services/deps.d.ts.map +1 -1
  39. package/dist/services/depsCache.d.ts +25 -0
  40. package/dist/services/depsCache.d.ts.map +1 -0
  41. package/dist/services/git.d.ts +5 -2
  42. package/dist/services/git.d.ts.map +1 -1
  43. package/dist/services/node-runtime.d.ts +9 -0
  44. package/dist/services/node-runtime.d.ts.map +1 -0
  45. package/dist/services/validation.d.ts +2 -1
  46. package/dist/services/validation.d.ts.map +1 -1
  47. package/dist/validatePython.d.ts +5 -5
  48. package/dist/validatePython.d.ts.map +1 -1
  49. package/dist/validateThemeCss.d.ts +4 -0
  50. package/dist/validateThemeCss.d.ts.map +1 -0
  51. package/dist/validators.d.ts +2 -2
  52. package/dist/validators.d.ts.map +1 -1
  53. package/dist/watch/ConflictResolver.d.ts +5 -4
  54. package/dist/watch/ConflictResolver.d.ts.map +1 -1
  55. package/dist/watch/FileWatcher.d.ts +3 -1
  56. package/dist/watch/FileWatcher.d.ts.map +1 -1
  57. package/dist/watch/SaveProcessor.d.ts +5 -2
  58. package/dist/watch/SaveProcessor.d.ts.map +1 -1
  59. package/dist/watch/SyncManager.d.ts +3 -1
  60. package/dist/watch/SyncManager.d.ts.map +1 -1
  61. package/dist/watch/WebSocketClient.d.ts +3 -0
  62. package/dist/watch/WebSocketClient.d.ts.map +1 -1
  63. package/package.json +3 -2
  64. package/scripts/install/install.cmd +11 -1
  65. package/scripts/install/install.ps1 +59 -43
  66. package/scripts/install/install.sh +108 -33
@@ -3,6 +3,16 @@ REM Source of truth: @anvil-works/anvil-cli (scripts/install/install.cmd).
3
3
  REM This script is synced into anvil website static install endpoints; do not edit the synced copy directly.
4
4
  setlocal
5
5
 
6
+ set "NODE_OPTION="
7
+ if "%~1"=="--install-node" (
8
+ set "NODE_OPTION=-InstallNode"
9
+ shift
10
+ )
11
+ if not "%~1"=="" (
12
+ echo Error: supported option is --install-node.
13
+ exit /b 1
14
+ )
15
+
6
16
  set "SCRIPT_URL=%ANVIL_INSTALL_URL%"
7
17
  if not defined SCRIPT_URL set "SCRIPT_URL=https://anvil.works/install-cli.ps1"
8
18
  set "SCRIPT_PATH=%TEMP%\anvil-install-%RANDOM%%RANDOM%.ps1"
@@ -26,7 +36,7 @@ if errorlevel 1 (
26
36
  exit /b 1
27
37
  )
28
38
 
29
- powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_PATH%"
39
+ powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_PATH%" %NODE_OPTION%
30
40
  set "EXIT_CODE=%ERRORLEVEL%"
31
41
 
32
42
  del /q "%SCRIPT_PATH%" >nul 2>&1
@@ -1,12 +1,15 @@
1
1
  # Source of truth: @anvil-works/anvil-cli (scripts/install/install.ps1).
2
2
  # This script is synced into anvil website static install endpoints; do not edit the synced copy directly.
3
+ param([switch]$InstallNode)
4
+
3
5
  $ErrorActionPreference = 'Stop'
4
6
  Set-StrictMode -Version Latest
5
7
 
6
8
  $AnvilHome = if ($env:ANVIL_HOME) { $env:ANVIL_HOME } else { Join-Path $env:USERPROFILE '.anvil-cli' }
7
- $NodeDir = Join-Path $AnvilHome 'node-v20'
9
+ $AnvilHome = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($AnvilHome)
10
+ $NodeDir = Join-Path $AnvilHome 'node-v24'
11
+ $LegacyNodeDir = Join-Path $AnvilHome 'node-v20'
8
12
  $NpmPrefix = Join-Path $AnvilHome 'npm-global'
9
- $MinTargetMajor = 20
10
13
 
11
14
  function Write-Info([string] $Message) {
12
15
  Write-Host $Message
@@ -29,41 +32,34 @@ function Get-PlatformArch {
29
32
  return 'x64'
30
33
  }
31
34
 
32
- function Get-NodeMajorFromPath {
33
- if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
34
- return $null
35
+ function Get-NodeVersion([string] $Command) {
36
+ try {
37
+ return ([string](& $Command -v 2>$null)).Trim()
35
38
  }
36
-
37
- $version = (& node -v).Trim()
38
- if ($version -match '^v(\d+)') {
39
- return [int]$Matches[1]
39
+ catch {
40
+ return ''
40
41
  }
41
-
42
- return $null
43
42
  }
44
43
 
45
44
  function Update-CurrentPath {
46
- $env:Path = "$NpmPrefix;$NodeDir;$env:Path"
45
+ if ($UseManagedNode) {
46
+ $env:Path = "$NodeDir;$env:Path"
47
+ }
48
+ $env:Path = "$NpmPrefix;$env:Path"
47
49
  }
48
50
 
49
- function Add-UserPathSegment([string] $Segment) {
51
+ function Update-UserPath {
50
52
  $currentUserPath = [Environment]::GetEnvironmentVariable('Path', 'User')
51
- if (-not $currentUserPath) {
52
- [Environment]::SetEnvironmentVariable('Path', $Segment, 'User')
53
- return
54
- }
55
-
56
- $parts = $currentUserPath -split ';' | Where-Object { $_ -ne '' }
57
- if ($parts -contains $Segment) {
58
- return
53
+ $parts = @($currentUserPath -split ';' | Where-Object { $_ -and $_ -notin @($LegacyNodeDir, $NodeDir, $NpmPrefix) })
54
+ if ($UseManagedNode) {
55
+ $parts = @($NodeDir) + $parts
59
56
  }
60
-
61
- [Environment]::SetEnvironmentVariable('Path', "$Segment;$currentUserPath", 'User')
57
+ [Environment]::SetEnvironmentVariable('Path', ((@($NpmPrefix) + $parts) -join ';'), 'User')
62
58
  }
63
59
 
64
- function Install-NodeV20 {
60
+ function Install-NodeV24 {
65
61
  $arch = Get-PlatformArch
66
- $baseUrl = 'https://nodejs.org/dist/latest-v20.x'
62
+ $baseUrl = 'https://nodejs.org/dist/latest-v24.x'
67
63
  $sumsUrl = "$baseUrl/SHASUMS256.txt"
68
64
 
69
65
  $tmpRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("anvil-install-" + [System.Guid]::NewGuid().ToString('N'))
@@ -73,7 +69,7 @@ function Install-NodeV20 {
73
69
  $sumsPath = Join-Path $tmpRoot 'SHASUMS256.txt'
74
70
  Invoke-WebRequest -UseBasicParsing -Uri $sumsUrl -OutFile $sumsPath
75
71
 
76
- $pattern = "node-v20\.[0-9]+\.[0-9]+-win-$arch\.zip$"
72
+ $pattern = "node-v24\.[0-9]+\.[0-9]+-win-$arch\.zip$"
77
73
  $archiveLine = Get-Content -LiteralPath $sumsPath | Where-Object { $_ -match $pattern } | Select-Object -First 1
78
74
  if (-not $archiveLine) {
79
75
  Fail "Could not resolve Node.js archive for win-$arch"
@@ -81,10 +77,16 @@ function Install-NodeV20 {
81
77
 
82
78
  $tokens = $archiveLine -split '\s+'
83
79
  $archiveName = $tokens[-1]
80
+ $latestVersion = ($archiveName -split '-')[1]
81
+ $nodeExe = Join-Path $NodeDir 'node.exe'
82
+ if ((Test-Path -LiteralPath $nodeExe) -and (Get-NodeVersion $nodeExe) -eq $latestVersion) {
83
+ Write-Info "Using current bundled Node.js $latestVersion"
84
+ return
85
+ }
84
86
  $archivePath = Join-Path $tmpRoot $archiveName
85
87
  $archiveUrl = "$baseUrl/$archiveName"
86
88
 
87
- Write-Info "Installing Node.js v20 for win-$arch..."
89
+ Write-Info "Installing Node.js $latestVersion for win-$arch..."
88
90
  Invoke-WebRequest -UseBasicParsing -Uri $archiveUrl -OutFile $archivePath
89
91
 
90
92
  $expectedHash = ($tokens | Where-Object { $_ -match '^[A-Fa-f0-9]{64}$' } | Select-Object -First 1)
@@ -95,16 +97,15 @@ function Install-NodeV20 {
95
97
  }
96
98
  }
97
99
 
98
- if (Test-Path -LiteralPath $NodeDir) {
99
- Remove-Item -LiteralPath $NodeDir -Recurse -Force
100
- }
101
-
102
100
  Expand-Archive -LiteralPath $archivePath -DestinationPath $tmpRoot -Force
103
- $expandedRoot = Get-ChildItem -LiteralPath $tmpRoot -Directory | Where-Object { $_.Name -like 'node-v20.*-win-*' } | Select-Object -First 1
101
+ $expandedRoot = Get-ChildItem -LiteralPath $tmpRoot -Directory | Where-Object { $_.Name -like 'node-v24.*-win-*' } | Select-Object -First 1
104
102
  if (-not $expandedRoot) {
105
103
  Fail 'Failed to locate extracted Node.js directory'
106
104
  }
107
105
 
106
+ if (Test-Path -LiteralPath $NodeDir) {
107
+ Remove-Item -LiteralPath $NodeDir -Recurse -Force
108
+ }
108
109
  Move-Item -LiteralPath $expandedRoot.FullName -Destination $NodeDir
109
110
  }
110
111
  finally {
@@ -115,24 +116,36 @@ function Install-NodeV20 {
115
116
  }
116
117
 
117
118
  function Ensure-Node {
118
- $major = Get-NodeMajorFromPath
119
- if ($major -and $major -ge $MinTargetMajor) {
120
- $version = (& node -v).Trim()
119
+ $nodeCommand = Get-Command node -ErrorAction SilentlyContinue
120
+ if ($nodeCommand -and $nodeCommand.CommandType -eq 'Application' -and (Split-Path -Parent $nodeCommand.Source) -in @($LegacyNodeDir, $NodeDir)) {
121
+ Install-NodeV24
122
+ return $true
123
+ }
124
+
125
+ $version = if ($nodeCommand) { Get-NodeVersion 'node' } else { '' }
126
+ $major = if ($version -match '^v(\d+)') { [int]$Matches[1] } else { $null }
127
+ if ($major -in @(22, 24, 26)) {
121
128
  Write-Info "Using existing Node.js $version"
122
- return
129
+ return $false
123
130
  }
124
131
 
125
- if ($major) {
126
- Write-Info "Existing Node.js major v$major is too old; installing Node.js v20 user-local"
132
+ if (-not $InstallNode) {
133
+ $found = if ($version) { "found Node.js $version" } elseif ($nodeCommand) { 'Node.js could not report its version' } else { 'Node.js was not found' }
134
+ Fail "Anvil CLI requires Node.js 22, 24 or 26 LTS; $found.
135
+ Install/update Node.js yourself: https://nodejs.org/en/download
136
+ Or install a private Node.js 24 copy and add it to PATH:
137
+ PowerShell: & ([scriptblock]::Create((irm https://anvil.works/install-cli.ps1))) -InstallNode
138
+ CMD: curl -fsSL https://anvil.works/install-cli.cmd -o install.cmd && install.cmd --install-node && del install.cmd"
127
139
  }
128
140
 
129
141
  Ensure-Directory -Path $AnvilHome
130
- Install-NodeV20
142
+ Install-NodeV24
143
+ return $true
131
144
  }
132
145
 
133
146
  function Ensure-Npm {
134
147
  $npmCmd = Join-Path $NodeDir 'npm.cmd'
135
- if (Test-Path -LiteralPath $npmCmd) {
148
+ if ($UseManagedNode -and (Test-Path -LiteralPath $npmCmd)) {
136
149
  return $npmCmd
137
150
  }
138
151
 
@@ -191,11 +204,10 @@ function Main {
191
204
  Ensure-Directory -Path $AnvilHome
192
205
  Ensure-Directory -Path $NpmPrefix
193
206
 
194
- Ensure-Node
207
+ $UseManagedNode = Ensure-Node
195
208
 
196
209
  Update-CurrentPath
197
- Add-UserPathSegment -Segment $NodeDir
198
- Add-UserPathSegment -Segment $NpmPrefix
210
+ Update-UserPath
199
211
 
200
212
  Warn-IfMissingGit
201
213
 
@@ -217,6 +229,10 @@ function Main {
217
229
  Fail "anvil installed but command verification failed: $($_.Exception.Message)"
218
230
  }
219
231
 
232
+ if (Test-Path -LiteralPath $LegacyNodeDir) {
233
+ Remove-Item -LiteralPath $LegacyNodeDir -Recurse -Force
234
+ }
235
+
220
236
  Write-Info ''
221
237
  Write-Info "anvil-cli installed successfully (v$version)"
222
238
  Write-Info "Next steps: run 'anvil configure' or 'anvil checkout'"
@@ -4,9 +4,12 @@
4
4
  set -eu
5
5
 
6
6
  ANVIL_HOME="${ANVIL_HOME:-$HOME/.anvil-cli}"
7
- NODE_DIR="$ANVIL_HOME/node-v20"
7
+ mkdir -p "$ANVIL_HOME"
8
+ ANVIL_HOME="$(cd "$ANVIL_HOME" && pwd -P)"
9
+ NODE_DIR="$ANVIL_HOME/node-v24"
8
10
  NPM_PREFIX="$ANVIL_HOME/npm-global"
9
- MIN_NODE_MAJOR=20
11
+ USE_MANAGED_NODE=1
12
+ INSTALL_NODE=0
10
13
 
11
14
  log() {
12
15
  printf '%s\n' "$*"
@@ -29,7 +32,10 @@ is_windows_posix() {
29
32
  }
30
33
 
31
34
  windows_posix_node_error() {
32
- fail "Windows Git Bash installs require existing Node.js v20+ and npm. Use PowerShell instead: irm https://anvil.works/install-cli.ps1 | iex"
35
+ fail "Windows Git Bash requires Node.js 22, 24 or 26 LTS and npm.
36
+ Install/update Node.js yourself: https://nodejs.org/en/download
37
+ Or use PowerShell to install a private Node.js 24 copy and add it to PATH:
38
+ & ([scriptblock]::Create((irm https://anvil.works/install-cli.ps1))) -InstallNode"
33
39
  }
34
40
 
35
41
  normalize_npm_prefix() {
@@ -66,15 +72,49 @@ cleanup_legacy_npm_prefix() {
66
72
  append_path_export() {
67
73
  profile_file="$1"
68
74
  if is_windows_posix; then
69
- line='export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"'
75
+ line='export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v24/bin:$PATH"'
76
+ if [ "${USE_MANAGED_NODE:-1}" -eq 0 ]; then
77
+ line='export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$PATH"'
78
+ fi
70
79
  else
71
- line='export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"'
80
+ line='export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v24/bin:$PATH"'
81
+ if [ "${USE_MANAGED_NODE:-1}" -eq 0 ]; then
82
+ line='export PATH="$HOME/.anvil-cli/npm-global/bin:$PATH"'
83
+ fi
84
+ fi
85
+
86
+ system_node_line="$line"
87
+ managed_node_line="$line"
88
+ if [ "$ANVIL_HOME" != "$(cd "$HOME" && pwd -P)/.anvil-cli" ]; then
89
+ saved_path="$NPM_PREFIX/bin"
90
+ if is_windows_posix; then
91
+ saved_path="$NPM_PREFIX:$saved_path"
92
+ fi
93
+ # Single-quote the actual custom location when saving it as shell code.
94
+ saved_path="$(printf '%s' "$saved_path" | sed "s/'/'\\\\''/g")"
95
+ saved_node_path="$(printf '%s' "$NODE_DIR/bin" | sed "s/'/'\\\\''/g")"
96
+ system_node_line="export PATH='$saved_path':\$PATH"
97
+ managed_node_line="export PATH='$saved_path:$saved_node_path':\$PATH"
98
+ line="$system_node_line"
99
+ if [ "${USE_MANAGED_NODE:-1}" -eq 1 ]; then
100
+ line="$managed_node_line"
101
+ fi
72
102
  fi
73
103
 
74
104
  [ -f "$profile_file" ] || touch "$profile_file"
75
- grep -F "$line" "$profile_file" >/dev/null 2>&1 || {
76
- printf '\n%s\n' "$line" >> "$profile_file"
77
- }
105
+ profile_tmp="$(mktemp)"
106
+ # Replace only the exact PATH exports written by these installers.
107
+ grep -Fvx \
108
+ -e 'export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"' \
109
+ -e 'export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"' \
110
+ -e 'export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v24/bin:$PATH"' \
111
+ -e 'export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v24/bin:$PATH"' \
112
+ -e 'export PATH="$HOME/.anvil-cli/npm-global/bin:$PATH"' \
113
+ -e 'export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$PATH"' \
114
+ -e "$system_node_line" -e "$managed_node_line" "$profile_file" > "$profile_tmp" || [ "$?" -eq 1 ]
115
+ printf '%s\n' "$line" >> "$profile_tmp"
116
+ cat "$profile_tmp" > "$profile_file"
117
+ rm -f "$profile_tmp"
78
118
  }
79
119
 
80
120
  persist_path_hint() {
@@ -109,26 +149,29 @@ detect_platform() {
109
149
  esac
110
150
  }
111
151
 
112
- node_version_major() {
113
- node -v 2>/dev/null | sed -E 's/^v([0-9]+).*/\1/'
114
- }
115
-
116
- install_node_v20() {
152
+ install_node_v24() {
117
153
  detect_platform
118
154
  need_cmd curl
119
155
  need_cmd tar
120
156
 
121
- base_url="https://nodejs.org/dist/latest-v20.x"
157
+ base_url="https://nodejs.org/dist/latest-v24.x"
122
158
  sums_url="$base_url/SHASUMS256.txt"
123
159
  tmp_dir="$(mktemp -d)"
124
160
  trap 'rm -rf "$tmp_dir"' EXIT INT TERM
125
161
 
126
- log "Installing Node.js v20 for $platform_os-$platform_arch..."
127
162
  curl -fsSL "$sums_url" -o "$tmp_dir/SHASUMS256.txt"
128
163
 
129
- archive_name="$(grep -E "node-v20\\.[0-9]+\\.[0-9]+-$platform_os-$platform_arch\\.tar\\.xz$" "$tmp_dir/SHASUMS256.txt" | awk '{print $2}' | head -n1)"
164
+ archive_name="$(grep -E "node-v24\\.[0-9]+\\.[0-9]+-$platform_os-$platform_arch\\.tar\\.xz$" "$tmp_dir/SHASUMS256.txt" | awk '{print $2}' | head -n1)"
130
165
  [ -n "$archive_name" ] || fail "Could not resolve Node.js archive for $platform_os-$platform_arch"
131
166
 
167
+ latest_version="${archive_name#node-}"
168
+ latest_version="${latest_version%-$platform_os-$platform_arch.tar.xz}"
169
+ if [ -x "$NODE_DIR/bin/node" ] && [ "$("$NODE_DIR/bin/node" -v)" = "$latest_version" ]; then
170
+ log "Using current bundled Node.js $latest_version"
171
+ return
172
+ fi
173
+
174
+ log "Installing Node.js $latest_version for $platform_os-$platform_arch..."
132
175
  archive_url="$base_url/$archive_name"
133
176
  archive_path="$tmp_dir/$archive_name"
134
177
 
@@ -146,37 +189,61 @@ install_node_v20() {
146
189
  log "Warning: no sha256 tool found; skipping checksum verification"
147
190
  fi
148
191
 
192
+ mkdir -p "$tmp_dir/node"
193
+ tar -xJf "$archive_path" -C "$tmp_dir/node" --strip-components=1
149
194
  rm -rf "$NODE_DIR"
150
- mkdir -p "$NODE_DIR"
151
- tar -xJf "$archive_path" -C "$NODE_DIR" --strip-components=1
195
+ mv "$tmp_dir/node" "$NODE_DIR"
152
196
  }
153
197
 
154
198
  ensure_node() {
199
+ found_version="Node.js was not found"
155
200
  if command -v node >/dev/null 2>&1; then
156
- major="$(node_version_major || true)"
157
- if [ -n "$major" ] && [ "$major" -ge "$MIN_NODE_MAJOR" ]; then
158
- log "Using existing Node.js $(node -v)"
159
- return
160
- fi
161
- if is_windows_posix; then
162
- windows_posix_node_error
163
- fi
164
- log "Existing Node.js $(node -v) is too old; installing Node.js v20 user-local"
165
- install_node_v20
166
- return
201
+ node_path="$(command -v node)"
202
+ case "$node_path" in
203
+ */*) node_path="$(cd "${node_path%/*}" && pwd -P)/${node_path##*/}" ;;
204
+ esac
205
+ case "$node_path" in
206
+ "$NODE_DIR/bin/node"|"$ANVIL_HOME/node-v20/bin/node"|"$NODE_DIR/node"|"$NODE_DIR/node.exe"|"$ANVIL_HOME/node-v20/node"|"$ANVIL_HOME/node-v20/node.exe")
207
+ if is_windows_posix; then
208
+ fail "Updating bundled Node.js on Windows requires PowerShell: irm https://anvil.works/install-cli.ps1 | iex"
209
+ fi
210
+ install_node_v24
211
+ return
212
+ ;;
213
+ esac
214
+ node_version="$(node -v 2>/dev/null)" || node_version=""
215
+ major="$(printf '%s\n' "$node_version" | sed -E 's/^v([0-9]+).*/\1/')"
216
+ case "$major" in
217
+ 22|24|26)
218
+ USE_MANAGED_NODE=0
219
+ log "Using existing Node.js $node_version"
220
+ return
221
+ ;;
222
+ esac
223
+ found_version="detected Node.js ${node_version:-(version unavailable)}"
167
224
  fi
168
225
 
169
226
  if is_windows_posix; then
170
227
  windows_posix_node_error
171
228
  fi
172
- install_node_v20
229
+ if [ "$INSTALL_NODE" -eq 1 ]; then
230
+ install_node_v24
231
+ return
232
+ fi
233
+ fail "Anvil CLI requires Node.js 22, 24 or 26 LTS; $found_version.
234
+ Install/update Node.js yourself: https://nodejs.org/en/download
235
+ Or install a private Node.js 24 copy and add it to PATH:
236
+ curl -fsSL https://anvil.works/install-cli.sh | sh -s -- --install-node"
173
237
  }
174
238
 
175
239
  configure_current_path() {
240
+ if [ "$USE_MANAGED_NODE" -eq 1 ]; then
241
+ PATH="$NODE_DIR/bin:$PATH"
242
+ fi
176
243
  if is_windows_posix; then
177
- export PATH="$NPM_PREFIX:$NPM_PREFIX/bin:$NODE_DIR/bin:$PATH"
244
+ export PATH="$NPM_PREFIX:$NPM_PREFIX/bin:$PATH"
178
245
  else
179
- export PATH="$NPM_PREFIX/bin:$NODE_DIR/bin:$PATH"
246
+ export PATH="$NPM_PREFIX/bin:$PATH"
180
247
  fi
181
248
  }
182
249
 
@@ -201,7 +268,13 @@ anvil_version() {
201
268
  }
202
269
 
203
270
  main() {
204
- mkdir -p "$ANVIL_HOME" "$NPM_PREFIX"
271
+ for arg in "$@"; do
272
+ case "$arg" in
273
+ --install-node) INSTALL_NODE=1 ;;
274
+ *) fail "Unknown option: $arg" ;;
275
+ esac
276
+ done
277
+ mkdir -p "$NPM_PREFIX"
205
278
 
206
279
  ensure_node
207
280
 
@@ -219,6 +292,8 @@ main() {
219
292
  fail "anvil installed but command not found on PATH"
220
293
  fi
221
294
 
295
+ rm -rf "$ANVIL_HOME/node-v20"
296
+
222
297
  log ""
223
298
  log "anvil-cli installed successfully${version:+ (v$version)}"
224
299
  log "Next steps: run 'anvil configure' or 'anvil checkout'"