Skip to content

Commit 6776ce8

Browse files
committed
fix(install): only cleanup semver-format version directories
The cleanup_old_versions function was deleting non-semver directories like 'local-dev' when they had the oldest birth time and there were 5+ other versions. This caused intermittent failures in bootstrap-cli when the binary was deleted between install and setup_node_manager. Fix: Only consider directories matching semver format (X.Y.Z or X.Y.Z-prerelease) for cleanup, naturally preserving 'current' symlink and development directories like 'local-dev'.
1 parent 1944f16 commit 6776ce8

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

.github/workflows/test-standalone-install.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
run: |
7575
# Verify bin directory was created by vp env --setup
7676
BIN_PATH="$HOME/.vite-plus/bin"
77+
ls -al "$BIN_PATH"
7778
if [ ! -d "$BIN_PATH" ]; then
7879
echo "Error: Bin directory not found: $BIN_PATH"
7980
exit 1
@@ -93,6 +94,11 @@ jobs:
9394
vp env doctor
9495
vp env run --node 24 -- node -p "process.versions"
9596
97+
which node
98+
which npm
99+
which npx
100+
which vp
101+
96102
test-install-sh-arm64:
97103
name: Test install.sh (Linux ARM64 glibc via QEMU)
98104
runs-on: ubuntu-latest
@@ -165,7 +171,7 @@ jobs:
165171
run: |
166172
& ./packages/global/install.ps1
167173
168-
- name: Verify installation
174+
- name: Verify installation on powershell
169175
shell: pwsh
170176
working-directory: ${{ runner.temp }}
171177
run: |
@@ -178,11 +184,12 @@ jobs:
178184
vp new create-vite --no-interactive --no-agent -- hello --no-interactive -t vanilla
179185
cd hello && vp run build
180186
181-
- name: Verify bin setup
187+
- name: Verify bin setup on powershell
182188
shell: pwsh
183189
run: |
184190
# Verify bin directory was created by vp env --setup
185191
$binPath = "$env:USERPROFILE\.vite-plus\bin"
192+
Get-ChildItem -Force $binPath
186193
if (-not (Test-Path $binPath)) {
187194
Write-Error "Bin directory not found: $binPath"
188195
exit 1
@@ -198,6 +205,10 @@ jobs:
198205
}
199206
Write-Host "Found shim: $shimFile"
200207
}
208+
where.exe node
209+
where.exe npm
210+
where.exe npx
211+
where.exe vp
201212
202213
# Verify vp env doctor works
203214
$env:Path = "$env:USERPROFILE\.vite-plus\bin;$env:Path"

packages/global/install.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,11 @@ function Cleanup-OldVersions {
170170
param([string]$InstallDir)
171171

172172
$maxVersions = 5
173+
# Only cleanup semver format directories (0.1.0, 1.2.3-beta.1, etc.)
174+
# This excludes 'current' symlink and non-semver directories like 'local-dev'
175+
$semverPattern = '^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$'
173176
$versions = Get-ChildItem -Path $InstallDir -Directory -ErrorAction SilentlyContinue |
174-
Where-Object { $_.Name -ne "current" }
177+
Where-Object { $_.Name -match $semverPattern }
175178

176179
if ($null -eq $versions -or $versions.Count -le $maxVersions) {
177180
return

packages/global/install.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,13 @@ cleanup_old_versions() {
452452
local max_versions=5
453453
local versions=()
454454

455-
# List version directories (exclude 'current' symlink)
455+
# List version directories (only semver format like 0.1.0, 1.2.3-beta.1)
456+
# This excludes 'current' symlink and non-semver directories like 'local-dev'
457+
local semver_regex='^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$'
456458
for dir in "$INSTALL_DIR"/*/; do
457459
local name
458460
name=$(basename "$dir")
459-
if [ "$name" != "current" ] && [ -d "$dir" ]; then
461+
if [ -d "$dir" ] && [[ "$name" =~ $semver_regex ]]; then
460462
versions+=("$dir")
461463
fi
462464
done

0 commit comments

Comments
 (0)