Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 65cc4da

Browse files
committed
When building outside the Bazel sandbox (in particular, on Windows where the sandbox is not available), vanilla tsc doesn't support multiple compilation units. See details in that TypeScript bug. The workaround is to build tsc_wrapped as a single compilation unit. PiperOrigin-RevId: 187475876
1 parent c138b1c commit 65cc4da

File tree

12 files changed

+65
-379
lines changed

12 files changed

+65
-379
lines changed

internal/BUILD.bazel

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,63 @@
1717
package(default_visibility = ["//visibility:public"])
1818

1919
exports_files(["worker_protocol.proto"])
20+
21+
load("//internal:build_defs.bzl", ts_library = "tsc_library")
22+
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "jasmine_node_test")
23+
24+
# Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript
25+
nodejs_binary(
26+
name = "tsc",
27+
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
28+
entry_point = "typescript/lib/tsc.js",
29+
visibility = ["//internal:__subpackages__"],
30+
)
31+
32+
# Build our custom compiler using the vanilla one
33+
ts_library(
34+
name = "tsc_wrapped",
35+
srcs = glob([
36+
"tsc_wrapped/*.ts",
37+
"tsetse/*.ts",
38+
"tsetse/rules/*.ts"
39+
], exclude=["**/test_support.ts", "**/*_test.ts"]),
40+
module_name = "@bazel/typescript",
41+
module_root = "index.d.ts",
42+
tsconfig = "//internal:tsc_wrapped/tsconfig.json",
43+
visibility = ["//visibility:public"],
44+
data = [
45+
# Should be @bazel_tools//src/main/protobuf:worker_protocol.proto
46+
# see https://github.com/bazelbuild/bazel/issues/3155#issuecomment-308156976
47+
":worker_protocol.proto",
48+
],
49+
# Cannot have any deps because it doesn't work with vanilla tsc
50+
# Workaround for https://github.com/Microsoft/TypeScript/issues/22208
51+
deps = [
52+
],
53+
)
54+
55+
# Other ts_library rules will use this custom compiler, which calls the
56+
# TypeScript APIs to act like tsc, but adds capabilities like Bazel workers.
57+
nodejs_binary(
58+
name = "tsc_wrapped_bin",
59+
data = [
60+
":tsc_wrapped",
61+
],
62+
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
63+
entry_point = "build_bazel_rules_typescript/internal/tsc_wrapped/tsc_wrapped.js",
64+
templated_args = ["--node_options=--expose-gc"],
65+
visibility = ["//visibility:public"],
66+
)
67+
68+
ts_library(
69+
name = "test_lib",
70+
srcs = glob(["tsc_wrapped/*_test.ts"]) + ["tsc_wrapped/test_support.ts"],
71+
deps = [":tsc_wrapped"],
72+
tsconfig = "//internal:tsc_wrapped/tsconfig.json",
73+
)
74+
75+
jasmine_node_test(
76+
name = "test",
77+
srcs = [],
78+
deps = [":test_lib"],
79+
)

internal/build_defs.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,6 @@ ts_library = rule(
195195
def tsc_library(**kwargs):
196196
ts_library(
197197
supports_workers = False,
198-
compiler = "//internal/tsc_wrapped:tsc",
198+
compiler = "//internal:tsc",
199199
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
200200
**kwargs)

internal/e2e/strict_deps/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ licenses(["notice"]) # Apache 2.0
1616

1717
package(default_visibility = ["//visibility:public"])
1818

19+
1920
load("//:defs.bzl", "ts_library")
2021

2122
ts_library(

internal/executables.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
"""
1717

1818
def get_tsc():
19-
return Label("//internal/tsc_wrapped:tsc_wrapped_bin")
19+
return Label("//internal:tsc_wrapped_bin")

internal/ts_repositories.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")
2020
def ts_setup_workspace():
2121
yarn_install(
2222
name = "build_bazel_rules_typescript_tsc_wrapped_deps",
23-
package_json = "@build_bazel_rules_typescript//internal/tsc_wrapped:package.json",
24-
yarn_lock = "@build_bazel_rules_typescript//internal/tsc_wrapped:yarn.lock",
23+
package_json = "@build_bazel_rules_typescript//internal:tsc_wrapped/package.json",
24+
yarn_lock = "@build_bazel_rules_typescript//internal:tsc_wrapped/yarn.lock",
2525
)
2626
yarn_install(
2727
name = "build_bazel_rules_typescript_devserver_deps",

internal/tsc_wrapped/BUILD.bazel

Lines changed: 0 additions & 93 deletions
This file was deleted.

internal/tsetse/BUILD.bazel

Lines changed: 0 additions & 43 deletions
This file was deleted.

internal/tsetse/rules/BUILD

Lines changed: 0 additions & 36 deletions
This file was deleted.

internal/tsetse/tests/ban_expect_truthy_promise/BUILD

Lines changed: 0 additions & 60 deletions
This file was deleted.

internal/tsetse/tests/check_return_value/BUILD

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)