Skip to content

src: list scripts when --run has no command - #64606

Open
Cherry wants to merge 1 commit into
nodejs:mainfrom
Cherry:run-list-scripts
Open

src: list scripts when --run has no command#64606
Cherry wants to merge 1 commit into
nodejs:mainfrom
Cherry:run-list-scripts

Conversation

@Cherry

@Cherry Cherry commented Jul 19, 2026

Copy link
Copy Markdown

This extends the behaviour when you run node --run <unknown script> that prints a list of available scripts, to now print available scripts when you simply run node --run, to mimic the behaviour of npm run, etc.

$ node --run
Available scripts are:
  test: node --test
  build: node build.js

Previously, node --run with no command errored with --run requires an argument.

This is my first contribution to Node.js so while I've tried to read and follow everything, please let me know if I'm missing anything!

Fixes: #64870

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 19, 2026
@Cherry
Cherry force-pushed the run-list-scripts branch from 228c3da to 141c9e6 Compare July 19, 2026 21:12
Comment thread src/node_options-inl.h
Comment on lines +457 to +459
// `--run` may be passed without a script name to list available scripts,
// so an omitted value is not an error and must not swallow a later flag.
const bool optional_value = name == "--run";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a better solution to modifying the options parser directly? We have other CLI flags that have different behavior depending on whether or not they have an argument passed?

How does --inspect do this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm not entirely familiar with the code, but looking at --inspect, it's a boolean option so works a bit differently I think:

node/src/node_options.cc

Lines 475 to 479 in 0bcc6ef

AddOption("--inspect",
"activate inspector on host:port (default: 127.0.0.1:9229)",
&DebugOptions::inspector_enabled,
kAllowedInEnvvar);
AddAlias("--inspect=", { "--inspect-port", "--inspect" });

So --inspect and --inspect=1234 work, but --inspect 1234 isn't valid.

If I'm understanding correctly, --run can't do this, because it's space separated.

To avoid the hardcoded name == "--run", what would you suggest?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm, perhaps I was mis-remembering that --inspect required an = to run 😓. I'm still wary about changing the parser, since there probably should be a way for a flag to be passed with an optional value, regardless of =.

Sorry about misremembering, I'll ask around to see if there's a way to do this, and if not, we can always add it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks! It's also very possible I'm misreading this or missing something, and this is already supported somewhere - sorry if so!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I doubt that, you (so far) demonstrate a great understanding of the codebase. It's probable that we just never encountered this scenario before.

Great work so far :-)

Comment thread src/node_task_runner.cc Outdated
@Cherry
Cherry force-pushed the run-list-scripts branch from 141c9e6 to cb3f4d7 Compare July 19, 2026 23:19
@avivkeller avivkeller added the cli Issues and PRs related to the Node.js command line interface. label Jul 19, 2026
@avivkeller

Copy link
Copy Markdown
Member

Implementation LGTM. I'm not giving this the green check while I look into better ways of actually detecting the option-less flag, but everything from that point on is great :)

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.20690% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.15%. Comparing base (bec3d0b) to head (8f4567d).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/node_options-inl.h 50.00% 0 Missing and 3 partials ⚠️
src/node_task_runner.cc 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #64606   +/-   ##
=======================================
  Coverage   90.14%   90.15%           
=======================================
  Files         746      746           
  Lines      242763   242775   +12     
  Branches    45761    45773   +12     
=======================================
+ Hits       218848   218867   +19     
+ Misses      15402    15397    -5     
+ Partials     8513     8511    -2     
Files with missing lines Coverage Δ
src/node.cc 76.93% <100.00%> (ø)
src/node_options.h 98.01% <100.00%> (+<0.01%) ⬆️
src/node_task_runner.cc 89.78% <95.23%> (+0.45%) ⬆️
src/node_options-inl.h 83.51% <50.00%> (-0.19%) ⬇️

... and 30 files with indirect coverage changes

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

@Cherry

Cherry commented Jul 20, 2026

Copy link
Copy Markdown
Author

Just pushed to fix the markdown linting - looks like I needed to prepend to changes, not append, sorry!

The macOS test failure looks to be an unrelated flake, but let me know if not.

@Cherry
Cherry force-pushed the run-list-scripts branch from cb3f4d7 to a39f0dc Compare July 20, 2026 13:00
@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jul 31, 2026
@anonrig

anonrig commented Jul 31, 2026

Copy link
Copy Markdown
Member

Thank you James! @Cherry

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 31, 2026
@nodejs-github-bot

This comment was marked as outdated.

@Renegade334

Copy link
Copy Markdown
Member

GHA is borked on the current PR head, and looks like there will be lint issues to address anyway, so I'm just going to trigger a rebase.

@Renegade334 Renegade334 removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 31, 2026
@Cherry

Cherry commented Jul 31, 2026

Copy link
Copy Markdown
Author

Let me know if I can help with any of the linting (etc.) issues! Thanks all.

@anonrig

anonrig commented Jul 31, 2026

Copy link
Copy Markdown
Member

Let me know if I can help with any of the linting (etc.) issues! Thanks all.

@Cherry can you rebase and ask your agent to fix the linting errors please?

@Renegade334

Copy link
Copy Markdown
Member

The only complaint appears to be:

doc/node.1 is out of date; run `make node.1` to regenerate it.

@Cherry

Cherry commented Jul 31, 2026

Copy link
Copy Markdown
Author

Yeah I can rebase and try and fix that shortly!

Signed-off-by: James Ross <james@jross.me>
@Cherry
Cherry force-pushed the run-list-scripts branch from 95d7a9a to 8f4567d Compare July 31, 2026 17:11
@Cherry

Cherry commented Jul 31, 2026

Copy link
Copy Markdown
Author

Should be good now, thanks!

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. cli Issues and PRs related to the Node.js command line interface. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node --run should print list of available tasks

5 participants