Fix ESM node processes being unable to fork into other scripts by devversion · Pull Request #1814 · TypeStrong/ts-node

@devversion mentioned this pull request

Jun 24, 2022

cspotcode

cspotcode

devversion

Currently, Node processes instantiated through the `--esm` flag result
in a child process being created so that the ESM loader can be
registered. This works fine and is reasonable.

The child process approach to register ESM hooks currently prevents
the NodeJS `fork` method from being used because the `execArgv`
propagated into forked processes causes `ts-node` (which is also
propagated as child exec script -- this is good because it allows nested
type resolution to work) to always execute the original entry-point,
causing potential infinite loops because the designated fork module
script is not executed as expected.

This commit fixes this by not encoding the entry-point information into
the state that is captured as part of the `execArgv`. Instead the
entry-point information is always retrieved from the parsed rest command
line arguments in the final stage (`phase4`).

Fixes TypeStrong#1812.
…hild process

Currently the `--esm` option does not necessarily do what the
documentation suggests. i.e. the script does not run as if the working
directory is the specified directory.

This commit fixes this, so that the option is useful for TSConfig
resolution, as well as for controlling the script working directory.

Also fixes that the CWD encoded in the bootstrap brotli state for the
ESM child process messes with the entry-point resolution, if e.g. the
entry-point in `child_process.fork` is relative to a specified `cwd`.

@cspotcode cspotcode linked an issue

Jul 10, 2022

that may be closed by this pull request

@cspotcode

@cspotcode

cspotcode

cspotcode

cspotcode

@cspotcode

… resolution but not process.cwd()
disable non --esm test with comment about known bug and link to tickets
make tests set cwd for fork() call, to be sure it is respected and not overridden by --cwd
…nding import.meta.url syntax

@cspotcode

@cspotcode

@cspotcode

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request

Jul 18, 2022

@Odida Odida mentioned this pull request

Jul 17, 2024