ts-node icon indicating copy to clipboard operation
ts-node copied to clipboard

Always put brotli payload in execArgv, even for non-esm bootstrapping

Open cspotcode opened this issue 3 years ago • 0 comments

Right now, if you fork() a ts-node process, the child gets the ts-node bin entrypoint and the same flags passed to ts-node: --project, etc. Yet if you've launched with --esm, then the child receives a pre-packed brotli payload of parsed configuration & bootstrapping information.

Without brotli, child process re-loads tsconfig, re-does all config work With brotli, some / most of config loading is already done and baked into the brotli payload

Should these 2 codepaths be unified? So that we always put the brotli payload in execArgv?

Once we have fully completed bootstrapping and config parsing, we can re-pack the brotli payload and put it in execArgv.

Pros

  • prevents subsequent child processes from repeating any of that config work
    • skip loading certain deps
    • skip loading TS compiler entirely if using SWC?
  • children are forced to use the same tsconfig and flags even if they're spawned in a different working directory
    • probably a good thing for simplicity
    • opens the door for future work where children talk to the same language service in external process perhaps?

Cons

  • breaks rare cases where child_processes are expected to re-discover tsconfig
    • these cases can be accomplished by scrubbing the execArgv / re-spawning ts-node CLI using cross-spawn or similar

Other notes

Will only happen in our bin.ts bootstrapping; not --loader nor register() codepaths, since the latter do not control the node process' startup.

cspotcode avatar Jul 10 '22 14:07 cspotcode