diff --git a/infra/scripts/deploy-dev-to-prod.ps1 b/infra/scripts/deploy-dev-to-prod.ps1 index 63d59c2..ddaef48 100644 --- a/infra/scripts/deploy-dev-to-prod.ps1 +++ b/infra/scripts/deploy-dev-to-prod.ps1 @@ -50,15 +50,26 @@ function Get-StepEnabled { function Invoke-Npm { param([string]$Script, [string[]]$ExtraArgs = @()) - $args = @('run', $Script) + $npmArgs = @('run', $Script) if ($ExtraArgs.Count -gt 0) { - $args += '--' - $args += $ExtraArgs + $npmArgs += '--' + $npmArgs += $ExtraArgs + } + # Important: callers assign the return value of this function to a variable + # (e.g. `$code = Invoke-Npm 'prod:build'`). + # If npm output is sent to the pipeline, PowerShell can accidentally capture + # stdout/stderr along with the function return value, breaking exit-code logic. + # So we stream npm output to $null and return only the exit code. + Write-Host ("Running npm: npm " + ($npmArgs -join ' ')) -ForegroundColor DarkGray + # Capture stdout/stderr so the function does not emit pipeline output. + $prevEap = $ErrorActionPreference + $ErrorActionPreference = 'Continue' + $npmOutput = & npm @npmArgs 2>&1 + $ErrorActionPreference = $prevEap + + foreach ($line in $npmOutput) { + Write-Host $line } - # Prevent npm stdout/stderr from becoming pipeline output for the caller. - # Without this, callers that assign the function result to a variable can - # accidentally capture npm's printed output instead of only exit code. - & npm @args 2>&1 | Out-Host return $LASTEXITCODE } @@ -248,6 +259,7 @@ Write-Host ('Steps: ' + ($enabled -join ', ')) if (Get-StepEnabled $steps 'validateBuild') { $ok = Invoke-Step 'validateBuild' { $code = Invoke-Npm 'prod:build' + Write-Host ("prod:build exit code: " + $code) if ($code -ne 0) { return $code } # Always prefer the dev host on LAN (192.168.10.70) because the HTTPS dev domain