What is the problem this feature will solve?
We can provide query and hash in ESM imports:
// 1.mjs
import './2.mjs?key=value#hash';
// 2.mjs
const { search, hash } = new URL(import.meta.url);
console.log({ search, hash });
$ node 1.mjs
{ search: '?key=value', hash: '#hash' }
However, AFAICT there is no way to provide them directly to main module:
$ node 2.mjs
{ search: '', hash: '' }
What is the feature you are proposing to solve the problem?
Command line option(s) to provide search and hash, e.g.
$ node 2.mjs --import-search="?key=value" --import-hash="#hash"
or
$ node 2.mjs --esm-appendix="key=value#hash"
What alternatives have you considered?
Right now we can do this with empty script:
$ node --input-type="module" --import="./2.mjs?key=value#hash" < /dev/null
{ search: '?key=value', hash: '#hash' }
$ node --import="./2.mjs?key=value#hash" --eval=";"
{ search: '?key=value', hash: '#hash' }
Which
- potentially will mess up with
import.meta.isMain
- messes up with
process.argv because process.argv[1] will contain first argument instead of path to 2.mjs
- requires to provide URL, i.e. to percent-encode special characters, to start relative paths with
. or .., and to use forward slashes on Windows
What is the problem this feature will solve?
We can provide query and hash in ESM imports:
However, AFAICT there is no way to provide them directly to main module:
What is the feature you are proposing to solve the problem?
Command line option(s) to provide
searchandhash, e.g.What alternatives have you considered?
Right now we can do this with empty script:
Which
import.meta.isMainprocess.argvbecauseprocess.argv[1]will contain first argument instead of path to2.mjs.or.., and to use forward slashes on Windows