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

Allow custom file extensions in --eval from CLI

Open PartMan7 opened this issue 1 year ago • 0 comments

Desired Behavior

As part of a prebuild step in a project of mine, I'm reading multiple tsx files, inserting a small snippet, and running them through ts-node --eval. I would like this to run if I specify an appropriate file extension.

Is this request related to a problem?

In the above case, even if I pass the appropriate config, due to the file name in eval being hardcoded as [eval].ts, it ends up evaluated as .ts.

image
npx ts-node --swc --compilerOptions '{"jsx":"react-jsx"}' -e 'const element = <div>You lost the game</div>;'

With the addition of a flag like --eval-extension '.tsx', the above could now work:

npx ts-node --swc --compilerOptions '{"jsx":"react-jsx"}' --eval-extension '.tsx' -e 'const element = <div>You lost the game</div>;'

Alternatives you've considered

Currently I'm adding an additional step to the process, where I pipe the output to an intermediate file and then interpret it through ts-node, but this is a bypass for an apparent shortcoming of the -e flag.

Additional context

This was run locally on 10.9.1.

PartMan7 avatar Sep 04 '24 08:09 PartMan7