From acf6bfe199ec6794e7ef595643016a90006ce3ec Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 30 Apr 2024 19:08:35 -0700 Subject: [PATCH] fix(powershell): use Invoke-Expression to pass args Co-authored-by: noseratio --- bin/npm.ps1 | 7 +++++-- bin/npx.ps1 | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/npm.ps1 b/bin/npm.ps1 index 04a1fd478ef9d..fbcef907ed481 100644 --- a/bin/npm.ps1 +++ b/bin/npm.ps1 @@ -22,11 +22,14 @@ if (Test-Path $NPM_PREFIX_NPM_CLI_JS) { $NPM_CLI_JS=$NPM_PREFIX_NPM_CLI_JS } +$NPM_ARGS = $MyInvocation.Line.Substring($MyInvocation.InvocationName.Length).Trim() +$INVOKE_NPM = "$($NODE_EXE -Replace ' ', '` ') $($NPM_CLI_JS -Replace ' ', '` ') $NPM_ARGS".Trim() + # Support pipeline input if ($MyInvocation.ExpectingInput) { - $input | & $NODE_EXE $NPM_CLI_JS $args + $input | Invoke-Expression $INVOKE_NPM } else { - & $NODE_EXE $NPM_CLI_JS $args + Invoke-Expression $INVOKE_NPM } exit $LASTEXITCODE diff --git a/bin/npx.ps1 b/bin/npx.ps1 index 28dae51b22ca9..a3562ef309134 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -22,11 +22,14 @@ if (Test-Path $NPM_PREFIX_NPX_CLI_JS) { $NPX_CLI_JS=$NPM_PREFIX_NPX_CLI_JS } +$NPX_ARGS = $MyInvocation.Line.Substring($MyInvocation.InvocationName.Length).Trim() +$INVOKE_NPX = "$($NODE_EXE -Replace ' ', '` ') $($NPX_CLI_JS -Replace ' ', '` ') $NPX_ARGS".Trim() + # Support pipeline input if ($MyInvocation.ExpectingInput) { - $input | & $NODE_EXE $NPX_CLI_JS $args + $input | Invoke-Expression $INVOKE_NPX } else { - & $NODE_EXE $NPX_CLI_JS $args + Invoke-Expression $INVOKE_NPX } exit $LASTEXITCODE