node icon indicating copy to clipboard operation
node copied to clipboard

util: fix parseArgs skipping first positional arg with --eval= and --…

Open azadgupta1 opened this issue 1 month ago • 9 comments

Fix: handle --eval= and --print= correctly in getMainArgs()

Fixes #60808

parseArgs() was skipping the first positional argument when Node was started with --eval= or --print=. The logic only checked for --eval / --print and missed the --eval=... / --print=... forms.

This patch adds startsWith('--eval=') and startsWith('--print=') checks so getMainArgs() returns the correct slice of process.argv.

After this fix, positional arguments are preserved correctly for all eval/print forms.

azadgupta1 avatar Nov 22 '25 14:11 azadgupta1

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 88.53%. Comparing base (7fd3688) to head (dc3236b). :warning: Report is 119 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60814      +/-   ##
==========================================
- Coverage   88.56%   88.53%   -0.03%     
==========================================
  Files         703      703              
  Lines      208254   208425     +171     
  Branches    40156    40197      +41     
==========================================
+ Hits       184430   184537     +107     
- Misses      15828    15893      +65     
+ Partials     7996     7995       -1     
Files with missing lines Coverage Δ
lib/internal/util/parse_args/parse_args.js 99.26% <100.00%> (-0.01%) :arrow_down:

... and 68 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 22 '25 16:11 codecov[bot]

Thanks for the guidance, appreciate it!

azadgupta1 avatar Nov 25 '25 10:11 azadgupta1

CI: https://ci.nodejs.org/job/node-test-pull-request/70315/

nodejs-github-bot avatar Nov 25 '25 20:11 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/70319/

nodejs-github-bot avatar Nov 26 '25 01:11 nodejs-github-bot

Nice catch and change. I like checking the internal options instead of doing a pseudo parse of execArgv.

shadowspawn avatar Dec 04 '25 22:12 shadowspawn

Just checking in — let me know if anything else is required from me.

azadgupta1 avatar Dec 07 '25 13:12 azadgupta1

There's https://github.com/nodejs/node/pull/60814#pullrequestreview-3540315205 regarding the order of the test assertions, otherwise all good 👍

Renegade334 avatar Dec 07 '25 15:12 Renegade334

CI: https://ci.nodejs.org/job/node-test-pull-request/70453/

nodejs-github-bot avatar Dec 09 '25 17:12 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/70459/

nodejs-github-bot avatar Dec 09 '25 19:12 nodejs-github-bot

Landed in 060deae99b03

Renegade334 avatar Dec 11 '25 01:12 Renegade334