ESM support: can't recognize '--experimental-specifier-resolution' flag passed via NODE_OPTIONS
koshic opened this issue · 2 comments
Code at
uses process.execArgv to get options and doesn't analyze NODE_OPTIONS anyhow.I'm marking this as "help wanted" to indicate that we'll wait for a pull request. This seems like a straightforward contribution.
node-esm-resolve-implementation.js
is largely copied from node's own source code.
ts-node/dist-raw/node-esm-resolve-implementation.js
Lines 1 to 4 in 44c61af
To write an ESM loader, we need to mimic many built-in behaviors of node. Unfortunately node does not expose this functionality via an API. So our best option for maintainability is to copy-paste node's own implementation where appropriate, tweaking as needed.
See also: discussion in #1010, where @evg656e helped me implement our execArgv
parsing.
Yep, I missed the need to parse the NODE_OPTIONS
environment variable in the initial implementation.
Unfortunately, the arg
parser does not allow getting options of the environment variables (like 'yargs` .env function does).
The workaround to use ParseNodeOptionsEnvVar from node source.
I rewrote getOptionValue code in my branch.
As you can see, the code becomes quite messy, so it may be worth putting it into a separate file to keep main module clean.