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!

@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.13%. Comparing base (0bcc6ef) to head (cb3f4d7).
⚠️ Report is 1 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.13%   -0.01%     
==========================================
  Files         741      741              
  Lines      242080   242092      +12     
  Branches    45563    45564       +1     
==========================================
- Hits       218213   218211       -2     
- Misses      15375    15391      +16     
+ Partials     8492     8490       -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 37 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.

Signed-off-by: James Ross <james@jross.me>
@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
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.

3 participants