From c4915a7a0f48ba1ece4b81e93ce877a974988405 Mon Sep 17 00:00:00 2001 From: MK Date: Thu, 14 May 2026 16:39:11 +0800 Subject: [PATCH 1/2] feat(install): support VP_PR_VERSION for pkg.pr.new testing 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, downloads the CLI platform tarball from pkg.pr.new, and writes the wrapper package.json with the vite-plus dependency pointing at the matching pkg.pr.new URL (the published tarball already rewrites its scoped workspace deps to pkg.pr.new URLs by commit SHA, so pnpm pulls in a coherent PR build). Usage: curl -fsSL https://vite.plus | VP_PR_VERSION=1569 bash $env:VP_PR_VERSION = "1569"; irm https://vite.plus/ps1 | iex --- packages/cli/install.ps1 | 34 ++++++++++++++++++++++++++++++---- packages/cli/install.sh | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/packages/cli/install.ps1 b/packages/cli/install.ps1 index b1d38588bd..3190558e99 100644 --- a/packages/cli/install.ps1 +++ b/packages/cli/install.ps1 @@ -9,6 +9,9 @@ # VP_HOME - Installation directory (default: $env:USERPROFILE\.vite-plus) # NPM_CONFIG_REGISTRY - Custom npm registry URL (default: https://registry.npmjs.org) # VP_LOCAL_TGZ - Path to local vite-plus.tgz (for development/testing) +# VP_PR_VERSION - PR number or commit SHA to install from pkg.pr.new +# (for temporary testing of unreleased builds, e.g. VP_PR_VERSION=1569). +# When set, overrides VP_VERSION and bypasses the npm registry. $ErrorActionPreference = "Stop" @@ -20,6 +23,15 @@ $NpmRegistry = if ($env:NPM_CONFIG_REGISTRY) { $env:NPM_CONFIG_REGISTRY.TrimEnd( $LocalTgz = $env:VP_LOCAL_TGZ # Local binary path (set by install-global-cli.ts for local dev) $LocalBinary = $env:VP_LOCAL_BINARY +# pkg.pr.new PR number or commit SHA (for temporary testing of unreleased builds) +$PrVersion = $env:VP_PR_VERSION +# pkg.pr.new base URL for fetching tarballs and constructing dependency URLs +$PkgPrNewBase = "https://pkg.pr.new/voidzero-dev/vite-plus" + +if ($PrVersion -and $LocalTgz) { + Write-Host "error: VP_PR_VERSION and VP_LOCAL_TGZ cannot be used together" -ForegroundColor Red + exit 1 +} function Write-Info { param([string]$Message) @@ -434,6 +446,12 @@ function Main { if ($ViteVersion -eq "latest" -or $ViteVersion -eq "test") { $ViteVersion = "local-dev" } + } elseif ($PrVersion) { + # pkg.pr.new mode: skip npm metadata, use a synthetic version label. + # Non-semver label keeps the directory out of Cleanup-OldVersions and + # makes it obvious in ~/.vite-plus which install is the PR build. + $ViteVersion = "pkg-pr-new-$PrVersion" + Write-Info "Using pkg.pr.new version: $PrVersion" } else { # Fetch package metadata and resolve version from npm $ViteVersion = Get-VersionFromMetadata @@ -465,10 +483,15 @@ function Main { Write-Error-Exit "VP_LOCAL_BINARY must be set when using VP_LOCAL_TGZ" } } else { - # Download from npm registry — extract only the vp binary from CLI platform package + # Download CLI platform tarball — npm registry or pkg.pr.new (when PrVersion is set) $platformSuffix = Get-PlatformSuffix -Platform $platform - $packageName = "@voidzero-dev/vite-plus-cli-$platformSuffix" - $platformUrl = "$NpmRegistry/$packageName/-/vite-plus-cli-$platformSuffix-$ViteVersion.tgz" + if ($PrVersion) { + # pkg.pr.new redirects this URL to the platform tarball for the matching PR/commit + $platformUrl = "$PkgPrNewBase/@voidzero-dev/vite-plus-cli-$platformSuffix@$PrVersion" + } else { + $packageName = "@voidzero-dev/vite-plus-cli-$platformSuffix" + $platformUrl = "$NpmRegistry/$packageName/-/vite-plus-cli-$platformSuffix-$ViteVersion.tgz" + } $platformTempFile = New-TemporaryFile try { @@ -506,13 +529,16 @@ function Main { # Generate wrapper package.json that declares vite-plus as a dependency. # pnpm will install vite-plus and all transitive deps via `vp install`. # The packageManager field pins pnpm to a known-good version. + # In pkg.pr.new mode, the dependency spec is a URL; the published tarball + # already rewrites scoped workspace deps to matching pkg.pr.new URLs. + $vitePlusSpec = if ($PrVersion) { "$PkgPrNewBase@$PrVersion" } else { $ViteVersion } $wrapperJson = @{ name = "vp-global" version = $ViteVersion private = $true packageManager = "pnpm@10.33.0" dependencies = @{ - "vite-plus" = $ViteVersion + "vite-plus" = $vitePlusSpec } } | ConvertTo-Json -Depth 10 Set-Content -Path (Join-Path $VersionDir "package.json") -Value $wrapperJson diff --git a/packages/cli/install.sh b/packages/cli/install.sh index ce5238c9b1..822e9e69a8 100644 --- a/packages/cli/install.sh +++ b/packages/cli/install.sh @@ -11,6 +11,9 @@ # NPM_CONFIG_REGISTRY - Custom npm registry URL (default: https://registry.npmjs.org) # VP_NODE_MANAGER - Set to "yes" or "no" to skip interactive prompt (for CI/devcontainers) # VP_LOCAL_TGZ - Path to local vite-plus.tgz (for development/testing) +# VP_PR_VERSION - PR number or commit SHA to install from pkg.pr.new +# (for temporary testing of unreleased builds, e.g. VP_PR_VERSION=1569). +# When set, overrides VP_VERSION and bypasses the npm registry. set -e @@ -31,6 +34,15 @@ NPM_REGISTRY="${NPM_REGISTRY%/}" LOCAL_TGZ="${VP_LOCAL_TGZ:-}" # Local binary path (set by install-global-cli.ts for local dev) LOCAL_BINARY="${VP_LOCAL_BINARY:-}" +# pkg.pr.new PR number or commit SHA (for temporary testing of unreleased builds) +PR_VERSION="${VP_PR_VERSION:-}" +# pkg.pr.new base URL for fetching tarballs and constructing dependency URLs +PKG_PR_NEW_BASE="https://pkg.pr.new/voidzero-dev/vite-plus" + +if [ -n "$PR_VERSION" ] && [ -n "$LOCAL_TGZ" ]; then + echo "error: VP_PR_VERSION and VP_LOCAL_TGZ cannot be used together" >&2 + exit 1 +fi # Colors for output RED='\033[0;31m' @@ -857,6 +869,12 @@ main() { if [ "$VP_VERSION" = "latest" ] || [ "$VP_VERSION" = "test" ]; then VP_VERSION="local-dev" fi + elif [ -n "$PR_VERSION" ]; then + # pkg.pr.new mode: skip npm metadata, use a synthetic version label. + # Non-semver label keeps the directory out of cleanup_old_versions and + # makes it obvious in `~/.vite-plus/` which install is the PR build. + VP_VERSION="pkg-pr-new-${PR_VERSION}" + info "Using pkg.pr.new version: ${PR_VERSION}" else # Fetch package metadata and resolve version from npm get_version_from_metadata @@ -896,10 +914,16 @@ main() { fi chmod +x "$BIN_DIR/$binary_name" else - # Download from npm registry — extract only the vp binary from CLI platform package + # Download CLI platform tarball — npm registry or pkg.pr.new (when PR_VERSION is set) get_platform_suffix "$platform" - local package_name="@voidzero-dev/vite-plus-cli-${PLATFORM_SUFFIX}" - local platform_url="${NPM_REGISTRY}/${package_name}/-/vite-plus-cli-${PLATFORM_SUFFIX}-${VP_VERSION}.tgz" + local platform_url + if [ -n "$PR_VERSION" ]; then + # pkg.pr.new redirects this URL to the platform tarball for the matching PR/commit + platform_url="${PKG_PR_NEW_BASE}/@voidzero-dev/vite-plus-cli-${PLATFORM_SUFFIX}@${PR_VERSION}" + else + local package_name="@voidzero-dev/vite-plus-cli-${PLATFORM_SUFFIX}" + platform_url="${NPM_REGISTRY}/${package_name}/-/vite-plus-cli-${PLATFORM_SUFFIX}-${VP_VERSION}.tgz" + fi # Create temp directory for extraction local platform_temp_dir @@ -920,6 +944,12 @@ main() { # pnpm will install vite-plus and all transitive deps via `vp install`. # The packageManager field pins pnpm to a known-good version, ensuring # consistent behavior regardless of the user's global pnpm version. + # In pkg.pr.new mode, the dependency spec is a URL; the published tarball + # already rewrites scoped workspace deps to matching pkg.pr.new URLs. + local vite_plus_spec="$VP_VERSION" + if [ -n "$PR_VERSION" ]; then + vite_plus_spec="${PKG_PR_NEW_BASE}@${PR_VERSION}" + fi cat > "$VERSION_DIR/package.json" < Date: Thu, 14 May 2026 16:45:32 +0800 Subject: [PATCH 2/2] refactor(install): use built-in error helpers for VP_PR_VERSION conflict check Move the VP_PR_VERSION/VP_LOCAL_TGZ conflict check into main()/Main so it can use the existing error() / Write-Error-Exit helpers, matching the style of the surrounding validations and producing the same red "error:" prefix. Drop a comment that restated the branch the reader was about to see; keep the non-obvious WHY about pre-rewritten transitive deps. --- packages/cli/install.ps1 | 13 ++++++------- packages/cli/install.sh | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/cli/install.ps1 b/packages/cli/install.ps1 index 3190558e99..d10243ce2c 100644 --- a/packages/cli/install.ps1 +++ b/packages/cli/install.ps1 @@ -28,11 +28,6 @@ $PrVersion = $env:VP_PR_VERSION # pkg.pr.new base URL for fetching tarballs and constructing dependency URLs $PkgPrNewBase = "https://pkg.pr.new/voidzero-dev/vite-plus" -if ($PrVersion -and $LocalTgz) { - Write-Host "error: VP_PR_VERSION and VP_LOCAL_TGZ cannot be used together" -ForegroundColor Red - exit 1 -} - function Write-Info { param([string]$Message) Write-Host "info: " -ForegroundColor Blue -NoNewline @@ -430,6 +425,10 @@ function Main { Write-Host "VITE+" -ForegroundColor Blue -NoNewline Write-Host "..." + if ($PrVersion -and $LocalTgz) { + Write-Error-Exit "VP_PR_VERSION and VP_LOCAL_TGZ cannot be used together" + } + # Suppress progress bars for cleaner output $ProgressPreference = 'SilentlyContinue' @@ -529,8 +528,8 @@ function Main { # Generate wrapper package.json that declares vite-plus as a dependency. # pnpm will install vite-plus and all transitive deps via `vp install`. # The packageManager field pins pnpm to a known-good version. - # In pkg.pr.new mode, the dependency spec is a URL; the published tarball - # already rewrites scoped workspace deps to matching pkg.pr.new URLs. + # pkg.pr.new tarballs pre-rewrite scoped workspace deps to matching URLs by + # commit SHA, so pointing vite-plus at one URL pulls in a coherent PR build. $vitePlusSpec = if ($PrVersion) { "$PkgPrNewBase@$PrVersion" } else { $ViteVersion } $wrapperJson = @{ name = "vp-global" diff --git a/packages/cli/install.sh b/packages/cli/install.sh index 822e9e69a8..da733e1157 100644 --- a/packages/cli/install.sh +++ b/packages/cli/install.sh @@ -39,11 +39,6 @@ PR_VERSION="${VP_PR_VERSION:-}" # pkg.pr.new base URL for fetching tarballs and constructing dependency URLs PKG_PR_NEW_BASE="https://pkg.pr.new/voidzero-dev/vite-plus" -if [ -n "$PR_VERSION" ] && [ -n "$LOCAL_TGZ" ]; then - echo "error: VP_PR_VERSION and VP_LOCAL_TGZ cannot be used together" >&2 - exit 1 -fi - # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' @@ -854,6 +849,10 @@ main() { echo "" echo -e "Setting up VITE+..." + if [ -n "$PR_VERSION" ] && [ -n "$LOCAL_TGZ" ]; then + error "VP_PR_VERSION and VP_LOCAL_TGZ cannot be used together" + fi + check_requirements local platform @@ -944,8 +943,8 @@ main() { # pnpm will install vite-plus and all transitive deps via `vp install`. # The packageManager field pins pnpm to a known-good version, ensuring # consistent behavior regardless of the user's global pnpm version. - # In pkg.pr.new mode, the dependency spec is a URL; the published tarball - # already rewrites scoped workspace deps to matching pkg.pr.new URLs. + # pkg.pr.new tarballs pre-rewrite scoped workspace deps to matching URLs by + # commit SHA, so pointing vite-plus at one URL pulls in a coherent PR build. local vite_plus_spec="$VP_VERSION" if [ -n "$PR_VERSION" ]; then vite_plus_spec="${PKG_PR_NEW_BASE}@${PR_VERSION}"