Skip to content

Commit 0bcee16

Browse files
committed
fix(cli): replace *> with 2>&1 in install.ps1 for PowerShell 7.6
The `*>` redirection operator on native commands can cause a .NET `InvalidOperationException` when `StandardOutputEncoding` is set but `RedirectStandardOutput` is not. This happens interactively (real console attached) but not in CI (no console). Capture output to a variable first, then write to log file via `Out-File` to avoid both the redirection issue and `$LASTEXITCODE` pipeline clobbering. Also adds a PowerShell 7.6 CI test job for regression coverage. Closes #1019
1 parent f1f6016 commit 0bcee16

2 files changed

Lines changed: 84 additions & 2 deletions

File tree

.github/workflows/test-standalone-install.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,86 @@ jobs:
474474
vp upgrade --rollback
475475
vp --version
476476
477+
test-install-ps1-v76:
478+
name: Test install.ps1 (Windows x64, PowerShell 7.6)
479+
runs-on: windows-latest
480+
permissions:
481+
contents: read
482+
steps:
483+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
484+
485+
- name: Install PowerShell 7.6
486+
shell: pwsh
487+
run: |
488+
dotnet tool install --global PowerShell --version 7.6.0
489+
$pwsh76 = "$env:USERPROFILE\.dotnet\tools\pwsh.exe"
490+
echo "PWSH76=$pwsh76" >> $env:GITHUB_ENV
491+
$ver = & $pwsh76 -NoProfile -Command '$PSVersionTable.PSVersion.ToString()'
492+
Write-Host "PowerShell version: $ver"
493+
if (-not $ver.StartsWith("7.6")) {
494+
Write-Error "Expected PowerShell 7.6.x but got $ver"
495+
exit 1
496+
}
497+
498+
- name: Run install.ps1 via iex under PowerShell 7.6
499+
shell: pwsh
500+
run: |
501+
& $env:PWSH76 -NoProfile -Command "Get-Content ./packages/cli/install.ps1 -Raw | Invoke-Expression"
502+
503+
- name: Set PATH
504+
shell: bash
505+
run: |
506+
echo "$USERPROFILE\.vite-plus\bin" >> $GITHUB_PATH
507+
508+
- name: Verify installation
509+
shell: pwsh
510+
working-directory: ${{ runner.temp }}
511+
run: |
512+
Write-Host "PATH: $env:Path"
513+
vp --version
514+
vp --help
515+
vp create vite --no-interactive --no-agent -- hello --no-interactive -t vanilla
516+
cd hello
517+
vp run build
518+
vp --version
519+
520+
- name: Verify bin setup
521+
shell: pwsh
522+
run: |
523+
$binPath = "$env:USERPROFILE\.vite-plus\bin"
524+
Get-ChildItem -Force $binPath
525+
if (-not (Test-Path $binPath)) {
526+
Write-Error "Bin directory not found: $binPath"
527+
exit 1
528+
}
529+
530+
$expectedShims = @("node.exe", "npm.exe", "npx.exe")
531+
foreach ($shim in $expectedShims) {
532+
$shimFile = Join-Path $binPath $shim
533+
if (-not (Test-Path $shimFile)) {
534+
Write-Error "Shim not found: $shimFile"
535+
exit 1
536+
}
537+
Write-Host "Found shim: $shimFile"
538+
}
539+
where.exe node
540+
where.exe npm
541+
where.exe npx
542+
where.exe vp
543+
544+
$env:Path = "$env:USERPROFILE\.vite-plus\bin;$env:Path"
545+
vp env doctor
546+
vp env run --node 24 -- node -p "process.versions"
547+
548+
- name: Verify upgrade
549+
shell: pwsh
550+
run: |
551+
vp upgrade --check
552+
vp upgrade 0.1.14-alpha.1
553+
vp --version
554+
vp upgrade --rollback
555+
vp --version
556+
477557
test-install-ps1:
478558
name: Test install.ps1 (Windows x64)
479559
runs-on: windows-latest

packages/cli/install.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,10 @@ function Main {
375375
Push-Location $VersionDir
376376
try {
377377
$env:CI = "true"
378-
& "$BinDir\vp.exe" install --silent *> $installLog
379-
if ($LASTEXITCODE -ne 0) {
378+
$output = & "$BinDir\vp.exe" install --silent 2>&1
379+
$installExitCode = $LASTEXITCODE
380+
$output | Out-File $installLog
381+
if ($installExitCode -ne 0) {
380382
Write-Host "error: Failed to install dependencies. See log for details: $installLog" -ForegroundColor Red
381383
exit 1
382384
}

0 commit comments

Comments
 (0)