module: add `--module` option
This adds an option to directly load ESM entry point by absolute or relative URL.
Allows:
$ node --module file.mjs?qwe=rty#uio
$ node --module relative/url/to/file.mjs?qwe=rty#uio
$ node --module /absolute/url/to/file.mjs?qwe=rty#uio
$ node --module win32_style\\url\\to\\file.mjs?qwe=rty#uio
$ node --module file:///wellformed/url/to/file.mjs?qwe=rty#uio
$ node --module file%20with%20spaces.mjs?qwe=rty#uio
$ node --module "file with spaces.mjs?qwe=rty#uio"
$ node --experimental-network-imports --module "https://example.com/module.js"
$ node --module esm_file_without_extension?qwe=rty#uio
$ node --module "data:text/javascript,console.log(new URL(import.meta.url));"?qwe=rty#uio
Doesn't allow:
use `node --import my-package` instead
$ node --module my-package
I.e. most importantly, it allows to
- load ES module as entry point with user-defined
search
andhash
- load ES module explicitly in ESM mode no matter what file extension it has
- load it explicitly as URL, with consistent percent-decoding
Without breaking changes to how node path/to/file.js
works.
Might be related to: https://github.com/nodejs/node/issues/34049 Fixes: https://github.com/nodejs/node/issues/46009 Fixes: https://github.com/nodejs/node/issues/49204
I'm not sure if this is the most correct way to implement it (or if a better alternative is planned), hence draft.
cc @nodejs/modules