Skip to content

Commit 4709abb

Browse files
authored
Merge branch 'main' into docs/readme-task-env
2 parents d091e69 + b56066b commit 4709abb

135 files changed

Lines changed: 6414 additions & 3323 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Run locally on Windows with ./.github/scripts/test-install-bootstrap.ps1; no registry or installed vp needed.
2+
$ErrorActionPreference = 'Stop'
3+
$source = Get-Content -LiteralPath (Join-Path $PSScriptRoot '../../packages/cli/install.ps1') -Raw
4+
. ([scriptblock]::Create(($source -replace '(?m)^ Main\r?$', '')))
5+
function Exit-Installer { param([int]$Code = 1); $script:ExitCode = $Code; throw $script:InstallStopSignal }
6+
function Assert($Condition, [string]$Message) {
7+
if (-not $Condition) { throw $Message }
8+
}
9+
10+
$testRoot = Join-Path $env:TEMP "vite-bootstrap-test-$(Get-Random)"
11+
$originalTemp = $env:TEMP
12+
$originalCheck = $env:VP_SELF_SETUP_SUPPORT_CHECK
13+
$originalPath = $env:Path
14+
$originalRegistry = $env:NPM_CONFIG_REGISTRY
15+
$fixtureSha = '0123456789012345678901234567890123456789'
16+
New-Item -ItemType Directory -Path "$testRoot/package", "$testRoot/tmp", "$testRoot/scripts" | Out-Null
17+
Set-Content -LiteralPath "$testRoot/package/vp.exe" -Value 'Payload fixture'
18+
@'
19+
if ($args.Count -eq 0) {
20+
if (Test-Path Env:VP_SELF_SETUP_SUPPORT_CHECK) { exit 99 }
21+
New-Item -ItemType File -Path "$testRoot/binary-invoked" | Out-Null
22+
if ($scenario -eq 'failure') { exit 42 }
23+
if ($env:VP_SELF_SETUP_SHELL -ne 'powershell') { exit 98 }
24+
if ($scenario -eq 'supported-pr' -and $env:NPM_CONFIG_REGISTRY -ne 'https://registry-bridge.viteplus.dev/') { exit 97 }
25+
Write-Output ("`$script:InstallDir = '{0}'" -f "$testRoot/data")
26+
Write-Output ("`$script:ShimDir = '{0}'" -f "$testRoot/installed bin")
27+
Write-Output ("`$script:CacheDir = '{0}'" -f "$testRoot/cache")
28+
Write-Output ("`$script:ConfigDir = '{0}'" -f "$testRoot/config")
29+
Write-Output ("`$script:StateDir = '{0}'" -f "$testRoot/state")
30+
exit 0
31+
}
32+
if ($env:VP_SELF_SETUP_SUPPORT_CHECK -ne '1') { exit 99 }
33+
if ($scenario -in @('legacy', 'legacy-failure', 'pr')) { Write-Output 'Usage: vp [COMMAND]' }
34+
else { Write-Output 'vite-plus-self-setup-v1' }
35+
exit 0
36+
'@ | Set-Content -LiteralPath "$testRoot/package/binary.ps1"
37+
@'
38+
param($BinarySource, $ResolvedVersion, $PreviewRef)
39+
$script:InstallDir = "$testRoot/data"
40+
$script:ShimDir = "$testRoot/installed bin"
41+
$script:CacheDir = "$testRoot/cache"
42+
$script:ConfigDir = "$testRoot/config"
43+
$script:StateDir = "$testRoot/state"
44+
if (-not [System.IO.Path]::IsPathRooted($BinarySource) -or -not (Test-Path -LiteralPath $BinarySource)) { throw 'Invalid payload path' }
45+
@($ResolvedVersion, $PreviewRef) | Set-Content -LiteralPath "$testRoot/legacy"
46+
if ($scenario -eq 'legacy-failure') { exit 42 }
47+
'@ | Set-Content -LiteralPath "$testRoot/scripts/install-legacy.ps1"
48+
& "$env:SystemRoot\System32\tar.exe" -czf "$testRoot/payload.tgz" -C $testRoot package
49+
Assert ($LASTEXITCODE -eq 0) 'Could not create fixture'
50+
$env:TEMP = "$testRoot/tmp"
51+
52+
function Invoke-RestMethod {
53+
param($Uri)
54+
$script:Requests.Add("GET $Uri")
55+
return @{ version = '0.2.9' }
56+
}
57+
function Invoke-WebRequest {
58+
param($Uri, $Method, $OutFile, [switch]$UseBasicParsing, $ErrorAction)
59+
$script:Requests.Add("$Method $Uri")
60+
if ($Method -eq 'Head') {
61+
return @{ Headers = @{ 'x-commit-key' = "voidzero-dev:vite-plus:$fixtureSha" } }
62+
}
63+
Copy-Item -LiteralPath "$testRoot/payload.tgz" -Destination $OutFile
64+
}
65+
66+
# Use an executable script fixture so these checks need no native compiler.
67+
$probe = ${function:Test-SelfSetupSupport}
68+
function Test-SelfSetupSupport {
69+
param($BinarySource)
70+
& $probe -BinarySource (Join-Path (Split-Path $BinarySource) 'binary.ps1')
71+
}
72+
$handoff = ${function:Invoke-InstallHandoff}
73+
function Invoke-InstallHandoff {
74+
param($BinarySource)
75+
& $handoff -BinarySource (Join-Path (Split-Path $BinarySource) 'binary.ps1')
76+
}
77+
78+
try {
79+
foreach ($scenario in @('supported', 'legacy', 'legacy-failure', 'failure', 'pr', 'supported-pr')) {
80+
$env:Path = $originalPath
81+
$env:NPM_CONFIG_REGISTRY = 'https://custom.example'
82+
$script:Requests = New-Object 'System.Collections.Generic.List[string]'
83+
$script:ExitCode = 0
84+
$script:PackageMetadata = $null
85+
Remove-Item -LiteralPath "$testRoot/legacy", "$testRoot/binary-invoked" -ErrorAction SilentlyContinue
86+
$env:VP_SELF_SETUP_SUPPORT_CHECK = if ($scenario -eq 'supported') { 'original' } else { $null }
87+
try {
88+
& {
89+
$ViteVersion = 'latest'
90+
$LocalTgz = $LocalBinary = $PrVersion = $PrCommitVersion = $null
91+
$NpmRegistry = 'https://custom.example'
92+
$InstallerDirectory = "$testRoot/scripts"
93+
if ($scenario -in @('pr', 'supported-pr')) { $PrVersion = '2406' }
94+
Main
95+
Assert ($env:NPM_CONFIG_REGISTRY -eq 'https://custom.example') 'Setup changed the caller registry'
96+
Assert ($script:InstallDir -eq "$testRoot/data") 'InstallDir was lost'
97+
Assert ($script:ShimDir -eq "$testRoot/installed bin") 'ShimDir was lost'
98+
Assert ($script:CacheDir -eq "$testRoot/cache") 'CacheDir was lost'
99+
Assert ($script:ConfigDir -eq "$testRoot/config") 'ConfigDir was lost'
100+
Assert ($script:StateDir -eq "$testRoot/state") 'StateDir was lost'
101+
}
102+
} catch {
103+
if ($scenario -notin @('failure', 'legacy-failure') -or -not (Test-IsInstallStopException $_)) { throw }
104+
}
105+
$expectedExit = if ($scenario -in @('failure', 'legacy-failure')) { 42 } else { 0 }
106+
Assert ($script:ExitCode -eq $expectedExit) 'Binary exit code was lost'
107+
if ($scenario -eq 'supported') {
108+
Assert (($env:Path -split ';')[0] -eq "$testRoot/installed bin") 'Installed bin directory was not added to the current PATH'
109+
} elseif ($scenario -eq 'failure') {
110+
Assert ($env:Path -eq $originalPath) 'Failed setup changed the current PATH'
111+
}
112+
$usesBinary = $scenario -in @('supported', 'supported-pr', 'failure')
113+
Assert ((Test-Path -LiteralPath "$testRoot/binary-invoked") -eq $usesBinary) 'Incorrect binary invocation'
114+
Assert ((Test-Path -LiteralPath "$testRoot/legacy") -eq (-not $usesBinary)) 'Incorrect legacy invocation'
115+
if ($scenario -eq 'pr') {
116+
$record = @(Get-Content -LiteralPath "$testRoot/legacy")
117+
Assert ($record[0] -eq "0.0.0-commit.$fixtureSha" -and $record[1] -eq '2406') 'Resolved preview identity was lost'
118+
Assert ($script:Requests[-1].EndsWith("@$fixtureSha")) 'Payload used a mutable ref'
119+
Assert ($script:Requests.Count -eq 2) 'Preview was resolved or downloaded more than once'
120+
}
121+
Assert (@(Get-ChildItem -LiteralPath "$testRoot/tmp" -Force).Count -eq 0) 'Temporary payload was not cleaned up'
122+
Write-Host "PASS: $scenario"
123+
}
124+
} finally {
125+
$env:VP_SELF_SETUP_SUPPORT_CHECK = $originalCheck
126+
$env:Path = $originalPath
127+
$env:NPM_CONFIG_REGISTRY = $originalRegistry
128+
$env:TEMP = $originalTemp
129+
Remove-Item -LiteralPath $testRoot -Recurse -Force
130+
$global:LASTEXITCODE = 0
131+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
# Run locally with bash .github/scripts/test-install-bootstrap.sh; no registry or installed vp needed.
3+
set -eu
4+
cd "$(dirname "$0")/../.."
5+
eval "$(sed '/^main "[$]@"$/d' packages/cli/install.sh)"
6+
7+
test_root=$(mktemp -d)
8+
trap 'rm -rf "$test_root"' EXIT
9+
export test_root
10+
mkdir -p "$test_root/package" "$test_root/tmp" "$test_root/scripts"
11+
touch "$test_root/scripts/install.sh"
12+
cat > "$test_root/scripts/install-legacy.sh" <<'LEGACY'
13+
#!/bin/bash
14+
set -eu
15+
INSTALL_DIR="$test_root/data"
16+
SHIM_DIR="$test_root/installed bin"
17+
CACHE_DIR="$test_root/cache"
18+
CONFIG_DIR="$test_root/config"
19+
STATE_DIR="$test_root/state"
20+
case "$1" in /*) ;; *) exit 80 ;; esac
21+
test -f "$1"
22+
printf '%s\n' "$2" "$3" > "$test_root/legacy"
23+
case "$scenario" in
24+
legacy-failure|piped-legacy-failure) exit 43 ;;
25+
esac
26+
LEGACY
27+
cat > "$test_root/package/vp" <<'BINARY'
28+
#!/bin/bash
29+
if [ "$#" -eq 0 ]; then
30+
test -z "${VP_SELF_SETUP_SUPPORT_CHECK+x}" || exit 99
31+
touch "$test_root/binary-invoked"
32+
if [ "$scenario" = failure ]; then exit 42; fi
33+
test "${VP_SELF_SETUP_SHELL:-}" = sh || exit 98
34+
if [ "$scenario" = supported-pr ]; then
35+
test "$NPM_CONFIG_REGISTRY" = https://registry-bridge.viteplus.dev/ || exit 97
36+
fi
37+
printf 'INSTALL_DIR=%q\n' "$test_root/data"
38+
printf 'SHIM_DIR=%q\n' "$test_root/installed bin"
39+
printf 'CACHE_DIR=%q\n' "$test_root/cache"
40+
printf 'CONFIG_DIR=%q\n' "$test_root/config"
41+
printf 'STATE_DIR=%q\n' "$test_root/state"
42+
exit 0
43+
fi
44+
test "${VP_SELF_SETUP_SUPPORT_CHECK:-}" = 1 || exit 99
45+
case "$scenario" in
46+
legacy|legacy-failure|piped-legacy|piped-legacy-failure|pr) printf 'Usage: vp [COMMAND]\n' ;;
47+
*) printf 'vite-plus-self-setup-v1\n' ;;
48+
esac
49+
BINARY
50+
chmod +x "$test_root/package/vp"
51+
tar czf "$test_root/payload.tgz" -C "$test_root" package
52+
export TMPDIR="$test_root/tmp"
53+
fixture_sha=0123456789012345678901234567890123456789
54+
55+
# Only transport is substituted; extraction, probing, and dispatch run normally.
56+
curl() {
57+
printf '%s\n' "$*" >> "$test_root/requests"
58+
case "$*" in
59+
*file://*) command curl "$@" ;;
60+
*-fsSIL*) printf 'x-commit-key: voidzero-dev:vite-plus:%s\r\n' "$fixture_sha" ;;
61+
*'https://custom.example/vite-plus/'*) printf '{"version":"0.2.9"}\n' ;;
62+
*) cp "$test_root/payload.tgz" "${@: -1}" ;;
63+
esac
64+
}
65+
66+
for scenario in supported legacy legacy-failure piped-legacy piped-legacy-failure failure pr supported-pr; do
67+
export scenario
68+
: > "$test_root/requests"
69+
rm -f "$test_root/legacy" "$test_root/binary-invoked"
70+
set +e
71+
(
72+
set -e
73+
VP_VERSION=latest
74+
LOCAL_TGZ="" LOCAL_BINARY="" PR_VERSION="" PACKAGE_METADATA=""
75+
NPM_REGISTRY=https://custom.example
76+
export NPM_CONFIG_REGISTRY="$NPM_REGISTRY"
77+
INSTALLER_PATH="$test_root/scripts/install.sh"
78+
if [[ "$scenario" == piped-legacy* ]]; then
79+
INSTALLER_PATH=""
80+
LEGACY_INSTALLER_URL="file://$test_root/scripts/install-legacy.sh"
81+
fi
82+
if [[ "$scenario" == *pr ]]; then PR_VERSION=2406; fi
83+
if [ "$scenario" = supported ]; then export VP_SELF_SETUP_SUPPORT_CHECK=original; fi
84+
main
85+
test "$NPM_CONFIG_REGISTRY" = https://custom.example
86+
test "$INSTALL_DIR" = "$test_root/data"
87+
test "$SHIM_DIR" = "$test_root/installed bin"
88+
test "$CACHE_DIR" = "$test_root/cache"
89+
test "$CONFIG_DIR" = "$test_root/config"
90+
test "$STATE_DIR" = "$test_root/state"
91+
) > "$test_root/output" 2>&1
92+
status=$?
93+
set -e
94+
if [ "$scenario" = failure ]; then
95+
test "$status" -eq 42
96+
elif [[ "$scenario" == *legacy-failure ]]; then
97+
test "$status" -eq 43
98+
elif [ "$status" -ne 0 ]; then
99+
cat "$test_root/output"
100+
exit 1
101+
fi
102+
case "$scenario" in
103+
supported|supported-pr|failure)
104+
test -f "$test_root/binary-invoked"
105+
test ! -f "$test_root/legacy" ;;
106+
legacy|legacy-failure|piped-legacy|piped-legacy-failure|pr)
107+
test -f "$test_root/legacy"
108+
test ! -f "$test_root/binary-invoked" ;;
109+
esac
110+
if [ "$scenario" = pr ]; then
111+
test "$(head -1 "$test_root/legacy")" = "0.0.0-commit.$fixture_sha"
112+
test "$(tail -1 "$test_root/legacy")" = 2406
113+
grep -q "@$fixture_sha -o" "$test_root/requests"
114+
test "$(wc -l < "$test_root/requests" | tr -d ' ')" = 2
115+
fi
116+
test -z "$(ls -A "$test_root/tmp")"
117+
echo "PASS: $scenario"
118+
done

.github/workflows/ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,8 @@ jobs:
760760
$initialBinDir = Join-Path $initialVersionDir "bin"
761761
New-Item -ItemType Directory -Path $initialBinDir | Out-Null
762762
Copy-Item $currentVp (Join-Path $initialBinDir "vp.exe")
763+
# Preserve installed state so the first invocation executes upgrade.
764+
Copy-Item (Join-Path (Split-Path $currentVp) ".vp-setup-complete") $initialBinDir
763765
New-Item -ItemType Junction -Path (Join-Path $tempVpHome "current") -Target $initialVersionDir | Out-Null
764766
765767
$env:VP_HOME = $tempVpHome
@@ -815,6 +817,8 @@ jobs:
815817
initial_bin_dir="$temp_vp_home/$version/bin"
816818
mkdir -p "$initial_bin_dir"
817819
cp "$current_vp" "$initial_bin_dir/vp"
820+
# Preserve installed state so the first invocation executes upgrade.
821+
cp "$(dirname "$current_vp")/.vp-setup-complete" "$initial_bin_dir/"
818822
chmod +x "$initial_bin_dir/vp"
819823
# Relative symlink, matching swap_current_link's `current -> <version>`.
820824
ln -s "$version" "$temp_vp_home/current"
@@ -1255,10 +1259,13 @@ jobs:
12551259
# The image must actually lack the CA bundle, or this job stops
12561260
# guarding anything.
12571261
test ! -e /etc/ssl/certs/ca-certificates.crt
1262+
# Exercise commands on the mounted build without installing a published package.
1263+
touch /usr/local/bin/.vp-setup-complete
12581264
vp --version
12591265
# HTTPS to nodejs.org through the shared client; exits nonzero
12601266
# without the bundled-roots fallback.
1261-
vp env list-remote --lts
1267+
vp env list-remote --lts --json > /tmp/vp-versions.json
1268+
node -e "const versions = require(\"/tmp/vp-versions.json\"); if (!versions.node?.length) process.exit(1)"
12621269
'
12631270
12641271
install-e2e-test:

.github/workflows/deploy-docs-main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ on:
1313
- 'docs/**'
1414
- 'packages/cli/install.sh'
1515
- 'packages/cli/install.ps1'
16+
- 'packages/cli/install-legacy.sh'
17+
- 'packages/cli/install-legacy.ps1'
1618
- '.github/workflows/deploy-docs-main.yml'
1719
- '.github/actions/deploy-docs/**'
1820

.github/workflows/deploy-docs-preview.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
- 'docs/**'
99
- 'packages/cli/install.sh'
1010
- 'packages/cli/install.ps1'
11+
- 'packages/cli/install-legacy.sh'
12+
- 'packages/cli/install-legacy.ps1'
1113
- '.github/workflows/deploy-docs-preview.yml'
1214
- '.github/actions/deploy-docs/**'
1315

.github/workflows/publish-preview-register.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ jobs:
388388
'',
389389
'```bash',
390390
'# macOS / Linux',
391-
`curl -fsSL ${installerScripts}/install.sh | VP_PR_VERSION=${pr} bash`,
391+
`curl -fsSL ${installerScripts}/install.sh | VP_PR_VERSION=${pr} VP_LEGACY_INSTALLER_URL=${installerScripts}/install-legacy.sh bash`,
392392
'```',
393393
'```powershell',
394394
'# Windows (PowerShell)',
395-
`$env:VP_PR_VERSION="${pr}"; irm ${installerScripts}/install.ps1 | iex`,
395+
`$env:VP_PR_VERSION="${pr}"; $env:VP_LEGACY_INSTALLER_URL="${installerScripts}/install-legacy.ps1"; irm ${installerScripts}/install.ps1 | iex`,
396396
'```',
397397
'',
398398
'**Or download the standalone Windows installer built from this commit:**',

.github/workflows/reusable-release-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ jobs:
153153
}
154154
trap cleanup EXIT
155155
tar -xzf "vp-${{ matrix.settings.target }}.tar.gz" -C "${archive_dir}"
156+
# Skip first-start setup because this build's preview packages are not published yet.
157+
touch "${archive_dir}/.vp-setup-complete"
156158
157159
node --input-type=module -e '
158160
const before = JSON.stringify({ devDependencies: { "vite-plus": "0.0.0" } }) + "\n";

0 commit comments

Comments
 (0)