Skip to content

fix(powershell): use Invoke-Expression to pass args #8343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 25, 2025

Conversation

alexsch01
Copy link
Contributor

@alexsch01 alexsch01 commented Jun 3, 2025

backports of

#8278
#8297
#8318

for npm 10.x series

alexsch01 added 3 commits June 3, 2025 13:54
Continuation of npm#8267 @mbtools 

---

This fixes the command `npm test -- hello -p1 world -p2 "hello world"
--q1=hello world --q2="hello world"` in Windows PowerShell and pwsh7
- where the "test" script prints all the arguments passed after the
first "--" in the command above

Before this change

```
PS> npm test -- hello -p1 world -p2 "hello world" --q1=hello world --q2="hello world"
npm warn "world" is being parsed as a normal command line argument.
npm warn "hello world" is being parsed as a normal command line argument.
npm warn Unknown cli config "--p1". This will stop working in the next major version of npm.
npm warn Unknown cli config "--p2". This will stop working in the next major version of npm.
npm warn Unknown cli config "--q1". This will stop working in the next major version of npm.
npm warn Unknown cli config "--q2". This will stop working in the next major version of npm.

> test@1.0.0 test
> node args.js hello world hello world world

hello
world
hello world
world
```

With this change

```
PS> npm test -- hello -p1 world -p2 "hello world" --q1=hello world --q2="hello world"

> test@1.0.0 test
> node args.js hello -p1 world -p2 hello world --q1=hello world --q2=hello world

hello
-p1
world
-p2
hello world
--q1=hello
world
--q2=hello world
```

---

Also, fixes comma-separated values in Windows PowerShell and pwsh7

Before this change

```
PS> npm help a=1,b=2,c=3
No matches in help for: a=1 b=2 c=3
```

With this change

```
PS> npm help a=1,b=2,c=3
No matches in help for: a=1,b=2,c=3
```
- prevent pipeline input from using Invoke-Expression
- allow redirect operator to behave again by stripping redirects out
from Invoke-Expression
@alexsch01 alexsch01 requested a review from a team as a code owner June 3, 2025 18:01
@alexsch01 alexsch01 changed the title fix(powershell): use Invoke-Expression to pass args (#8278, #8297, #8318) fix(powershell): use Invoke-Expression to pass args (https://github.com/npm/cli/pull/8278, #8297, #8318) Jun 3, 2025
@alexsch01 alexsch01 changed the title fix(powershell): use Invoke-Expression to pass args (https://github.com/npm/cli/pull/8278, #8297, #8318) fix(powershell): use Invoke-Expression to pass args (https://github.com/npm/cli/pull/8278, https://github.com/npm/cli/pull/8297, https://github.com/npm/cli/pull/8318) Jun 3, 2025
@alexsch01 alexsch01 changed the title fix(powershell): use Invoke-Expression to pass args (https://github.com/npm/cli/pull/8278, https://github.com/npm/cli/pull/8297, https://github.com/npm/cli/pull/8318) fix(powershell): use Invoke-Expression to pass args Jun 3, 2025
@wraithgar
Copy link
Member

Linting failure is because we somehow didn't catch the update for our eslint config in this backport branch when doing updates. I'll get a PR made for that which will make that error go away.

cf: https://github.com/npm/eslint-config/blob/17468c9113c42f3b47528bf9410972c1351dc041/CHANGELOG.md#510-2025-01-14

@alexsch01
Copy link
Contributor Author

@wraithgar good news, the last part of this just landed in NodeJS 24.3.0 and it works as I expected!

Copy link
Member

@wraithgar wraithgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linting failure was fixed in #8378

@wraithgar wraithgar merged commit 7cff878 into npm:release/v10 Jun 25, 2025
26 of 27 checks passed
@github-actions github-actions bot mentioned this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants