Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to re-use the JS output by tsc #1020

Closed
zen0wu opened this issue Apr 30, 2020 · 3 comments
Closed

Add an option to re-use the JS output by tsc #1020

zen0wu opened this issue Apr 30, 2020 · 3 comments
Labels
enhancement research Needs design work, investigation, or prototyping. Implementation uncertain.

Comments

@zen0wu
Copy link

zen0wu commented Apr 30, 2020

Desired Behavior

Given ts-node already reads tsconfig.json, it should be able to figure out a mapping from source file -> target file. By checking the timestamp of both file, we should be able to know whether the target file is up-to-date and smartly just import that file instead of taking time to compile TS file.

There might be certain level of uncertain in some setup, so considering making it an option seems a reasonable choice.

Alternatively, if ts-node can detect a tsc (or tsc watch) running and wait for it to finish, seems like another good option.

Is this request related to a problem?

I want to run ts-node as my entrypoint to everything including the server and scripts, but typically it's slower than just running node on the transpiled JS (if there's one). I also want to keep the possibility if tsc watch is not running or the transpiled JS is outdated, ts-node will just "smartly" choose to compile TS file and import.

Alternatives you've considered

  • Doing the detection myself
  • Detect whether a tsc-watch is running

Additional context

@zen0wu
Copy link
Author

zen0wu commented Apr 30, 2020

It seems that we're also considering leveraging the new TSC api to obtain the tsbuildinfo map (#817)? Not sure if they could solve the same problem

@cspotcode cspotcode added enhancement research Needs design work, investigation, or prototyping. Implementation uncertain. labels Apr 30, 2020
@cspotcode
Copy link
Collaborator

@zen0wu in general, any ideas that make ts-node faster are great, and I'm a fan. However, for this request, we'll need a clearer picture of the implementation. Here are a few bullet points to spur discussion:

  • How do we detect a tsc-watch? Is this possible and practical?
  • It is possible that changes to bar.ts affect the emit of foo.ts, even if foo.ts did not change. How do we deal with that?
  • Are there guarantees around the mtime of tsbuildinfo? Can it be used to figure out if files have been compiled?
  • When using transpile-only things get way simpler. We have a ticket to re-add caching, see Restore cache functionality (default to off) #951. Is it more practical and simpler for someone to implement that feature?

Someone will need to figure out a more detailed proposal, with answers to the questions above, before we can consider adding a feature like this.

@cspotcode
Copy link
Collaborator

cspotcode commented Jul 22, 2022

Closing because I doubt we'll receive a PR for this, and the complexity is too high.

Users can always precompile and run the compiled output directly if they want, using ts-node or vanilla node, either should work, since ts-node is happy to run precompiled stuff.

Possibly related: #1845
Another related idea: outDir -> rootDir mapping #1514

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement research Needs design work, investigation, or prototyping. Implementation uncertain.
Projects
None yet
Development

No branches or pull requests

2 participants