@anvil-works/anvil-cli 0.6.1 → 0.6.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvil-works/anvil-cli",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "CLI tool for developing Anvil apps locally",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/api.d.ts",
@@ -151,6 +151,42 @@ function Warn-IfMissingGit {
151
151
  }
152
152
  }
153
153
 
154
+ function Repair-LegacyNpmPrefix([string] $NpmCommand) {
155
+ try {
156
+ $currentPrefix = (& $NpmCommand config get prefix).Trim()
157
+ }
158
+ catch {
159
+ return
160
+ }
161
+
162
+ if ($currentPrefix -eq $NpmPrefix) {
163
+ Write-Info "Detected legacy anvil npm prefix in user config; restoring npm default prefix behavior."
164
+ try {
165
+ & $NpmCommand config delete prefix --location=user | Out-Null
166
+ }
167
+ catch {
168
+ # Best effort cleanup; install proceeds with process-local prefix either way.
169
+ }
170
+ }
171
+ }
172
+
173
+ function Install-AnvilCli([string] $NpmCommand) {
174
+ $previousPrefix = $env:NPM_CONFIG_PREFIX
175
+ $env:NPM_CONFIG_PREFIX = $NpmPrefix
176
+
177
+ try {
178
+ & $NpmCommand install -g @anvil-works/anvil-cli@latest
179
+ }
180
+ finally {
181
+ if ($null -eq $previousPrefix) {
182
+ Remove-Item Env:NPM_CONFIG_PREFIX -ErrorAction SilentlyContinue
183
+ }
184
+ else {
185
+ $env:NPM_CONFIG_PREFIX = $previousPrefix
186
+ }
187
+ }
188
+ }
189
+
154
190
  function Main {
155
191
  Ensure-Directory -Path $AnvilHome
156
192
  Ensure-Directory -Path $NpmPrefix
@@ -164,10 +200,10 @@ function Main {
164
200
  Warn-IfMissingGit
165
201
 
166
202
  $npm = Ensure-Npm
203
+ Repair-LegacyNpmPrefix -NpmCommand $npm
167
204
 
168
205
  Write-Info 'Installing anvil-cli...'
169
- & $npm config set prefix "$NpmPrefix"
170
- & $npm install -g @anvil-works/anvil-cli@latest
206
+ Install-AnvilCli -NpmCommand $npm
171
207
 
172
208
  $anvilCmd = Join-Path $NpmPrefix 'anvil.cmd'
173
209
  if (-not (Test-Path -LiteralPath $anvilCmd)) {
@@ -21,6 +21,27 @@ need_cmd() {
21
21
  command -v "$1" >/dev/null 2>&1 || fail "Required command not found: $1"
22
22
  }
23
23
 
24
+ is_windows_posix() {
25
+ case "$(uname -s 2>/dev/null || true)" in
26
+ MINGW*|MSYS*|CYGWIN*) return 0 ;;
27
+ *) return 1 ;;
28
+ esac
29
+ }
30
+
31
+ 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"
33
+ }
34
+
35
+ normalize_npm_prefix() {
36
+ prefix="$1"
37
+ if is_windows_posix && command -v cygpath >/dev/null 2>&1; then
38
+ cygpath -u "$prefix" 2>/dev/null || printf '%s\n' "$prefix"
39
+ return
40
+ fi
41
+
42
+ printf '%s\n' "$prefix"
43
+ }
44
+
24
45
  warn_if_missing_git() {
25
46
  if ! command -v git >/dev/null 2>&1; then
26
47
  log "Warning: git was not found on PATH."
@@ -29,9 +50,26 @@ warn_if_missing_git() {
29
50
  fi
30
51
  }
31
52
 
53
+ cleanup_legacy_npm_prefix() {
54
+ current_prefix="$(npm config get prefix 2>/dev/null | tr -d '\r' || true)"
55
+ [ -n "$current_prefix" ] || return 0
56
+
57
+ legacy_prefix="$NPM_PREFIX"
58
+ normalized_current_prefix="$(normalize_npm_prefix "$current_prefix")"
59
+ normalized_legacy_prefix="$(normalize_npm_prefix "$legacy_prefix")"
60
+ if [ "$current_prefix" = "$legacy_prefix" ] || [ "$normalized_current_prefix" = "$normalized_legacy_prefix" ]; then
61
+ log "Detected legacy anvil npm prefix in user config; restoring npm default prefix behavior."
62
+ npm config delete prefix --location=user >/dev/null 2>&1 || true
63
+ fi
64
+ }
65
+
32
66
  append_path_export() {
33
67
  profile_file="$1"
34
- line='export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"'
68
+ 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"'
70
+ else
71
+ line='export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"'
72
+ fi
35
73
 
36
74
  [ -f "$profile_file" ] || touch "$profile_file"
37
75
  grep -F "$line" "$profile_file" >/dev/null 2>&1 || {
@@ -120,37 +158,64 @@ ensure_node() {
120
158
  log "Using existing Node.js $(node -v)"
121
159
  return
122
160
  fi
161
+ if is_windows_posix; then
162
+ windows_posix_node_error
163
+ fi
123
164
  log "Existing Node.js $(node -v) is too old; installing Node.js v20 user-local"
124
165
  install_node_v20
125
166
  return
126
167
  fi
127
168
 
169
+ if is_windows_posix; then
170
+ windows_posix_node_error
171
+ fi
128
172
  install_node_v20
129
173
  }
130
174
 
131
- main() {
132
- need_cmd curl
133
- need_cmd tar
175
+ configure_current_path() {
176
+ if is_windows_posix; then
177
+ export PATH="$NPM_PREFIX:$NPM_PREFIX/bin:$NODE_DIR/bin:$PATH"
178
+ else
179
+ export PATH="$NPM_PREFIX/bin:$NODE_DIR/bin:$PATH"
180
+ fi
181
+ }
182
+
183
+ anvil_version() {
184
+ if command -v anvil >/dev/null 2>&1 && anvil --version 2>/dev/null; then
185
+ return 0
186
+ fi
187
+
188
+ if [ -f "$NPM_PREFIX/anvil" ] && "$NPM_PREFIX/anvil" --version 2>/dev/null; then
189
+ return 0
190
+ fi
191
+
192
+ if [ -f "$NPM_PREFIX/anvil.cmd" ] && "$NPM_PREFIX/anvil.cmd" --version 2>/dev/null; then
193
+ return 0
194
+ fi
195
+
196
+ if [ -x "$NPM_PREFIX/bin/anvil" ] && "$NPM_PREFIX/bin/anvil" --version 2>/dev/null; then
197
+ return 0
198
+ fi
134
199
 
200
+ return 1
201
+ }
202
+
203
+ main() {
135
204
  mkdir -p "$ANVIL_HOME" "$NPM_PREFIX"
136
205
 
137
206
  ensure_node
138
207
 
139
- export PATH="$NPM_PREFIX/bin:$NODE_DIR/bin:$PATH"
208
+ configure_current_path
140
209
  persist_path_hint
141
210
 
142
211
  need_cmd npm
212
+ cleanup_legacy_npm_prefix
143
213
  warn_if_missing_git
144
214
 
145
215
  log "Installing anvil-cli..."
146
- npm config set prefix "$NPM_PREFIX" >/dev/null
147
216
  NPM_CONFIG_PREFIX="$NPM_PREFIX" npm install -g @anvil-works/anvil-cli@latest
148
217
 
149
- if command -v anvil >/dev/null 2>&1; then
150
- version="$(anvil --version 2>/dev/null || true)"
151
- elif [ -x "$NPM_PREFIX/bin/anvil" ]; then
152
- version="$($NPM_PREFIX/bin/anvil --version 2>/dev/null || true)"
153
- else
218
+ if ! version="$(anvil_version)"; then
154
219
  fail "anvil installed but command not found on PATH"
155
220
  fi
156
221