Skip to content

Commit bf3e8f7

Browse files
committed
build: use worker for ts_project to enable fast DX and avoid no-sandbox issues
For the `rules_js` migration we are introducing a new ruleset for Angular rules. These rules are not used here by the CLI as we don't use `ng_module`, but we are building the rules in a way where we expose a worker binary that can also work with vanilla TS. The worker significantly speeds up compilations, bringing them to equivalent speeds of `ts_library`, and **importantly** fixes/avoids issues when actions are executing outside sandbox. E.g. on Windows where the tsc compilation currently can see many other files that aren't action inputs; and accidentally picks them up.
1 parent 894de96 commit bf3e8f7

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

WORKSPACE

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ register_toolchains(
88
"//tools:windows_tar_system_toolchain",
99
)
1010

11-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
11+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
1212

1313
http_archive(
1414
name = "bazel_skylib",
@@ -37,9 +37,9 @@ build_bazel_rules_nodejs_dependencies()
3737

3838
http_archive(
3939
name = "aspect_rules_js",
40-
sha256 = "75c25a0f15a9e4592bbda45b57aa089e4bf17f9176fd735351e8c6444df87b52",
41-
strip_prefix = "rules_js-2.1.0",
42-
url = "https://github.com/aspect-build/rules_js/releases/download/v2.1.0/rules_js-v2.1.0.tar.gz",
40+
sha256 = "3388abe9b9728ef68ea8d8301f932b11b2c9a271d74741ddd5f3b34d1db843ac",
41+
strip_prefix = "rules_js-2.1.1",
42+
url = "https://github.com/aspect-build/rules_js/releases/download/v2.1.1/rules_js-v2.1.1.tar.gz",
4343
)
4444

4545
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
@@ -218,3 +218,9 @@ rules_ts_dependencies(
218218
# TODO: Support in https://github.com/aspect-build/rules_ts/blob/main/ts/private/npm_repositories.bzl
219219
ts_version = "5.6.2",
220220
)
221+
222+
http_file(
223+
name = "tsc_worker",
224+
sha256 = "4fb116945734840d6097998a25e5b88fdd22be2b5395570f2fa0baee2d47b4e0",
225+
urls = ["https://raw.githubusercontent.com/devversion/rules_angular/e9045b9fc89304a12d9e1f97a40dab9b5b793e77/dist/worker.mjs"],
226+
)

tools/BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
load("@aspect_bazel_lib//lib/private:tar_toolchain.bzl", "tar_toolchain")
2+
load("@aspect_rules_js//js:defs.bzl", "js_binary")
3+
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
24

35
# Copyright Google Inc. All Rights Reserved.
46
#
@@ -42,4 +44,22 @@ toolchain(
4244
toolchain = ":system_tar_exec",
4345
toolchain_type = "@aspect_bazel_lib//lib:tar_toolchain_type",
4446
)
47+
48+
# TODO(devversion): Improve this by potentially sharing this common block.
49+
copy_file(
50+
name = "copy_worker_js",
51+
src = "@tsc_worker//file",
52+
out = "ts_worker.mjs",
53+
)
54+
55+
js_binary(
56+
name = "vanilla_ts_worker",
57+
data = [
58+
":copy_worker_js",
59+
"//:root_modules/@angular/compiler-cli",
60+
"//:root_modules/typescript",
61+
],
62+
entry_point = ":copy_worker_js",
63+
fixed_args = ["--vanilla-ts"],
64+
)
4565
# @external_end

tools/interop.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ def ts_project(name, module_name = None, interop_deps = [], deps = [], testonly
9494
testonly = testonly,
9595
tsconfig = "//:test-tsconfig" if testonly else "//:build-tsconfig",
9696
declaration = True,
97+
# Use the worker from our own Angular rules, as the default worker
98+
# from `rules_ts` is incompatible with TS5+ and abandoned. We need
99+
# worker for efficient, fast DX and avoiding Windows no-sandbox issues.
100+
supports_workers = 1,
101+
tsc_worker = "//tools:vanilla_ts_worker",
97102
deps = ["%s_interop_deps" % name] + deps,
98103
**kwargs
99104
)

0 commit comments

Comments
 (0)