Skip to content

Commit 6a5246a

Browse files
authored
chore(install): reduce retained vp versions from 5 to 3 (#1716)
## What Lower the global `vp` version-retention limit from **5 → 3** across all three install paths that manage `~/.vite-plus`: | Path | Location | |------|----------| | Rust (installer binary + `vp upgrade`) | `crates/vite_setup/src/lib.rs` — `MAX_VERSIONS_KEEP` | | Shell bootstrap (`curl … \| sh`) | `packages/cli/install.sh` — `max_versions` | | PowerShell bootstrap (`irm … \| iex`) | `packages/cli/install.ps1` — `$maxVersions` | ## Why The `5` was an undocumented default. Keeping 3 cuts `~/.vite-plus` disk usage (~60–90MB instead of ~100–150MB) while still leaving rollback headroom. The cleanup logic is fully parameterized and the **protected-versions safeguard is unchanged** — the active and previous versions are never pruned regardless of the limit, so a downgrade/rollback target is always preserved. Behavior change applies to **future** cleanup runs only (next install / `vp upgrade`); it does not retroactively prune existing machines. ## Also updated - **RFCs** synced to the new number: `rfcs/global-cli-rust-binary.md`, `rfcs/upgrade-command.md` (incl. the disk-math line), `rfcs/windows-installer.md`. - **Docs**: added a concise *Rollback* section to `docs/guide/upgrade.md` documenting the 3-version retention and `vp upgrade --rollback`. ## Testing - `cargo test -p vite_setup` → 14/14 passing. The existing `cleanup_old_versions` tests pass explicit `max_keep` values, so they exercise the generic logic independently of the constant. - Doc/RFC edits are text-only. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Config and documentation only; cleanup semantics and protected-version safeguards are unchanged, so rollback safety is preserved with slightly less disk headroom. > > **Overview** > **Retained global `vp` versions drop from 5 → 3** everywhere post-install cleanup runs: `MAX_VERSIONS_KEEP` in `vite_setup` (used by `vp upgrade` and `vp-setup.exe`), plus `max_versions` / `$maxVersions` in `install.sh` and `install.ps1`. Pruning still only targets semver dirs under `~/.vite-plus`; **active and previous versions stay protected** for rollback—the limit only caps how many *other* old copies remain. > > **Docs:** `docs/guide/upgrade.md` now documents `vp upgrade --check`, a **Rollback** subsection (`vp upgrade --rollback`, 3-version retention), and clarifies upgrade command examples. > > **RFCs** (`global-cli-rust-binary`, `upgrade-command`, `windows-installer`) are updated to say “keep max 3” and the lower disk estimate (~60–90MB vs ~100–150MB). Behavior change applies on the **next** install or upgrade, not as a one-time migration on existing machines. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b933a20. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 7501b30 commit 6a5246a

7 files changed

Lines changed: 27 additions & 16 deletions

File tree

crates/vite_setup/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub mod platform;
2222
pub mod registry;
2323

2424
/// Maximum number of old versions to keep.
25-
pub const MAX_VERSIONS_KEEP: usize = 5;
25+
pub const MAX_VERSIONS_KEEP: usize = 3;
2626

2727
/// Platform-specific binary name for the `vp` CLI.
2828
pub const VP_BINARY_NAME: &str = if cfg!(windows) { "vp.exe" } else { "vp" };

docs/guide/upgrade.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ You can upgrade both of them independently.
1414
## Global `vp`
1515

1616
```bash
17-
vp upgrade
17+
vp upgrade # upgrade to the latest version
18+
vp upgrade --check # check for updates without installing
1819
```
1920

21+
### Rollback
22+
23+
Vite+ keeps the **3 most recent** versions installed so you can revert quickly:
24+
25+
```bash
26+
vp upgrade --rollback
27+
```
28+
29+
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.
30+
2031
## Local `vite-plus`
2132

2233
Update the project dependency with the package manager commands in Vite+:

packages/cli/install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function Download-AndExtract {
240240
function Cleanup-OldVersions {
241241
param([string]$InstallDir)
242242

243-
$maxVersions = 5
243+
$maxVersions = 3
244244
# Only cleanup semver format directories (0.1.0, 1.2.3-beta.1, etc.)
245245
# This excludes 'current' symlink and non-semver directories like 'local-dev'
246246
$semverPattern = '^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$'

packages/cli/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ setup_node_manager() {
801801

802802
# Cleanup old versions, keeping only the most recent ones
803803
cleanup_old_versions() {
804-
local max_versions=5
804+
local max_versions=3
805805
local versions=()
806806

807807
# List version directories (semver format like 0.1.0, 1.2.3-beta.1, 0.0.0-f48af939.20260205-0533)

rfcs/global-cli-rust-binary.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ main_url="${NPM_REGISTRY}/vite-plus-cli/-/vite-plus-cli-${VITE_PLUS_VERSION}.tgz
751751
# Create/update current symlink
752752
ln -sfn "$VITE_PLUS_VERSION" "$CURRENT_LINK"
753753
754-
# Cleanup old versions (keep max 5)
754+
# Cleanup old versions (keep max 3)
755755
cleanup_old_versions
756756
757757
# Add ~/.vite-plus/current/bin to PATH
@@ -803,7 +803,7 @@ if (Test-Path $CurrentLink) {
803803
}
804804
cmd /c mklink /J "$CurrentLink" "$VersionDir" | Out-Null
805805
806-
# Cleanup old versions (keep max 5)
806+
# Cleanup old versions (keep max 3)
807807
Cleanup-OldVersions -InstallDir $InstallDir
808808
809809
# Add $InstallDir\current\bin to user PATH
@@ -853,7 +853,7 @@ The installer supports multiple versions with symlinks, allowing version switchi
853853
854854
- PATH points to `~/.vite-plus/current/bin` (stable location)
855855
- Installing a new version updates the `current` symlink
856-
- Old versions are automatically cleaned up (keeps max 5 versions)
856+
- Old versions are automatically cleaned up (keeps max 3 versions)
857857
858858
#### How the Rust Binary Uses JS Scripts
859859

rfcs/upgrade-command.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Key invariant: `~/.vite-plus/bin/vp` is a symlink to `../current/bin/vp` (Unix)
3838
1. Provide a fast, reliable `vp upgrade` command that upgrades the CLI to the latest (or specified) version
3939
2. Reuse the same npm-based distribution channel (no new infrastructure)
4040
3. Support atomic upgrades with automatic rollback on failure
41-
4. Keep the last 5 versions for manual rollback
41+
4. Keep the last 3 versions for manual rollback
4242
5. Support version pinning and channel selection (latest, test)
4343

4444
## Non-Goals
@@ -161,7 +161,7 @@ The upgrade command is implemented entirely in Rust within the `vite_global_cli`
161161
│ 6. Install production dependencies │
162162
│ 7. Atomic swap: current → {version} │
163163
│ 8. Refresh shims (non-fatal) │
164-
│ 9. Cleanup old versions (non-fatal, keep 5) │
164+
│ 9. Cleanup old versions (non-fatal, keep 3) │
165165
└─────────────────────────────────────────────────┘
166166
```
167167

@@ -303,7 +303,7 @@ Key differences on Windows:
303303
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).
304304

305305
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.
306-
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`).
306+
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`).
307307

308308
#### Step 7: Running Binary Consideration
309309

@@ -501,15 +501,15 @@ Upgrade {
501501
- Users can opt into periodic checks via their own cron/launchd if desired
502502
- This can be revisited as a future enhancement with proper opt-in
503503

504-
### 5. Keep 5 Versions for Rollback
504+
### 5. Keep 3 Versions for Rollback
505505

506-
**Decision**: Maintain the same cleanup policy as `install.sh` (keep 5 most recent versions by creation time, with protected versions).
506+
**Decision**: Maintain the same cleanup policy as `install.sh` (keep 3 most recent versions by creation time, with protected versions).
507507

508508
**Rationale**:
509509

510510
- Consistent with existing `install.sh` behavior (sorts by creation time, not semver)
511511
- Provides rollback safety net without unbounded disk usage
512-
- Each version is ~20-30MB, so 5 versions is ~100-150MB total
512+
- Each version is ~20-30MB, so 3 versions is ~60-90MB total
513513
- The active version and previous version are always protected from cleanup, preventing accidental deletion after a downgrade
514514

515515
## Implementation Phases
@@ -522,7 +522,7 @@ Upgrade {
522522
- `vp upgrade <version>` — installs a specific version
523523
- `--tag`, `--force`, `--silent` flags
524524
- Platform detection, npm registry query, download, extract, symlink swap
525-
- Version cleanup (keep 5)
525+
- Version cleanup (keep 3)
526526
- Error handling with clean rollback
527527

528528
**Files to create/modify:**
@@ -542,7 +542,7 @@ Upgrade {
542542
- [ ] Downloaded tarballs are verified against npm registry `integrity` (SHA-512)
543543
- [ ] Running binary is not affected during update
544544
- [ ] Failed update leaves the current installation untouched
545-
- [ ] Old versions are cleaned up (max 5 retained)
545+
- [ ] Old versions are cleaned up (max 3 retained)
546546
- [ ] Works on macOS, Linux, and Windows
547547

548548
### Phase 1 (P1): Rollback and Check

rfcs/windows-installer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ The installer replicates the same result as `install.ps1`, implemented in Rust v
265265
│ │ (junction on Windows, │
266266
│ │ atomic symlink on Unix) │
267267
│ │ │
268-
│ └─ cleanup old versions ── keep last 5 by creation time │
268+
│ └─ cleanup old versions ── keep last 3 by creation time │
269269
│ protects new + previous version │
270270
└─────────────────────────────────────────────────────────────┘
271271

0 commit comments

Comments
 (0)