From 32db79e26dc3d50ea1520598c6bd3fdeaeaae821 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 28 Aug 2025 14:33:50 -0400 Subject: [PATCH 1/7] fix(powershell): improve argument parsing --- bin/npm.ps1 | 8 ++++---- bin/npx.ps1 | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/npm.ps1 b/bin/npm.ps1 index e18a672625354..e676668d3801f 100644 --- a/bin/npm.ps1 +++ b/bin/npm.ps1 @@ -26,7 +26,7 @@ if (Test-Path $NPM_PREFIX_NPM_CLI_JS) { if ($MyInvocation.ExpectingInput) { # takes pipeline input $input | & $NODE_EXE $NPM_CLI_JS $args -} elseif (-not $MyInvocation.Line -or $MyInvocation.InvocationName -in '&', '.') { # used "-File" argument +} elseif (-not $MyInvocation.Line) { # used "-File" argument & $NODE_EXE $NPM_CLI_JS $args } else { # used "-Command" argument if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) { @@ -40,9 +40,9 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPM_CLI_JS = $NPM_CLI_JS.Replace("``", "````") - $NPM_NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). - EndBlock.Statements.PipelineElements.CommandElements.Extent.Text -join ' ' - $NPM_ARGS = $NPM_NO_REDIRECTS_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim() + $NPM_NO_REDIRECTS_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + EndBlock.Statements.PipelineElements.CommandElements.Extent.Text + $NPM_ARGS = $NPM_NO_REDIRECTS_COMMAND_ARR[1..($NPM_NO_REDIRECTS_COMMAND_ARR.Length - 1)] -join ' ' Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" } diff --git a/bin/npx.ps1 b/bin/npx.ps1 index 60ba47ba39641..08610a8856792 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -26,7 +26,7 @@ if (Test-Path $NPM_PREFIX_NPX_CLI_JS) { if ($MyInvocation.ExpectingInput) { # takes pipeline input $input | & $NODE_EXE $NPX_CLI_JS $args -} elseif (-not $MyInvocation.Line -or $MyInvocation.InvocationName -in '&', '.') { # used "-File" argument +} elseif (-not $MyInvocation.Line) { # used "-File" argument & $NODE_EXE $NPX_CLI_JS $args } else { # used "-Command" argument if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) { @@ -40,9 +40,9 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPX_CLI_JS = $NPX_CLI_JS.Replace("``", "````") - $NPX_NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). - EndBlock.Statements.PipelineElements.CommandElements.Extent.Text -join ' ' - $NPX_ARGS = $NPX_NO_REDIRECTS_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim() + $NPX_NO_REDIRECTS_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + EndBlock.Statements.PipelineElements.CommandElements.Extent.Text + $NPX_ARGS = $NPX_NO_REDIRECTS_COMMAND_ARR[1..($NPX_NO_REDIRECTS_COMMAND_ARR.Length - 1)] -join ' ' Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" } From 675b9c4dd83ce76014e92ee3e9b68e2a6e3a9e4d Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 28 Aug 2025 14:47:09 -0400 Subject: [PATCH 2/7] lint --- bin/npx.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/npx.ps1 b/bin/npx.ps1 index 08610a8856792..b1271225e65d4 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -40,7 +40,7 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPX_CLI_JS = $NPX_CLI_JS.Replace("``", "````") - $NPX_NO_REDIRECTS_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + $NPX_NO_REDIRECTS_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text $NPX_ARGS = $NPX_NO_REDIRECTS_COMMAND_ARR[1..($NPX_NO_REDIRECTS_COMMAND_ARR.Length - 1)] -join ' ' From c80bac736aa1029ad65316a8e5aeeb1cf7869e24 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 28 Aug 2025 15:02:07 -0400 Subject: [PATCH 3/7] fix for single argument such as just `npm` command --- bin/npm.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/npm.ps1 b/bin/npm.ps1 index e676668d3801f..e321c96a771c4 100644 --- a/bin/npm.ps1 +++ b/bin/npm.ps1 @@ -40,9 +40,14 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPM_CLI_JS = $NPM_CLI_JS.Replace("``", "````") - $NPM_NO_REDIRECTS_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + $NPM_NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text - $NPM_ARGS = $NPM_NO_REDIRECTS_COMMAND_ARR[1..($NPM_NO_REDIRECTS_COMMAND_ARR.Length - 1)] -join ' ' + + if ($NPM_NO_REDIRECTS_COMMAND -is [array] -and $NPM_NO_REDIRECTS_COMMAND.Length -gt 1) { + $NPM_ARGS = $NPM_NO_REDIRECTS_COMMAND[1..($NPM_NO_REDIRECTS_COMMAND.Length - 1)] -join ' ' + } else { + $NPM_ARGS = "" + } Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" } From 3bffe977bf4b1ea9ab3dbe995fa36c5615026b57 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 28 Aug 2025 15:04:05 -0400 Subject: [PATCH 4/7] same for npx --- bin/npx.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/npx.ps1 b/bin/npx.ps1 index b1271225e65d4..13595d8e8c9de 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -40,9 +40,14 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPX_CLI_JS = $NPX_CLI_JS.Replace("``", "````") - $NPX_NO_REDIRECTS_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + $NPX_NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text - $NPX_ARGS = $NPX_NO_REDIRECTS_COMMAND_ARR[1..($NPX_NO_REDIRECTS_COMMAND_ARR.Length - 1)] -join ' ' + + if ($NPX_NO_REDIRECTS_COMMAND -is [array] -and $NPX_NO_REDIRECTS_COMMAND.Length -gt 1) { + $NPX_ARGS = $NPX_NO_REDIRECTS_COMMAND[1..($NPX_NO_REDIRECTS_COMMAND.Length - 1)] -join ' ' + } else { + $NPX_ARGS = "" + } Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" } From 60b77f4ae453b62fb42c2dbc68985229f6164000 Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 28 Aug 2025 15:16:40 -0400 Subject: [PATCH 5/7] simplify workaround --- bin/npm.ps1 | 7 +------ bin/npx.ps1 | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/bin/npm.ps1 b/bin/npm.ps1 index e321c96a771c4..b7ddb7d54c22f 100644 --- a/bin/npm.ps1 +++ b/bin/npm.ps1 @@ -42,12 +42,7 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NPM_NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text - - if ($NPM_NO_REDIRECTS_COMMAND -is [array] -and $NPM_NO_REDIRECTS_COMMAND.Length -gt 1) { - $NPM_ARGS = $NPM_NO_REDIRECTS_COMMAND[1..($NPM_NO_REDIRECTS_COMMAND.Length - 1)] -join ' ' - } else { - $NPM_ARGS = "" - } + $NPM_ARGS = ($NPM_NO_REDIRECTS_COMMAND | Select-Object -Skip 1) -join ' ' Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" } diff --git a/bin/npx.ps1 b/bin/npx.ps1 index 13595d8e8c9de..e51f4564b2f60 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -42,12 +42,7 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NPX_NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text - - if ($NPX_NO_REDIRECTS_COMMAND -is [array] -and $NPX_NO_REDIRECTS_COMMAND.Length -gt 1) { - $NPX_ARGS = $NPX_NO_REDIRECTS_COMMAND[1..($NPX_NO_REDIRECTS_COMMAND.Length - 1)] -join ' ' - } else { - $NPX_ARGS = "" - } + $NPX_ARGS = ($NPX_NO_REDIRECTS_COMMAND | Select-Object -Skip 1) -join ' ' Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" } From b53a4a6f9c71a44d7ba78482301602dcf891017d Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 28 Aug 2025 15:52:44 -0400 Subject: [PATCH 6/7] update variable name since it doesn't just handle redirection operator --- bin/npm.ps1 | 4 ++-- bin/npx.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/npm.ps1 b/bin/npm.ps1 index b7ddb7d54c22f..2447d0181ee04 100644 --- a/bin/npm.ps1 +++ b/bin/npm.ps1 @@ -40,9 +40,9 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPM_CLI_JS = $NPM_CLI_JS.Replace("``", "````") - $NPM_NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + $NPM_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text - $NPM_ARGS = ($NPM_NO_REDIRECTS_COMMAND | Select-Object -Skip 1) -join ' ' + $NPM_ARGS = ($NPM_COMMAND_ARR | Select-Object -Skip 1) -join ' ' Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" } diff --git a/bin/npx.ps1 b/bin/npx.ps1 index e51f4564b2f60..091155b9edf7a 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -40,9 +40,9 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPX_CLI_JS = $NPX_CLI_JS.Replace("``", "````") - $NPX_NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + $NPX_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text - $NPX_ARGS = ($NPX_NO_REDIRECTS_COMMAND | Select-Object -Skip 1) -join ' ' + $NPX_ARGS = ($NPX_COMMAND_ARR | Select-Object -Skip 1) -join ' ' Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" } From 8fc4b42b0997474a3c2de17d8b8c6ce342d10e3f Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Tue, 2 Sep 2025 11:22:00 -0400 Subject: [PATCH 7/7] Namechange --- bin/npm.ps1 | 4 ++-- bin/npx.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/npm.ps1 b/bin/npm.ps1 index 2447d0181ee04..efed03fe5655e 100644 --- a/bin/npm.ps1 +++ b/bin/npm.ps1 @@ -40,9 +40,9 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPM_CLI_JS = $NPM_CLI_JS.Replace("``", "````") - $NPM_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + $NPM_COMMAND_ARRAY = [Management.Automation.Language.Parser]::ParseInput($NPM_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text - $NPM_ARGS = ($NPM_COMMAND_ARR | Select-Object -Skip 1) -join ' ' + $NPM_ARGS = ($NPM_COMMAND_ARRAY | Select-Object -Skip 1) -join ' ' Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" } diff --git a/bin/npx.ps1 b/bin/npx.ps1 index 091155b9edf7a..3fe7b5435763a 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -40,9 +40,9 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input $NODE_EXE = $NODE_EXE.Replace("``", "````") $NPX_CLI_JS = $NPX_CLI_JS.Replace("``", "````") - $NPX_COMMAND_ARR = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). + $NPX_COMMAND_ARRAY = [Management.Automation.Language.Parser]::ParseInput($NPX_ORIGINAL_COMMAND, [ref] $null, [ref] $null). EndBlock.Statements.PipelineElements.CommandElements.Extent.Text - $NPX_ARGS = ($NPX_COMMAND_ARR | Select-Object -Skip 1) -join ' ' + $NPX_ARGS = ($NPX_COMMAND_ARRAY | Select-Object -Skip 1) -join ' ' Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" }