@@ -22,34 +22,27 @@ if (Test-Path $NPM_PREFIX_NPM_CLI_JS) {
22
22
$NPM_CLI_JS = $NPM_PREFIX_NPM_CLI_JS
23
23
}
24
24
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
26
30
if ($MyInvocation.Statement ) {
27
- $NPM_ARGS = $MyInvocation.Statement.Substring ( $MyInvocation .InvocationName.Length ).Trim()
31
+ $NPM_ORIGINAL_COMMAND = $MyInvocation.Statement
28
32
} 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' )
31
35
).GetValue($MyInvocation ).Text
32
- $NPM_ARGS = $NPM_OG_COMMAND.Substring ($MyInvocation.InvocationName.Length ).Trim()
33
36
}
34
37
35
38
$NODE_EXE = $NODE_EXE.Replace (" `` " , " ```` " )
36
39
$NPM_CLI_JS = $NPM_CLI_JS.Replace (" `` " , " ```` " )
37
40
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( )
41
44
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 "
53
46
}
54
47
55
48
exit $LASTEXITCODE
0 commit comments