Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ESM node processes being unable to fork into other scripts #1814

Merged
merged 11 commits into from Jul 13, 2022

Commits on Jul 3, 2022

  1. Fix ESM node processes being unable to fork into other scripts

    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.
    devversion committed Jul 3, 2022
    Copy the full SHA
    796b593 View commit details
    Browse the repository at this point in the history
  2. Fix --cwd to actually set the working directory and work with ESM c…

    …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`.
    devversion committed Jul 3, 2022
    Copy the full SHA
    d78e437 View commit details
    Browse the repository at this point in the history

Commits on Jul 12, 2022

  1. changes based on review

    cspotcode committed Jul 12, 2022
    Copy the full SHA
    38befcc View commit details
    Browse the repository at this point in the history
  2. lint-fix

    cspotcode committed Jul 12, 2022
    Copy the full SHA
    ad19d9f View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    e112f7c View commit details
    Browse the repository at this point in the history
  4. Tweak basic working dir tests to verify that --cwd affects entrypoint…

    … resolution but not process.cwd()
    cspotcode committed Jul 12, 2022
    Copy the full SHA
    112a47c View commit details
    Browse the repository at this point in the history
  5. update forking tests:

    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
    cspotcode committed Jul 12, 2022
    Copy the full SHA
    d52c0b5 View commit details
    Browse the repository at this point in the history

Commits on Jul 13, 2022

  1. use swc compiler to avoid issue with ancient TS versions not understa…

    …nding import.meta.url syntax
    cspotcode committed Jul 13, 2022
    Copy the full SHA
    b7bcdcf View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    3d9e040 View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    5164e2f View commit details
    Browse the repository at this point in the history
  4. final review updates

    cspotcode committed Jul 13, 2022
    Copy the full SHA
    58ddc33 View commit details
    Browse the repository at this point in the history