Fix devtoprod validateBuild exit-code handling
Ensure Invoke-Npm returns correct exit code without breaking step logic. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
9e28f3db3f
commit
3934cedc62
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user