Skip to content
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

Add auto-detection of args when node evaluating script code on command-line #2164

Merged
merged 5 commits into from
Apr 7, 2024

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Mar 3, 2024

Pull Request

Problem

program.parse() will not detect the user arguments correctly when script supplied with node --print "script..." or node --eval "script...".

See: #2163

% node --eval 'const { program } = require("./index.js"); console.log(program.parse().args);' 1 2 3                                            develop
[ '2', '3' ]

Solution

Look for the relevant options in process.execArgv to detect these special cases.

References:

% node --eval 'const { program } = require("./index.js"); console.log(program.parse().args);' 1 2 3                                  feature/node-repl
[ '1', '2', '3' ]

ChangeLog

  • add: auto-detect special node flags node --eval and node --print when call .parse() with no arguments

@shadowspawn shadowspawn marked this pull request as ready for review March 3, 2024 07:13
@shadowspawn shadowspawn changed the title Add auto-detection of node evaluating script code on command-line Add auto-detection of args when node evaluating script code on command-line Mar 3, 2024
@shadowspawn shadowspawn marked this pull request as draft March 4, 2024 19:27
@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Mar 4, 2024

I am thinking the "node" mode should be smart about eval/print too, since it is a node behaviour, and would be quite like the "electron" behaviour.

And being more explicit in the README that no arguments is the auto-detect mode and "node" is the default if arguments are supplied.

And whether changing explicit "node" mode may make it a breaking semver-major change for the few people who have already coded it themselves. 😢 I think perhaps so, since the README is quite explicit about the existing behaviour:

'node': default, argv[0] is the application and argv[1] is the script being run, with user parameters after that

@shadowspawn shadowspawn added the semver: major Releasing requires a major version bump, not backwards compatible label Mar 4, 2024
@shadowspawn shadowspawn removed the semver: major Releasing requires a major version bump, not backwards compatible label Mar 5, 2024
@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Mar 5, 2024

I decided I am happy with the full-auto just when Commander is deciding everything!

Supplied arguments means we don't know where they came from, so play safe and assume normal node.

Did big rework of docs. Might be overkill for the JSDoc/TSDoc, but parse is a fundamental method to get right. (Could trim it down if too much!)

@shadowspawn shadowspawn marked this pull request as ready for review March 5, 2024 07:55
@shadowspawn shadowspawn merged commit b9ca390 into tj:develop Apr 7, 2024
8 checks passed
@shadowspawn shadowspawn deleted the feature/node-repl branch April 7, 2024 00:28
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Apr 7, 2024
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label May 18, 2024
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