Home

Awesome

Persistent TypeScript compiler

This is a TypeScript compiler that can be used as a Bazel "persistent worker." If it is launched with --persistent_worker, then it will run in a loop, reading compilation arguments (in protobuf format) from stdin; doing a compile; and then writing the results (also in protobuf format) to stdout. (The format is defined by Bazel.)

For Bazel projects that do a lot of TypeScript compilation, this has two performance benefits:

  1. It avoids compiler startup time.
  2. It avoids unnecessarily re-parsing source files. Specifically, the runtime file, lib.d.ts, will only be read once; any any other .ts or .d.ts files will also only be read once.

In our internal usage at Asana, using bazeltsc has led to roughly a 2x to 4x speedup in TypeScript compilation (the numbers are affected by a variety of factors).

Installation

You will need to get bazeltsc into a place where Bazel can find it. One way to do this is by using Bazel's rules_nodejs; but you can do it any way you like.

Instructions if you are using rules_nodejs:

Experimenting with bazeltsc

Normally, you just let Bazel launch bazeltsc. But it is helpful to understand how bazeltsc is launched by Bazel, and how you can experiment with it yourself.

bazeltsc can run in any of three modes: