1
1
# !/usr/bin/env pwsh
2
2
3
+ Set-StrictMode - Version ' Latest'
4
+
3
5
$NODE_EXE = " $PSScriptRoot /node.exe"
4
6
if (-not (Test-Path $NODE_EXE )) {
5
7
$NODE_EXE = " $PSScriptRoot /node"
@@ -27,7 +29,7 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input
27
29
} elseif (-not $MyInvocation.Line ) { # used "-File" argument
28
30
& $NODE_EXE $NPM_CLI_JS $args
29
31
} else { # used "-Command" argument
30
- if ($MyInvocation.Statement ) {
32
+ if (( $MyInvocation | Get-Member - Name ' Statement ' ) -and $MyInvocation.Statement ) {
31
33
$NPM_ORIGINAL_COMMAND = $MyInvocation.Statement
32
34
} else {
33
35
$NPM_ORIGINAL_COMMAND = (
@@ -38,9 +40,9 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input
38
40
$NODE_EXE = $NODE_EXE.Replace (" `` " , " ```` " )
39
41
$NPM_CLI_JS = $NPM_CLI_JS.Replace (" `` " , " ```` " )
40
42
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()
43
+ $NPM_COMMAND_ARRAY = [Management.Automation.Language.Parser ]::ParseInput($NPM_ORIGINAL_COMMAND , [ref ] $null , [ref ] $null ).
44
+ EndBlock.Statements.PipelineElements.CommandElements.Extent.Text
45
+ $NPM_ARGS = ( $NPM_COMMAND_ARRAY | Select-Object - Skip 1 ) -join ' '
44
46
45
47
Invoke-Expression " & `" $NODE_EXE `" `" $NPM_CLI_JS `" $NPM_ARGS "
46
48
}
0 commit comments