@anvil-works/anvil-cli 0.6.1-canary.0 → 0.6.2

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-canary.0",
3
+ "version": "0.6.2",
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)) {
@@ -29,6 +29,17 @@ warn_if_missing_git() {
29
29
  fi
30
30
  }
31
31
 
32
+ cleanup_legacy_npm_prefix() {
33
+ current_prefix="$(npm config get prefix 2>/dev/null || true)"
34
+ [ -n "$current_prefix" ] || return 0
35
+
36
+ legacy_prefix="$NPM_PREFIX"
37
+ if [ "$current_prefix" = "$legacy_prefix" ]; then
38
+ log "Detected legacy anvil npm prefix in user config; restoring npm default prefix behavior."
39
+ npm config delete prefix --location=user >/dev/null 2>&1 || true
40
+ fi
41
+ }
42
+
32
43
  append_path_export() {
33
44
  profile_file="$1"
34
45
  line='export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"'
@@ -42,7 +53,8 @@ append_path_export() {
42
53
  persist_path_hint() {
43
54
  append_path_export "$HOME/.profile"
44
55
 
45
- shell_name="${SHELL##*/}"
56
+ shell_name="${SHELL:-}"
57
+ shell_name="${shell_name##*/}"
46
58
 
47
59
  if [ -n "${ZSH_VERSION:-}" ] || [ "$shell_name" = "zsh" ] || [ -f "$HOME/.zshrc" ]; then
48
60
  append_path_export "$HOME/.zshrc"
@@ -139,10 +151,10 @@ main() {
139
151
  persist_path_hint
140
152
 
141
153
  need_cmd npm
154
+ cleanup_legacy_npm_prefix
142
155
  warn_if_missing_git
143
156
 
144
157
  log "Installing anvil-cli..."
145
- npm config set prefix "$NPM_PREFIX" >/dev/null
146
158
  NPM_CONFIG_PREFIX="$NPM_PREFIX" npm install -g @anvil-works/anvil-cli@latest
147
159
 
148
160
  if command -v anvil >/dev/null 2>&1; then