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

Support for typescript incremental compilation #347

Closed
wawyed opened this issue Jul 16, 2019 · 13 comments
Closed

Support for typescript incremental compilation #347

wawyed opened this issue Jul 16, 2019 · 13 comments
Labels
Milestone

Comments

@wawyed
Copy link
Contributor

wawyed commented Jul 16, 2019

In typescript 3.4+ they've added support for incremental compilation which would allow subsequential compilation runs to be much faster. Is this something that could be supported by karma-typescript?

https://devblogs.microsoft.com/typescript/announcing-typescript-3-4-rc/

@erikbarke erikbarke added this to the 5.0.0 milestone Jul 19, 2019
@erikbarke
Copy link
Collaborator

erikbarke commented Jul 19, 2019

This sounds nice! It seems an API for incremental builds was added recently, I'll see if I can squeeze this into the 5.0.0 release ☺️

@erikbarke
Copy link
Collaborator

@erikbarke
Copy link
Collaborator

Update, still waiting for the API to be completed, typings are missing in typescript@3.5.3: microsoft/TypeScript#29978

@wawyed
Copy link
Contributor Author

wawyed commented Sep 12, 2019

Hi, I was wondering if this is still blocked?

@erikbarke
Copy link
Collaborator

It looks like the API is complete now, I just installed typescript@3.6.3!

@erikbarke
Copy link
Collaborator

PR #353, for those of you interested in this feature, should this be a feature that can be toggled on/off or should the compiler just silently use the incremental API if available?

@anon-corporate
Copy link

anon-corporate commented Sep 14, 2019

If the tsconfig has the "incremental" property set, it should just use that.

Otherwise, I think enabling by default is fine.

PS: Thanks for getting this out! Excited to use it in our projects.

@erikbarke
Copy link
Collaborator

erikbarke commented Sep 14, 2019

I've poked around the source code for tsc, and it performs an incremental compilation if the tsconfig option incremental is set, otherwise it performs the old style compilation, so I guess karma-typescript should honor the incremental flag too 🤔We should probably also support the tsBuildInfoFile option.

@wawyed
Copy link
Contributor Author

wawyed commented Sep 16, 2019

I've poked around the source code for tsc, and it performs an incremental compilation if the tsconfig option incremental is set, otherwise it performs the old style compilation, so I guess karma-typescript should honor the incremental flag too 🤔We should probably also support the tsBuildInfoFile option.

That seems reasonable enough

@erikbarke
Copy link
Collaborator

A bit of a dilemma: karma-typescript does all its work in-memory, ie all .ts files are compiled and served directly to Karma, no compiled versions of the .ts files are ever written to the file system, which is kind of the main selling point of this plugin, it won't touch the project structure.

On the other hand, the new incremental feature of the Typescript compiler is meant to speed up cold builds by reading information about the project graph from the last build, stored on disk.

This makes it hard to add this new feature to the karma-typescript compiler, because if the source files haven't changed (according to the .tsbuildinfo file), the typescript compiler outputs nothing which makes the rest of the tool chain barf and crash. To fix this, the compiler could try to fall back to performing a regular compilation, but that would really defeat the purpose of the incremental feature...

Ideas?

@anon-corporate
Copy link

Is the issue that you don't want to write back out to the tsBuildInfoFile by design or is it a limitation of the API? I can see why folks don't expect the ts output to be dumped by this plugin, but it seems reasonable that this would still modify the build-cache metadata (which is what the tsBuildInfoFile is).

@erikbarke
Copy link
Collaborator

If karma-typescript would write to the .tsbuildinfo file, the graph and the file versions recorded there would correspond to what the project graph looks like when running karma, not what any .ts file compiled to .js om disk looks like, my guess is this could wreak havoc on the subsequent runs 🤔Also, even if a .tsbuildinfo file exists when running karma that won't help making the cold build faster because the typescript compiler produces no output if nothing has changed.

To summarize the problem: the typescript compiler relies on what the compiled version of the project looks like on disk and karma-typescript does all its work in-memory, I don't think this is going to work 😞

One way to solve this might be if karma-typescript would keep a temp cache (out of the project folder) with the transpiled .js files along with a "private" .tsbuildinfo but I have no idea as to what can of worms that would open (files changed in the project folder but not in the cache, weird temp file names in error messages, etc, bleh).

Also note that when running karma in watch mode, karma-typescript already mimics the tsc --watch mode by caching and reusing the last build program, reducing compilation time on subsequent runs, the incremental compilation feature wouldn't add any performance gains when already running karma in watch mode.

@erikbarke
Copy link
Collaborator

Closing this since this isn't doable 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants