Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexeagle committed Mar 1, 2018
1 parent a765196 commit 3efc8ef
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 379 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,63 @@
package(default_visibility = ["//visibility:public"])

exports_files(["worker_protocol.proto"])

load("//internal:build_defs.bzl", ts_library = "tsc_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "jasmine_node_test")

# Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript
nodejs_binary(
name = "tsc",
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
entry_point = "typescript/lib/tsc.js",
visibility = ["//internal:__subpackages__"],
)

# Build our custom compiler using the vanilla one
ts_library(
name = "tsc_wrapped",
srcs = glob([
"tsc_wrapped/*.ts",
"tsetse/*.ts",
"tsetse/rules/*.ts"
], exclude=["**/test_support.ts", "**/*_test.ts"]),
module_name = "@bazel/typescript",
module_root = "index.d.ts",
tsconfig = "//internal:tsc_wrapped/tsconfig.json",
visibility = ["//visibility:public"],
data = [
# Should be @bazel_tools//src/main/protobuf:worker_protocol.proto
# see https://github.com/bazelbuild/bazel/issues/3155#issuecomment-308156976
":worker_protocol.proto",
],
# Cannot have any deps because it doesn't work with vanilla tsc
# Workaround for https://github.com/Microsoft/TypeScript/issues/22208
deps = [
],
)

# Other ts_library rules will use this custom compiler, which calls the
# TypeScript APIs to act like tsc, but adds capabilities like Bazel workers.
nodejs_binary(
name = "tsc_wrapped_bin",
data = [
":tsc_wrapped",
],
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
entry_point = "build_bazel_rules_typescript/internal/tsc_wrapped/tsc_wrapped.js",
templated_args = ["--node_options=--expose-gc"],
visibility = ["//visibility:public"],
)

ts_library(
name = "test_lib",
srcs = glob(["tsc_wrapped/*_test.ts"]) + ["tsc_wrapped/test_support.ts"],
deps = [":tsc_wrapped"],
tsconfig = "//internal:tsc_wrapped/tsconfig.json",
)

jasmine_node_test(
name = "test",
srcs = [],
deps = [":test_lib"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ ts_library = rule(
def tsc_library(**kwargs):
ts_library(
supports_workers = False,
compiler = "//internal/tsc_wrapped:tsc",
compiler = "//internal:tsc",
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
**kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ licenses(["notice"]) # Apache 2.0

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


load("//:defs.bzl", "ts_library")

ts_library(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"""

def get_tsc():
return Label("//internal/tsc_wrapped:tsc_wrapped_bin")
return Label("//internal:tsc_wrapped_bin")
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")
def ts_setup_workspace():
yarn_install(
name = "build_bazel_rules_typescript_tsc_wrapped_deps",
package_json = "@build_bazel_rules_typescript//internal/tsc_wrapped:package.json",
yarn_lock = "@build_bazel_rules_typescript//internal/tsc_wrapped:yarn.lock",
package_json = "@build_bazel_rules_typescript//internal:tsc_wrapped/package.json",
yarn_lock = "@build_bazel_rules_typescript//internal:tsc_wrapped/yarn.lock",
)
yarn_install(
name = "build_bazel_rules_typescript_devserver_deps",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 3efc8ef

Please sign in to comment.