jrieken / gulp-tsb

gulp plugin for incremental TypeScript building
MIT License
50 stars 19 forks source link

Duplicate of gulp-typescript #5

Closed ivogabe closed 9 years ago

ivogabe commented 9 years ago

This plugin looks to be a duplicate of gulp-typescript. Because of that it has been blacklisted (gulpjs/plugins#187). Can you instead of creating your own version consolidate your work into gulp-typescript?

A difference I could find between gulp-typescript & gulp-tsb is that gulp-tsb will recompile only changed files. That can be dangerous as you can see in Microsoft/TypeScript#3113. That's why it is not supported in gulp-typescript. If there are more features not supported by gulp-typescript, let me know, so that we can take a look at how these can be implemented in gulp-typescript.

jrieken commented 9 years ago

Feel free to take inspiration from the work here. The difference is -as you have pointed out- in how incremental changes are handled. From my understanding, gulp-typescript always starts a fresh compile (createProgram) when something has changed - even a comment. In contrast, we implement the following strategy:

(1) when a file changes only reemit that file* (generate js and d.ts files) (2) perform syntax and semantic checks for changed files only (3) check if the 'shape' of a changed file changed - changing a local variable vs changing an exported variable (3.1) If no shape changes -> done (3.2) Else If external modules are used traverse the dependency graph in reverse order and only perform a semantic check on them (3.3) Else If internal modules are used perform a semantic check on all files

With this approach we achieve an average code emit/validate time of ~1second for a code base with more than 1000 files - it obviously depends on what the change. I am pessimistic if gulp-typescript achieves this performance because it is not incremental. The main differences are:

In summary, I think this justifies having two implementations. gulp-typescript is for sure correct wrt enums but gulp-tsb is fast.

*With respect to enums and inlining their const values you are correct. There is simple trick to prevent that from happening (https://github.com/jrieken/gulp-tsb/commit/a97becbf3fa90608f88c336de36cb53ecd2dd14b) and according to the TS team this shouldn't be an issue anymore with 1.5. I have to confirm the latter tho. And even if and if inlined enums are desired there are ways of knowing where enums are defined and used.

ivogabe commented 9 years ago

gulp-typescript does support incremental compilation, by calling createProject outside of the task, just like your plugin. That gives a big increase in performance. The compiler api does support incremental compilation. Your step 3 is handled by TypeScript in gulp-typescript, it feels a bit unsafe for me to implement my own logic for that.

I'm looking to implement single file compilation in gulp-typescript, that's new in TS1.5. That will disallow all unsafe features. I think that will result in a very big performance boost and it remains safe.

jrieken commented 9 years ago

Yes - I am eager to see what is going to be possible with 1.5. Go ahead and take the lead on that and if it fits our perf requirements I am happy to give up this project.

ivogabe commented 9 years ago

@jrieken Can you take a look at ivogabe/gulp-typescript#130? Note that you will have to use gulp-plumber and TypeScript 1.5-alpha or newer. Currently you'll see lots of errors, but that will be fixed in TypeScript 1.5.

djabraham commented 8 years ago

I was doing a code merge to demonstrate a classic pattern to some guys who never used a packager before, when I noticed that I was only getting only the changed file in the output. No big deal, just though you might want to know it was a little confusing in that particular non-optimal scenario.

Don't know if you intend to continue with this or not, but I learned a hell of a lot about how the typescript compiler works, just by studying this effort. I was trying to do use ts-services on something else a while back, when I first encountered this, and there was not a lot of info on it then.

Thanks for this great project!

egamma commented 8 years ago

Don't know if you intend to continue with this or not, but I learned a hell of a lot about how the typescript compiler works, just by studying this effort.

Actually, we are using gulp-tsc to build microsoft/vscode, so we have a lot of interest in this module to make it good and fast.

jrieken commented 6 years ago

@ivogabe Does gulp-typescript already make use of the compiler API, introduced with 2.7, which allows for fast and incremental compiles? We have the code changes for that in master and have dropped our custom reconcile logic. Given that gulp-tsb lost its beef by that I am willing to retire it - assuming gulp-typescript is now incremental and fast?

ivogabe commented 6 years ago

gulp-typescript still uses the old incremental api, I didn’t have time to update to the new api yet. I think that I can implement it in april, I have a free week then.

vvs commented 6 years ago

Hi @jrieken and @ivogabe, do you have any news w.r.t. gulp-typescript using the new compiler API to speed up the incremental compilation (in watch mode).

The reason I am asking is because in our project we are struggling with long incremental compilations, which are getting worse as project grows.

We do use gulp-typescript's incremental compilation approach (project outside of the task), but he speedup, while there, is not huge, about 25-30% faster as compared to the full re-compilation, which is still quite long. Basically, full recompilation after a single file change is quite painful.

So, the question is what to do: try to switch to gulp-tsb or maybe there is some magic bullet in the works for gulp-typescript (maybe new Compiler API would improve things significantly)?

Thanks!