Skip to content

Commit afc75ce

Browse files
devversionclydin
authored andcommitted
build: setup rules_ts for compiling TypeScript sources
This commit sets up `rules_ts`, providing the `ts_library` equivalent for the `rules_js` migration.
1 parent f22d4ee commit afc75ce

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Disable NG CLI TTY mode
22
build --action_env=NG_FORCE_TTY=false
33

4+
# Required by `rules_ts`.
5+
common --@aspect_rules_ts//ts:skipLibCheck=always
6+
common --@aspect_rules_ts//ts:default_to_tsc_transpiler
7+
48
# Make TypeScript compilation fast, by keeping a few copies of the compiler
59
# running as daemons, and cache SourceFile AST's to reduce parse time.
610
build --strategy=TypeScriptCompile=worker

BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", rules_js_tsconfig = "ts_config")
2+
13
# Copyright Google Inc. All Rights Reserved.
24
#
35
# Use of this source code is governed by an MIT-style license that can be
@@ -24,6 +26,15 @@ npm_link_all_packages(
2426
name = "node_modules",
2527
)
2628

29+
rules_js_tsconfig(
30+
name = "build-tsconfig",
31+
src = "tsconfig-build.json",
32+
deps = [
33+
"tsconfig.json",
34+
"//:node_modules/@types/node",
35+
],
36+
)
37+
2738
# Files required by e2e tests
2839
copy_to_bin(
2940
name = "config-files",

WORKSPACE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,20 @@ npm_translate_lock(
195195
load("@npm2//:repositories.bzl", "npm_repositories")
196196

197197
npm_repositories()
198+
199+
http_archive(
200+
name = "aspect_rules_ts",
201+
patch_args = ["-p1"],
202+
patches = ["//tools:rules_ts_windows.patch"],
203+
sha256 = "9acd128abe77397505148eaa6895faed57839560dbf2177dd6285e51235e2724",
204+
strip_prefix = "rules_ts-3.3.1",
205+
url = "https://github.com/aspect-build/rules_ts/releases/download/v3.3.1/rules_ts-v3.3.1.tar.gz",
206+
)
207+
208+
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
209+
210+
rules_ts_dependencies(
211+
# ts_version_from = "//:package.json",
212+
# TODO: Support in https://github.com/aspect-build/rules_ts/blob/main/ts/private/npm_repositories.bzl
213+
ts_version = "5.6.2",
214+
)

tools/rules_ts_windows.patch

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/ts/private/ts_project.bzl b/ts/private/ts_project.bzl
2+
index 367bba0..a112f8f 100644
3+
--- a/ts/private/ts_project.bzl
4+
+++ b/ts/private/ts_project.bzl
5+
@@ -93,25 +93,6 @@ def _ts_project_impl(ctx):
6+
elif ctx.attr.supports_workers == 0:
7+
supports_workers = False
8+
9+
- host_is_windows = platform_utils.host_platform_is_windows()
10+
- if host_is_windows and supports_workers:
11+
- supports_workers = False
12+
-
13+
- # buildifier: disable=print
14+
- print("""\
15+
-WARNING: disabling ts_project workers which are not currently supported on Windows hosts.
16+
-See https://github.com/aspect-build/rules_ts/issues/228 for more details.
17+
-""")
18+
-
19+
- if ctx.attr.is_typescript_5_or_greater and supports_workers:
20+
- supports_workers = False
21+
-
22+
- # buildifier: disable=print
23+
- print("""\
24+
-WARNING: disabling ts_project workers which are not currently supported with TS >= 5.0.0.
25+
-See https://github.com/aspect-build/rules_ts/issues/361 for more details.
26+
-""")
27+
-
28+
if supports_workers:
29+
execution_requirements["supports-workers"] = "1"
30+
execution_requirements["worker-key-mnemonic"] = "TsProject"

0 commit comments

Comments
 (0)