Skip to content

Commit 23d7e68

Browse files
authored
feat(install): support VP_PR_VERSION for pkg.pr.new testing (#1578)
## Summary Add `VP_PR_VERSION` env var to both `install.sh` and `install.ps1` so users can install an unreleased PR build (or any commit) via pkg.pr.new for temporary testing. Since npm releases only ship from `main`, pkg.pr.new is the only available testing channel for in-flight changes. When `VP_PR_VERSION` is set, the installer: - Bypasses the npm registry (no metadata fetch) - Downloads the CLI platform tarball from `https://pkg.pr.new/voidzero-dev/vite-plus/@voidzero-dev/vite-plus-cli-{platform}@{PR_or_SHA}` - Writes `vite-plus` in the wrapper `package.json` as `https://pkg.pr.new/voidzero-dev/vite-plus@{PR_or_SHA}` — the published pkg.pr.new tarball already rewrites scoped workspace deps to matching pkg.pr.new URLs by commit SHA, so pnpm pulls in a coherent PR build. - Installs into `~/.vite-plus/pkg-pr-new-{PR_or_SHA}/` — a non-semver dir name so `cleanup_old_versions` won't auto-delete it. - Errors early if combined with `VP_LOCAL_TGZ`. ## Usage ```bash # bash / macOS / Linux curl -fsSL https://vite.plus | VP_PR_VERSION=1569 bash ``` ```powershell # Windows $env:VP_PR_VERSION = "1569"; irm https://vite.plus/ps1 | iex ``` `VP_PR_VERSION` accepts either a PR number (e.g. `1569`) or a commit SHA. ## Test plan End-to-end verified against #1569 in a sandboxed `HOME`: - [x] `vp --version` reports `v0.0.0-pkg-pr-new.c178e90` (matches PR #1569 commit) - [x] `node_modules/vite-plus/package.json` version matches the PR build - [x] Transitive `@voidzero-dev/vite-plus-core` resolves via pkg.pr.new URL with the same commit SHA - [x] `pnpm-lock.yaml` records `vite-plus.specifier: https://pkg.pr.new/voidzero-dev/vite-plus@1569` - [x] Normal (no `VP_PR_VERSION`) flow unchanged — still hits npm registry - [x] `VP_PR_VERSION` + `VP_LOCAL_TGZ` errors early as expected - [x] `bash -n` passes on `install.sh` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes the installation path and download sources in the cross-platform installers, which could break installs or pull unintended artifacts if the new URL construction/branching logic is wrong. Scope is limited to `install.sh`/`install.ps1` and guarded by an opt-in env var. > > **Overview** > Adds `VP_PR_VERSION` to `install.sh` and `install.ps1` to install unreleased PR/commit builds via `pkg.pr.new`, bypassing npm metadata/version resolution. > > When set, the installers (1) refuse to run alongside `VP_LOCAL_TGZ`, (2) download the platform CLI tarball from `pkg.pr.new`, (3) install into a synthetic non-semver version directory (`pkg-pr-new-...`) to avoid old-version cleanup, and (4) write the wrapper `package.json` dependency as a `pkg.pr.new` URL so `pnpm` pulls a coherent PR build of `vite-plus` and its workspace deps. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 247c17e. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 5a40c19 commit 23d7e68

2 files changed

Lines changed: 62 additions & 8 deletions

File tree

packages/cli/install.ps1

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# VP_HOME - Installation directory (default: $env:USERPROFILE\.vite-plus)
1010
# NPM_CONFIG_REGISTRY - Custom npm registry URL (default: https://registry.npmjs.org)
1111
# VP_LOCAL_TGZ - Path to local vite-plus.tgz (for development/testing)
12+
# VP_PR_VERSION - PR number or commit SHA to install from pkg.pr.new
13+
# (for temporary testing of unreleased builds, e.g. VP_PR_VERSION=1569).
14+
# When set, overrides VP_VERSION and bypasses the npm registry.
1215

1316
$ErrorActionPreference = "Stop"
1417

@@ -20,6 +23,10 @@ $NpmRegistry = if ($env:NPM_CONFIG_REGISTRY) { $env:NPM_CONFIG_REGISTRY.TrimEnd(
2023
$LocalTgz = $env:VP_LOCAL_TGZ
2124
# Local binary path (set by install-global-cli.ts for local dev)
2225
$LocalBinary = $env:VP_LOCAL_BINARY
26+
# pkg.pr.new PR number or commit SHA (for temporary testing of unreleased builds)
27+
$PrVersion = $env:VP_PR_VERSION
28+
# pkg.pr.new base URL for fetching tarballs and constructing dependency URLs
29+
$PkgPrNewBase = "https://pkg.pr.new/voidzero-dev/vite-plus"
2330

2431
function Write-Info {
2532
param([string]$Message)
@@ -418,6 +425,10 @@ function Main {
418425
Write-Host "VITE+" -ForegroundColor Blue -NoNewline
419426
Write-Host "..."
420427

428+
if ($PrVersion -and $LocalTgz) {
429+
Write-Error-Exit "VP_PR_VERSION and VP_LOCAL_TGZ cannot be used together"
430+
}
431+
421432
# Suppress progress bars for cleaner output
422433
$ProgressPreference = 'SilentlyContinue'
423434

@@ -434,6 +445,12 @@ function Main {
434445
if ($ViteVersion -eq "latest" -or $ViteVersion -eq "test") {
435446
$ViteVersion = "local-dev"
436447
}
448+
} elseif ($PrVersion) {
449+
# pkg.pr.new mode: skip npm metadata, use a synthetic version label.
450+
# Non-semver label keeps the directory out of Cleanup-OldVersions and
451+
# makes it obvious in ~/.vite-plus which install is the PR build.
452+
$ViteVersion = "pkg-pr-new-$PrVersion"
453+
Write-Info "Using pkg.pr.new version: $PrVersion"
437454
} else {
438455
# Fetch package metadata and resolve version from npm
439456
$ViteVersion = Get-VersionFromMetadata
@@ -465,10 +482,15 @@ function Main {
465482
Write-Error-Exit "VP_LOCAL_BINARY must be set when using VP_LOCAL_TGZ"
466483
}
467484
} else {
468-
# Download from npm registryextract only the vp binary from CLI platform package
485+
# Download CLI platform tarballnpm registry or pkg.pr.new (when PrVersion is set)
469486
$platformSuffix = Get-PlatformSuffix -Platform $platform
470-
$packageName = "@voidzero-dev/vite-plus-cli-$platformSuffix"
471-
$platformUrl = "$NpmRegistry/$packageName/-/vite-plus-cli-$platformSuffix-$ViteVersion.tgz"
487+
if ($PrVersion) {
488+
# pkg.pr.new redirects this URL to the platform tarball for the matching PR/commit
489+
$platformUrl = "$PkgPrNewBase/@voidzero-dev/vite-plus-cli-$platformSuffix@$PrVersion"
490+
} else {
491+
$packageName = "@voidzero-dev/vite-plus-cli-$platformSuffix"
492+
$platformUrl = "$NpmRegistry/$packageName/-/vite-plus-cli-$platformSuffix-$ViteVersion.tgz"
493+
}
472494

473495
$platformTempFile = New-TemporaryFile
474496
try {
@@ -506,13 +528,16 @@ function Main {
506528
# Generate wrapper package.json that declares vite-plus as a dependency.
507529
# pnpm will install vite-plus and all transitive deps via `vp install`.
508530
# The packageManager field pins pnpm to a known-good version.
531+
# pkg.pr.new tarballs pre-rewrite scoped workspace deps to matching URLs by
532+
# commit SHA, so pointing vite-plus at one URL pulls in a coherent PR build.
533+
$vitePlusSpec = if ($PrVersion) { "$PkgPrNewBase@$PrVersion" } else { $ViteVersion }
509534
$wrapperJson = @{
510535
name = "vp-global"
511536
version = $ViteVersion
512537
private = $true
513538
packageManager = "pnpm@10.33.0"
514539
dependencies = @{
515-
"vite-plus" = $ViteVersion
540+
"vite-plus" = $vitePlusSpec
516541
}
517542
} | ConvertTo-Json -Depth 10
518543
Set-Content -Path (Join-Path $VersionDir "package.json") -Value $wrapperJson

packages/cli/install.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
# NPM_CONFIG_REGISTRY - Custom npm registry URL (default: https://registry.npmjs.org)
1212
# VP_NODE_MANAGER - Set to "yes" or "no" to skip interactive prompt (for CI/devcontainers)
1313
# VP_LOCAL_TGZ - Path to local vite-plus.tgz (for development/testing)
14+
# VP_PR_VERSION - PR number or commit SHA to install from pkg.pr.new
15+
# (for temporary testing of unreleased builds, e.g. VP_PR_VERSION=1569).
16+
# When set, overrides VP_VERSION and bypasses the npm registry.
1417

1518
set -e
1619

@@ -31,6 +34,10 @@ NPM_REGISTRY="${NPM_REGISTRY%/}"
3134
LOCAL_TGZ="${VP_LOCAL_TGZ:-}"
3235
# Local binary path (set by install-global-cli.ts for local dev)
3336
LOCAL_BINARY="${VP_LOCAL_BINARY:-}"
37+
# pkg.pr.new PR number or commit SHA (for temporary testing of unreleased builds)
38+
PR_VERSION="${VP_PR_VERSION:-}"
39+
# pkg.pr.new base URL for fetching tarballs and constructing dependency URLs
40+
PKG_PR_NEW_BASE="https://pkg.pr.new/voidzero-dev/vite-plus"
3441

3542
# Colors for output
3643
RED='\033[0;31m'
@@ -842,6 +849,10 @@ main() {
842849
echo ""
843850
echo -e "Setting up VITE+..."
844851

852+
if [ -n "$PR_VERSION" ] && [ -n "$LOCAL_TGZ" ]; then
853+
error "VP_PR_VERSION and VP_LOCAL_TGZ cannot be used together"
854+
fi
855+
845856
check_requirements
846857

847858
local platform
@@ -857,6 +868,12 @@ main() {
857868
if [ "$VP_VERSION" = "latest" ] || [ "$VP_VERSION" = "test" ]; then
858869
VP_VERSION="local-dev"
859870
fi
871+
elif [ -n "$PR_VERSION" ]; then
872+
# pkg.pr.new mode: skip npm metadata, use a synthetic version label.
873+
# Non-semver label keeps the directory out of cleanup_old_versions and
874+
# makes it obvious in `~/.vite-plus/` which install is the PR build.
875+
VP_VERSION="pkg-pr-new-${PR_VERSION}"
876+
info "Using pkg.pr.new version: ${PR_VERSION}"
860877
else
861878
# Fetch package metadata and resolve version from npm
862879
get_version_from_metadata
@@ -896,10 +913,16 @@ main() {
896913
fi
897914
chmod +x "$BIN_DIR/$binary_name"
898915
else
899-
# Download from npm registryextract only the vp binary from CLI platform package
916+
# Download CLI platform tarballnpm registry or pkg.pr.new (when PR_VERSION is set)
900917
get_platform_suffix "$platform"
901-
local package_name="@voidzero-dev/vite-plus-cli-${PLATFORM_SUFFIX}"
902-
local platform_url="${NPM_REGISTRY}/${package_name}/-/vite-plus-cli-${PLATFORM_SUFFIX}-${VP_VERSION}.tgz"
918+
local platform_url
919+
if [ -n "$PR_VERSION" ]; then
920+
# pkg.pr.new redirects this URL to the platform tarball for the matching PR/commit
921+
platform_url="${PKG_PR_NEW_BASE}/@voidzero-dev/vite-plus-cli-${PLATFORM_SUFFIX}@${PR_VERSION}"
922+
else
923+
local package_name="@voidzero-dev/vite-plus-cli-${PLATFORM_SUFFIX}"
924+
platform_url="${NPM_REGISTRY}/${package_name}/-/vite-plus-cli-${PLATFORM_SUFFIX}-${VP_VERSION}.tgz"
925+
fi
903926

904927
# Create temp directory for extraction
905928
local platform_temp_dir
@@ -920,14 +943,20 @@ main() {
920943
# pnpm will install vite-plus and all transitive deps via `vp install`.
921944
# The packageManager field pins pnpm to a known-good version, ensuring
922945
# consistent behavior regardless of the user's global pnpm version.
946+
# pkg.pr.new tarballs pre-rewrite scoped workspace deps to matching URLs by
947+
# commit SHA, so pointing vite-plus at one URL pulls in a coherent PR build.
948+
local vite_plus_spec="$VP_VERSION"
949+
if [ -n "$PR_VERSION" ]; then
950+
vite_plus_spec="${PKG_PR_NEW_BASE}@${PR_VERSION}"
951+
fi
923952
cat > "$VERSION_DIR/package.json" <<WRAPPER_EOF
924953
{
925954
"name": "vp-global",
926955
"version": "$VP_VERSION",
927956
"private": true,
928957
"packageManager": "pnpm@10.33.0",
929958
"dependencies": {
930-
"vite-plus": "$VP_VERSION"
959+
"vite-plus": "$vite_plus_spec"
931960
}
932961
}
933962
WRAPPER_EOF

0 commit comments

Comments
 (0)