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

`TS_NODE_OPTIONS` to mimic `NODE_OPTIONS`

Open cspotcode opened this issue 3 years ago • 2 comments

Desired Behavior

TS_NODE_OPTIONS allows specifying multiple ts-node CLI flags in a single env var. Perhaps we deprecate various other env vars in the process, to reduce our env var API surface.

Not sure if it should work with programmatic ts-node usage though. Would require parsing TS_NODE_OPTIONS as argv but outside of bin.ts

cspotcode avatar Jan 28 '21 21:01 cspotcode

How would these options merge with what's defined inside a tsconfig? I am assuming there are other sources of arguments as well, but let's try to keep it simple for now.

My guess would be that the values within TS_NODE_OPTIONS should take precedence, in which case the question becomes do we merge or overwrite?

seivan avatar Apr 07 '21 16:04 seivan

I figure they can be treated the same as if they had been passed in the argv array, so they can get the same level of precedence as when you pass them to our CLI.

When you do ts-node --transpile-only --./index.ts it will load tsconfig.json by default, and it is already merging the --transpile-only with whatever it finds in tsconfig.json. We should keep the same logic here.

For splitting the TS_NODE_OPTIONS into an array, we can use the same function we use to parse NODE_OPTIONS, which we have to do for some of our ESM loader stuff. Then we can pass this array to the same code we use for parsing the argv array today.

We might need to slightly refactor bin.ts, since now we will be attempting argv parsing even when we're not being invoked as a CLI tool.

cspotcode avatar Apr 07 '21 17:04 cspotcode