Skip to content

Add self as preload script, to load in worker_threads and child processes. #1177

Open
@cspotcode

Description

@cspotcode

When user runs ts-node ./index.ts and the code spawns worker_threads and/or child_processes, these should also be able to require() .ts files.

This already happens with node --require ts-node/register, since that's inherited by child processes and worker threads.

Should we make our ts-node bin entrypoint behave the same way?


yarn uses NODE_OPTIONS='--require .pnp.js' to hook their PnP API into the runtime.
nyc uses some sort of child_process.spawn monkey-patching, but they also don't support worker_threads. Why don't they use NODE_OPTIONS?

nodejs/node#36531
nodejs/node#29117

Are there performance concerns? Can we avoid child processes/threads re-resolving tsconfig when the parent has already done so? By passing the necessary config via an env var, or maybe prepending a --require /tmp/ts-node-config-497f86.cjs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementresearchNeeds design work, investigation, or prototyping. Implementation uncertain.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions