-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Closed as not planned
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.stale
Description
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
becauseprocess.argv[1]
will contain first argument instead of path to2.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
Metadata
Metadata
Assignees
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.stale