diff --git a/bin/npm.ps1 b/bin/npm.ps1 index 77bc9a5777c80..c4c8d9ec79943 100644 --- a/bin/npm.ps1 +++ b/bin/npm.ps1 @@ -22,7 +22,11 @@ if (Test-Path $NPM_PREFIX_NPM_CLI_JS) { $NPM_CLI_JS=$NPM_PREFIX_NPM_CLI_JS } -if ($MyInvocation.Line) { # used "-Command" argument +if ($MyInvocation.ExpectingInput) { # takes pipeline input + $input | & $NODE_EXE $NPM_CLI_JS $args +} elseif (-not $MyInvocation.Line) { # used "-File" argument + & $NODE_EXE $NPM_CLI_JS $args +} else { # used "-Command" argument if ($MyInvocation.Statement) { $NPM_ARGS = $MyInvocation.Statement.Substring($MyInvocation.InvocationName.Length).Trim() } else { @@ -35,21 +39,7 @@ if ($MyInvocation.Line) { # used "-Command" argument $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPM_CLI_JS = $NPM_CLI_JS.Replace("``", "````") - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input = (@($input) -join "`n").Replace("``", "````") - - Invoke-Expression "Write-Output `"$input`" | & `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" - } else { - Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" - } -} else { # used "-File" argument - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & $NODE_EXE $NPM_CLI_JS $args - } else { - & $NODE_EXE $NPM_CLI_JS $args - } + Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" } exit $LASTEXITCODE diff --git a/bin/npx.ps1 b/bin/npx.ps1 index e89536bf3542a..6ac637ff16498 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -22,7 +22,11 @@ if (Test-Path $NPM_PREFIX_NPX_CLI_JS) { $NPX_CLI_JS=$NPM_PREFIX_NPX_CLI_JS } -if ($MyInvocation.Line) { # used "-Command" argument +if ($MyInvocation.ExpectingInput) { # takes pipeline input + $input | & $NODE_EXE $NPX_CLI_JS $args +} elseif (-not $MyInvocation.Line) { # used "-File" argument + & $NODE_EXE $NPX_CLI_JS $args +} else { # used "-Command" argument if ($MyInvocation.Statement) { $NPX_ARGS = $MyInvocation.Statement.Substring($MyInvocation.InvocationName.Length).Trim() } else { @@ -35,21 +39,7 @@ if ($MyInvocation.Line) { # used "-Command" argument $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPX_CLI_JS = $NPX_CLI_JS.Replace("``", "````") - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input = (@($input) -join "`n").Replace("``", "````") - - Invoke-Expression "Write-Output `"$input`" | & `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" - } else { - Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" - } -} else { # used "-File" argument - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & $NODE_EXE $NPX_CLI_JS $args - } else { - & $NODE_EXE $NPX_CLI_JS $args - } + Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" } exit $LASTEXITCODE