{"id":13450618,"url":"https://github.com/Asana/bazeltsc","last_synced_at":"2025-03-23T16:31:44.556Z","repository":{"id":66154791,"uuid":"88675779","full_name":"Asana/bazeltsc","owner":"Asana","description":"TypeScript compiler that knows how to run as a Bazel \"persistent worker\"","archived":true,"fork":false,"pushed_at":"2023-04-07T08:12:52.000Z","size":102,"stargazers_count":38,"open_issues_count":3,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-25T03:47:42.684Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Asana.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-04-18T22:25:12.000Z","updated_at":"2024-10-22T11:14:14.000Z","dependencies_parsed_at":"2023-07-02T21:31:15.711Z","dependency_job_id":null,"html_url":"https://github.com/Asana/bazeltsc","commit_stats":null,"previous_names":["asana/bazel-tsc"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asana%2Fbazeltsc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asana%2Fbazeltsc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asana%2Fbazeltsc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asana%2Fbazeltsc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Asana","download_url":"https://codeload.github.com/Asana/bazeltsc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245130837,"owners_count":20565729,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:00:36.722Z","updated_at":"2025-03-23T16:31:44.278Z","avatar_url":"https://github.com/Asana.png","language":"TypeScript","readme":"# Persistent TypeScript compiler\n\nThis is a TypeScript compiler that can be used as a Bazel \"persistent worker.\"\nIf it is launched with `--persistent_worker`, then it will run in a loop,\nreading compilation arguments (in protobuf format) from stdin; doing a compile;\nand then writing the results (also in protobuf format) to stdout.  (The format\nis defined by Bazel.)\n\nFor Bazel projects that do a lot of TypeScript compilation, this has two\nperformance benefits:\n\n1. It avoids compiler startup time.\n2. It avoids unnecessarily re-parsing source files. Specifically, the runtime\n   file, lib.d.ts, will only be read once; any any other .ts or .d.ts files\n   will also only be read once.\n\nIn our internal usage at Asana, using bazeltsc has led to roughly a 2x to 4x\nspeedup in TypeScript compilation (the numbers are affected by a variety of\nfactors).\n\n## Installation\n\nYou will need to get bazeltsc into a place where Bazel can find it. One way to\ndo this is by using Bazel's\n[`rules_nodejs`](https://github.com/bazelbuild/rules_nodejs); but you can do it\nany way you like.\n\nInstructions if you are using `rules_nodejs`:\n\n*   Follow the [`rules_nodejs`](https://github.com/bazelbuild/rules_nodejs)\n    setup instructions.\n\n*   Add `bazeltsc` to your `package.json`:\n\n        npm install --save-dev bazeltsc\n\n*   Run the Bazel equivalent of `npm install`:\n\n        bazel run @nodejs//:npm install\n\n*   Copy `tsc.bzl` from `node_modules/bazeltsc/tsc.bzl` into your repo\n    somewhere.  (We intend to clean this up as soon as we figure out how to get\n    Bazel to be able to find `tsc.bzl` directly from inside `node_modules`.)\n\n*   Use the example from the `example` directory -- especially the `WORKSPACE`\n    and `BUILD` file -- to finish setting things up.\n\n*   It is essential that when you run Bazel, you invoke it with\n    `--strategy=TsCompile=worker`. This is what tells Bazel to use `bazeltsc`\n    as a persistent worker instead of as a regular tool that is invoked once\n    per compilation.\n\n    You will probably want to add that to a `.bazelrc` file in the root directory\n    of your project, so that you don't have to specify it on the command line:\n\n        # This will be used every time someone does `bazel build ...`:\n        build --strategy=TsCompile=worker\n\n## Experimenting with bazeltsc\n\nNormally, you just let Bazel launch bazeltsc. But it is helpful to understand\nhow bazeltsc is launched by Bazel, and how you can experiment with it yourself.\n\nbazeltsc can run in any of three modes:\n\n*   **As a bazel persistent worker.**  Bazel will launch it with this command line: \n\n        bazeltsc --persistent_worker\n\n    At that point, bazeltsc is reading protobuf-formatted compilation requests\n    from stdin; compiling; and returning protobuf-formatted results on stdout.\n\n*   **As a thin wrapper around tsc.**  Examples:\n\n        bazeltsc --outDir target foo.ts bar.ts\n        bazeltsc @argfile\n\n    This provides no functionality beyond what tsc itself provides; it is\n    supported in case, for whatever reason, there are times when you want to\n    tell Bazel not to use persistent workers.\n\n*   **In \"debug\" mode.** If you want to experiment interactively with bazeltsc,\n    run it like this:\n\n        bazeltsc --debug\n\n    Then, at the `\u003e` prompt, enter a full tsc command line. This will let you\n    see the speed difference between an initial compilation and a subsequent\n    one.\n\n    For example:\n\n        bazeltsc --debug\n        \u003e x.ts\n        Compilation took 890ms. Exit code: 0.\n        \u003e x.ts\n        Compilation took 351ms. Exit code: 0.\n","funding_links":[],"categories":["TypeScript","Tooling"],"sub_categories":["General"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAsana%2Fbazeltsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAsana%2Fbazeltsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAsana%2Fbazeltsc/lists"}