Ts-node: Production ready without cache

Created on 11 Feb 2019  Â·  3Comments  Â·  Source: TypeStrong/ts-node

I am aware, this has been addressed in #104 and #653 and before I get trashed for that, I want to point out that PR #701 changes a lot :point_up:

Since I still could not find any up-to-date info about this (e.g. expected to find in readme), what is the current state of cache? As I ran through the implementation I noticed there is an in-memory solution implemented at the moment.

Is it something that would have impact on the production usage, or it is of no importance?

question

Most helpful comment

In production, I'd recommend using --transpile-only. In general, it shouldn't affect much - most likely the production run will be the first execution of the code anyway, so using a cache isn't particularly useful there. It's meant to be more useful in development, e.g. repeated execution of similar code. Unfortunately there is a bug in the naive cache - for TypeScript and type checking it should have been taking into account a recursive hash of all dependencies, not just its own file.

All 3 comments

In production, I'd recommend using --transpile-only. In general, it shouldn't affect much - most likely the production run will be the first execution of the code anyway, so using a cache isn't particularly useful there. It's meant to be more useful in development, e.g. repeated execution of similar code. Unfortunately there is a bug in the naive cache - for TypeScript and type checking it should have been taking into account a recursive hash of all dependencies, not just its own file.

Hello @blakeembrey, thanks for your great answers. Currently I'm using it in development and I consider using it in production only for one case…

I'm using .graphql files and they are living in the same directory as my sources, which is cool for module pattern and single responsability files.

Using ts-node would allows me to prevent copying files, in the build process ? What do you suggest in such case ?

Regards

@ScreamZ Typically I create a directory a directory at the root of the project that both can import upward from (e.g. ./{src,dist,assets}), or I have a step after the compiler that'll just copy the files I care about from src into dist.

Was this page helpful?
0 / 5 - 0 ratings