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

Handle the case when node called with the "-e" argument #2163

Closed
atleta opened this issue Mar 1, 2024 · 4 comments
Closed

Handle the case when node called with the "-e" argument #2163

atleta opened this issue Mar 1, 2024 · 4 comments

Comments

@atleta
Copy link

atleta commented Mar 1, 2024

When you call node with the -e argument and supply the script (commands) to execute on the command line then the script parameter will be missing from process.argv (at index 1) so automatic parsing ({from: 'node'}) will fail.

As far as I can see this case can be handled by looking into process.execArgv and checking for the presence of the -e or --eval option.

(One might use this option to run non-trivial scripts e.g. when calling a node process in a docker container.)

@shadowspawn
Copy link
Collaborator

shadowspawn commented Mar 1, 2024

For interest, did you encounter this lack in use or noticed in code?

Yes, this is a case we could handle.

I wrote code for this in parseargs where node eval/print was a use case being considered:

@atleta
Copy link
Author

atleta commented Mar 4, 2024

I ran into this when I changed the way I called a script (running in a docker instance) from another app.

It took a bit of investigation to figure out what caused the problem as node is not my main development environment and I'd say, this definitely is a surprising behavior. Knowing what the problem is, the workaround is 2 lines of code but, I think, it's better to take care of it in a higher-level library, like this.

@shadowspawn
Copy link
Collaborator

shadowspawn commented Mar 5, 2024

I have opened a PR which will autodetect node --eval and node --print when no arguments are specified to .parse(). To avoid breaking existing code or getting weird test results with custom argv depending on how node is launched, { from: 'node' } still assumes "normal" node conventions.

(And updated documentation to match.)

@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Apr 7, 2024
@shadowspawn
Copy link
Collaborator

Released in v12.1.0

@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
Projects
None yet
Development

No branches or pull requests

2 participants