@@ -22,34 +22,27 @@ if (Test-Path $NPM_PREFIX_NPM_CLI_JS) {
2222 $NPM_CLI_JS = $NPM_PREFIX_NPM_CLI_JS
2323}
2424
25- if ($MyInvocation.Line ) { # used "-Command" argument
25+ if ($MyInvocation.ExpectingInput ) { # takes pipeline input
26+ $input | & $NODE_EXE $NPM_CLI_JS $args
27+ } elseif (-not $MyInvocation.Line ) { # used "-File" argument
28+ & $NODE_EXE $NPM_CLI_JS $args
29+ } else { # used "-Command" argument
2630 if ($MyInvocation.Statement ) {
27- $NPM_ARGS = $MyInvocation.Statement.Substring ( $MyInvocation .InvocationName.Length ).Trim()
31+ $NPM_ORIGINAL_COMMAND = $MyInvocation.Statement
2832 } else {
29- $NPM_OG_COMMAND = (
30- [System. Management.Automation.InvocationInfo ].GetProperty(' ScriptPosition' , [System. Reflection.BindingFlags ] ' Instance, NonPublic' )
33+ $NPM_ORIGINAL_COMMAND = (
34+ [Management.Automation.InvocationInfo ].GetProperty(' ScriptPosition' , [Reflection.BindingFlags ] ' Instance, NonPublic' )
3135 ).GetValue($MyInvocation ).Text
32- $NPM_ARGS = $NPM_OG_COMMAND.Substring ($MyInvocation.InvocationName.Length ).Trim()
3336 }
3437
3538 $NODE_EXE = $NODE_EXE.Replace (" `` " , " ```` " )
3639 $NPM_CLI_JS = $NPM_CLI_JS.Replace (" `` " , " ```` " )
3740
38- # Support pipeline input
39- if ( $MyInvocation .ExpectingInput ) {
40- $input = ( @ ( $input ) -join " `n " ).Replace( " `` " , " ```` " )
41+ $NPM_NO_REDIRECTS_COMMAND = [ Management.Automation.Language.Parser ]::ParseInput( $NPM_ORIGINAL_COMMAND , [ ref ] $null , [ ref ] $null ).
42+ EndBlock.Statements.PipelineElements.CommandElements.Extent.Text -join ' '
43+ $NPM_ARGS = $NPM_NO_REDIRECTS_COMMAND .Substring ( $MyInvocation .InvocationName.Length ).Trim( )
4144
42- Invoke-Expression " Write-Output `" $input `" | & `" $NODE_EXE `" `" $NPM_CLI_JS `" $NPM_ARGS "
43- } else {
44- Invoke-Expression " & `" $NODE_EXE `" `" $NPM_CLI_JS `" $NPM_ARGS "
45- }
46- } else { # used "-File" argument
47- # Support pipeline input
48- if ($MyInvocation.ExpectingInput ) {
49- $input | & $NODE_EXE $NPM_CLI_JS $args
50- } else {
51- & $NODE_EXE $NPM_CLI_JS $args
52- }
45+ Invoke-Expression " & `" $NODE_EXE `" `" $NPM_CLI_JS `" $NPM_ARGS "
5346}
5447
5548exit $LASTEXITCODE
0 commit comments