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

Support query parameters (and hash) in CLI paths #33163

Closed
brettz9 opened this issue Apr 30, 2020 · 4 comments
Closed

Support query parameters (and hash) in CLI paths #33163

brettz9 opened this issue Apr 30, 2020 · 4 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. feature request Issues that request new features to be added to Node.js. stale

Comments

@brettz9
Copy link

brettz9 commented Apr 30, 2020

Is your feature request related to a problem? Please describe.

I am interested in having my scripts respond to arguments supplied by the calling file, rather than for the application as a whole (i.e., checking the likes of new URL(import.meta.url).searchParams.get('someParam') rather than process.argv).

This works well when a file imports another. In polyglot files too, it works to get the query string and hash in the browser (Chrome or Firefox at least) no matter whether the import originates in HTML or in JavaScript.

But I get a MODULE_NOT_FOUND error when trying the likes of:

node --experimental-modules  index.mjs?someParam=1

...apparently as it is looking for a file here rather than a (portion of) a URL.

Describe the solution you'd like

Allow the supplied file to be treated as a URL at least as far as the query string and any hash.

Describe alternatives you've considered

It duplicates effort to add special process.argv handling (and it could interfere if the same file is used in an application which has a different root file yet checks process.argv as well as import.meta.url).

Thanks!

@himself65 himself65 added esm Issues and PRs related to the ECMAScript Modules implementation. feature request Issues that request new features to be added to Node.js. labels Apr 30, 2020
@bnoordhuis
Copy link
Member

bnoordhuis commented May 4, 2020

That's pretty much impossible to implement even if it was a good idea because ? is a valid path character on UNIX systems. E.g. index.mjs?file=home.mjs is a legal filename.

You might counter that no one in their right mind would name a file that way but tools that auto-generate files surely can and probably will.

@jasnell
Copy link
Member

jasnell commented May 4, 2020

The only possible way to handle this would be to require that such input be a proper file:// URL with appropriate escaping for special characters that happen to be in the filename, e.g.

node --experimental-modules file:///path/to/my/index%3f.mjs?someParam=1

This is also just a little bit problematic given that file: is a valid directory name on some systems but it's exceedingly unlikely to be an issue in practice.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2022

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Mar 8, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot closed this as completed Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. feature request Issues that request new features to be added to Node.js. stale
Projects
None yet
Development

No branches or pull requests

4 participants