From 08ae095fe58308c4201aae022f6d248024cdce4a Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Thu, 15 May 2025 11:56:11 -0400 Subject: [PATCH] fix(powershell): support pipeline input with Invoke-Expression --- bin/npm.ps1 | 4 +++- bin/npx.ps1 | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/npm.ps1 b/bin/npm.ps1 index 08fabb66761ce..77bc9a5777c80 100644 --- a/bin/npm.ps1 +++ b/bin/npm.ps1 @@ -37,7 +37,9 @@ if ($MyInvocation.Line) { # used "-Command" argument # Support pipeline input if ($MyInvocation.ExpectingInput) { - $input | Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" + $input = (@($input) -join "`n").Replace("``", "````") + + Invoke-Expression "Write-Output `"$input`" | & `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" } else { Invoke-Expression "& `"$NODE_EXE`" `"$NPM_CLI_JS`" $NPM_ARGS" } diff --git a/bin/npx.ps1 b/bin/npx.ps1 index f3e8152b30cca..e89536bf3542a 100644 --- a/bin/npx.ps1 +++ b/bin/npx.ps1 @@ -37,7 +37,9 @@ if ($MyInvocation.Line) { # used "-Command" argument # Support pipeline input if ($MyInvocation.ExpectingInput) { - $input | Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" + $input = (@($input) -join "`n").Replace("``", "````") + + Invoke-Expression "Write-Output `"$input`" | & `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" } else { Invoke-Expression "& `"$NODE_EXE`" `"$NPX_CLI_JS`" $NPX_ARGS" }