I am looking for a CLI tool that can run a .ts file directly, without writing to a file. That would mean it transpiles in memory, and then somehow passes that data to the node.js executable. Does such an executable exist?
Asked
Active
Viewed 1,138 times
1
-
You can "compile" a node.js module from string data via https://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory – Alexander Mills Jun 26 '17 at 04:10
-
2A shell pipe is what you describe – cat Jun 26 '17 at 04:17
-
well node.js cannot compile a file from stdin. and also tsc (the typescript compiler) by default writes files out, not to stdout...so using shell pipes is not possible right off the bat, that's the point of the question. – Alexander Mills Jun 26 '17 at 04:47
2 Answers
4
Does such an executable exist?
Yes. Its called ts-node
: https://github.com/TypeStrong/ts-node

basarat
- 261,912
- 58
- 460
- 511
0
As one commenter suggested, you can also do:
tsc --outfile /dev/stdout <file> | node

Alexander Mills
- 90,741
- 139
- 482
- 817