diff --git a/bin/npm.ps1 b/bin/npm.ps1 index 77bc9a5777c80..4add6e642b82f 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 { @@ -32,24 +36,14 @@ if ($MyInvocation.Line) { # used "-Command" argument $NPM_ARGS = $NPM_OG_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim() } - $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" + if ($NPM_ARGS.Contains(">")) { + & $NODE_EXE $NPM_CLI_JS $args } else { + $NODE_EXE = $NODE_EXE.Replace("``", "````") + $NPM_CLI_JS = $NPM_CLI_JS.Replace("``", "````") + 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 - } } exit $LASTEXITCODE diff --git a/bin/npx.ps1 b/bin/npx.ps1 index e89536bf3542a..ba9035d7a6c9f 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 { @@ -32,24 +36,14 @@ if ($MyInvocation.Line) { # used "-Command" argument $NPX_ARGS = $NPX_OG_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim() } - $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" + if ($NPX_ARGS.Contains(">")) { + & $NODE_EXE $NPX_CLI_JS $args } else { + $NODE_EXE = $NODE_EXE.Replace("``", "````") + $NPX_CLI_JS = $NPX_CLI_JS.Replace("``", "````") + 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 - } } exit $LASTEXITCODE