diff --git a/crates/vite_setup/src/lib.rs b/crates/vite_setup/src/lib.rs index 4db53f84a1..c2e5d4a494 100644 --- a/crates/vite_setup/src/lib.rs +++ b/crates/vite_setup/src/lib.rs @@ -22,7 +22,7 @@ pub mod platform; pub mod registry; /// Maximum number of old versions to keep. -pub const MAX_VERSIONS_KEEP: usize = 5; +pub const MAX_VERSIONS_KEEP: usize = 3; /// Platform-specific binary name for the `vp` CLI. pub const VP_BINARY_NAME: &str = if cfg!(windows) { "vp.exe" } else { "vp" }; diff --git a/docs/guide/upgrade.md b/docs/guide/upgrade.md index 9b5c48e328..2902b33af6 100644 --- a/docs/guide/upgrade.md +++ b/docs/guide/upgrade.md @@ -14,9 +14,20 @@ You can upgrade both of them independently. ## Global `vp` ```bash -vp upgrade +vp upgrade # upgrade to the latest version +vp upgrade --check # check for updates without installing ``` +### Rollback + +Vite+ keeps the **3 most recent** versions installed so you can revert quickly: + +```bash +vp upgrade --rollback +``` + +Older versions are pruned automatically after each upgrade. The active version and the previous version are always kept, so a rollback target is never removed. + ## Local `vite-plus` Update the project dependency with the package manager commands in Vite+: diff --git a/packages/cli/install.ps1 b/packages/cli/install.ps1 index 33454c7a94..31ad7925a9 100644 --- a/packages/cli/install.ps1 +++ b/packages/cli/install.ps1 @@ -240,7 +240,7 @@ function Download-AndExtract { function Cleanup-OldVersions { param([string]$InstallDir) - $maxVersions = 5 + $maxVersions = 3 # Only cleanup semver format directories (0.1.0, 1.2.3-beta.1, etc.) # This excludes 'current' symlink and non-semver directories like 'local-dev' $semverPattern = '^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$' diff --git a/packages/cli/install.sh b/packages/cli/install.sh index da733e1157..0424696b0d 100644 --- a/packages/cli/install.sh +++ b/packages/cli/install.sh @@ -801,7 +801,7 @@ setup_node_manager() { # Cleanup old versions, keeping only the most recent ones cleanup_old_versions() { - local max_versions=5 + local max_versions=3 local versions=() # List version directories (semver format like 0.1.0, 1.2.3-beta.1, 0.0.0-f48af939.20260205-0533) diff --git a/rfcs/global-cli-rust-binary.md b/rfcs/global-cli-rust-binary.md index 9153948d15..86c471a829 100644 --- a/rfcs/global-cli-rust-binary.md +++ b/rfcs/global-cli-rust-binary.md @@ -751,7 +751,7 @@ main_url="${NPM_REGISTRY}/vite-plus-cli/-/vite-plus-cli-${VITE_PLUS_VERSION}.tgz # Create/update current symlink ln -sfn "$VITE_PLUS_VERSION" "$CURRENT_LINK" -# Cleanup old versions (keep max 5) +# Cleanup old versions (keep max 3) cleanup_old_versions # Add ~/.vite-plus/current/bin to PATH @@ -803,7 +803,7 @@ if (Test-Path $CurrentLink) { } cmd /c mklink /J "$CurrentLink" "$VersionDir" | Out-Null -# Cleanup old versions (keep max 5) +# Cleanup old versions (keep max 3) Cleanup-OldVersions -InstallDir $InstallDir # Add $InstallDir\current\bin to user PATH @@ -853,7 +853,7 @@ The installer supports multiple versions with symlinks, allowing version switchi - PATH points to `~/.vite-plus/current/bin` (stable location) - Installing a new version updates the `current` symlink -- Old versions are automatically cleaned up (keeps max 5 versions) +- Old versions are automatically cleaned up (keeps max 3 versions) #### How the Rust Binary Uses JS Scripts diff --git a/rfcs/upgrade-command.md b/rfcs/upgrade-command.md index 6e379119a3..711c0422c5 100644 --- a/rfcs/upgrade-command.md +++ b/rfcs/upgrade-command.md @@ -38,7 +38,7 @@ Key invariant: `~/.vite-plus/bin/vp` is a symlink to `../current/bin/vp` (Unix) 1. Provide a fast, reliable `vp upgrade` command that upgrades the CLI to the latest (or specified) version 2. Reuse the same npm-based distribution channel (no new infrastructure) 3. Support atomic upgrades with automatic rollback on failure -4. Keep the last 5 versions for manual rollback +4. Keep the last 3 versions for manual rollback 5. Support version pinning and channel selection (latest, test) ## Non-Goals @@ -161,7 +161,7 @@ The upgrade command is implemented entirely in Rust within the `vite_global_cli` │ 6. Install production dependencies │ │ 7. Atomic swap: current → {version} │ │ 8. Refresh shims (non-fatal) │ -│ 9. Cleanup old versions (non-fatal, keep 5) │ +│ 9. Cleanup old versions (non-fatal, keep 3) │ └─────────────────────────────────────────────────┘ ``` @@ -303,7 +303,7 @@ Key differences on Windows: After the symlink swap (the **point of no return**), post-update operations are treated as non-fatal. Errors are printed to stderr as warnings but do not trigger the outer error handler (which would delete the now-active version directory). 1. **Refresh shims**: Run the equivalent of `vp env setup --refresh` to ensure node/npm/npx shims point to the new version. This also refreshes trampoline `.exe` files for globally installed package shims (e.g., `corepack.exe`, `tsc.exe`) by scanning `BinConfig` entries. If this fails, the user can run it manually. -2. **Cleanup old versions**: Remove old version directories, keeping the 5 most recent by **creation time** (matching `install.sh` behavior). The new version and the previous version are always protected from cleanup, even if they fall outside the top 5 (e.g., after a downgrade via `--rollback`). +2. **Cleanup old versions**: Remove old version directories, keeping the 3 most recent by **creation time** (matching `install.sh` behavior). The new version and the previous version are always protected from cleanup, even if they fall outside the top 3 (e.g., after a downgrade via `--rollback`). #### Step 7: Running Binary Consideration @@ -501,15 +501,15 @@ Upgrade { - Users can opt into periodic checks via their own cron/launchd if desired - This can be revisited as a future enhancement with proper opt-in -### 5. Keep 5 Versions for Rollback +### 5. Keep 3 Versions for Rollback -**Decision**: Maintain the same cleanup policy as `install.sh` (keep 5 most recent versions by creation time, with protected versions). +**Decision**: Maintain the same cleanup policy as `install.sh` (keep 3 most recent versions by creation time, with protected versions). **Rationale**: - Consistent with existing `install.sh` behavior (sorts by creation time, not semver) - Provides rollback safety net without unbounded disk usage -- Each version is ~20-30MB, so 5 versions is ~100-150MB total +- Each version is ~20-30MB, so 3 versions is ~60-90MB total - The active version and previous version are always protected from cleanup, preventing accidental deletion after a downgrade ## Implementation Phases @@ -522,7 +522,7 @@ Upgrade { - `vp upgrade ` — installs a specific version - `--tag`, `--force`, `--silent` flags - Platform detection, npm registry query, download, extract, symlink swap -- Version cleanup (keep 5) +- Version cleanup (keep 3) - Error handling with clean rollback **Files to create/modify:** @@ -542,7 +542,7 @@ Upgrade { - [ ] Downloaded tarballs are verified against npm registry `integrity` (SHA-512) - [ ] Running binary is not affected during update - [ ] Failed update leaves the current installation untouched -- [ ] Old versions are cleaned up (max 5 retained) +- [ ] Old versions are cleaned up (max 3 retained) - [ ] Works on macOS, Linux, and Windows ### Phase 1 (P1): Rollback and Check diff --git a/rfcs/windows-installer.md b/rfcs/windows-installer.md index 43f6c03c8e..80737430aa 100644 --- a/rfcs/windows-installer.md +++ b/rfcs/windows-installer.md @@ -265,7 +265,7 @@ The installer replicates the same result as `install.ps1`, implemented in Rust v │ │ (junction on Windows, │ │ │ atomic symlink on Unix) │ │ │ │ -│ └─ cleanup old versions ── keep last 5 by creation time │ +│ └─ cleanup old versions ── keep last 3 by creation time │ │ protects new + previous version │ └─────────────────────────────────────────────────────────────┘ │