From 3efc8ef6f85377c6c4b2a5fc9e35434a426cd56a Mon Sep 17 00:00:00 2001 From: alexeagle Date: Thu, 1 Mar 2018 07:31:18 -0800 Subject: [PATCH] Workaround for https://github.com/Microsoft/TypeScript/issues/22208 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 --- .../rules_typescript/internal/BUILD.bazel | 60 ++++++++++++ .../rules_typescript/internal/build_defs.bzl | 2 +- .../internal/e2e/strict_deps/BUILD | 1 + .../rules_typescript/internal/executables.bzl | 2 +- .../internal/ts_repositories.bzl | 4 +- .../internal/tsc_wrapped/BUILD.bazel | 93 ------------------- .../internal/tsetse/BUILD.bazel | 43 --------- .../internal/tsetse/rules/BUILD | 36 ------- .../tests/ban_expect_truthy_promise/BUILD | 60 ------------ .../tsetse/tests/check_return_value/BUILD | 63 ------------- .../internal/tsetse/tests/equals_nan/BUILD | 43 --------- .../tsetse/tests/must_use_promises/BUILD | 37 -------- 12 files changed, 65 insertions(+), 379 deletions(-) delete mode 100644 third_party/github.com/bazelbuild/rules_typescript/internal/tsc_wrapped/BUILD.bazel delete mode 100644 third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/BUILD.bazel delete mode 100644 third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/rules/BUILD delete mode 100644 third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/ban_expect_truthy_promise/BUILD delete mode 100644 third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/check_return_value/BUILD delete mode 100644 third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/equals_nan/BUILD delete mode 100644 third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/must_use_promises/BUILD diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/BUILD.bazel b/third_party/github.com/bazelbuild/rules_typescript/internal/BUILD.bazel index 0ea8d845a0..ea9af5d2ab 100644 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/BUILD.bazel +++ b/third_party/github.com/bazelbuild/rules_typescript/internal/BUILD.bazel @@ -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"], +) diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/build_defs.bzl b/third_party/github.com/bazelbuild/rules_typescript/internal/build_defs.bzl index a111292f55..084ace4cab 100644 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/build_defs.bzl +++ b/third_party/github.com/bazelbuild/rules_typescript/internal/build_defs.bzl @@ -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) diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/e2e/strict_deps/BUILD b/third_party/github.com/bazelbuild/rules_typescript/internal/e2e/strict_deps/BUILD index 604704e81c..b25079bdd6 100644 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/e2e/strict_deps/BUILD +++ b/third_party/github.com/bazelbuild/rules_typescript/internal/e2e/strict_deps/BUILD @@ -16,6 +16,7 @@ licenses(["notice"]) # Apache 2.0 package(default_visibility = ["//visibility:public"]) + load("//:defs.bzl", "ts_library") ts_library( diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/executables.bzl b/third_party/github.com/bazelbuild/rules_typescript/internal/executables.bzl index d7dacb4d85..e83baa2709 100644 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/executables.bzl +++ b/third_party/github.com/bazelbuild/rules_typescript/internal/executables.bzl @@ -16,4 +16,4 @@ """ def get_tsc(): - return Label("//internal/tsc_wrapped:tsc_wrapped_bin") + return Label("//internal:tsc_wrapped_bin") diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/ts_repositories.bzl b/third_party/github.com/bazelbuild/rules_typescript/internal/ts_repositories.bzl index c5f49d5532..79d6c8eaba 100644 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/ts_repositories.bzl +++ b/third_party/github.com/bazelbuild/rules_typescript/internal/ts_repositories.bzl @@ -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", diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/tsc_wrapped/BUILD.bazel b/third_party/github.com/bazelbuild/rules_typescript/internal/tsc_wrapped/BUILD.bazel deleted file mode 100644 index 4b7c80e80d..0000000000 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/tsc_wrapped/BUILD.bazel +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 = [ - "compiler_host.ts", - "diagnostics.ts", - "file_cache.ts", - "index.ts", - "manifest.ts", - "strict_deps.ts", - "tsc_wrapped.ts", - "tsconfig.ts", - "umd_module_declaration_transform.ts", - "worker.ts", - ], - module_name = "@bazel/typescript", - module_root = "index.d.ts", - tsconfig = ":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 - "//internal:worker_protocol.proto", - ], - deps = [ - ":perf_trace", - ":plugin_api", - "//internal/tsetse:runner", - ], -) - -ts_library( - name = "plugin_api", - srcs = ["plugin_api.ts"], - visibility = ["//internal/tsetse:__pkg__"], -) - -ts_library( - name = "perf_trace", - srcs = ["perf_trace.ts"], - visibility = ["//internal/tsetse:__pkg__"], -) - -# 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(["*_test.ts"]) + ["test_support.ts"], - deps = [":tsc_wrapped"], - tsconfig = ":tsconfig.json", -) - -jasmine_node_test( - name = "test", - srcs = [], - deps = [":test_lib"], -) diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/BUILD.bazel b/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/BUILD.bazel deleted file mode 100644 index b36643944f..0000000000 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/BUILD.bazel +++ /dev/null @@ -1,43 +0,0 @@ -package(default_visibility = [ - "//internal/tsc_wrapped:__pkg__", - "//internal/tsetse:__subpackages__", -]) - -licenses(["notice"]) # Apache 2.0 - -load("//internal:build_defs.bzl", ts_library = "tsc_library") - -ts_library( - name = "tsetse_lib", - srcs = [ - "checker.ts", - "error_code.ts", - "failure.ts", - "rule.ts", - ], - tsconfig = ":tsconfig.json", -) - -ts_library( - name = "runner", - srcs = [ - "runner.ts", - ], - deps = [ - ":tsetse_lib", - "//internal/tsc_wrapped:perf_trace", - "//internal/tsc_wrapped:plugin_api", - "//internal/tsetse/rules", - ], -) - -ts_library( - name = "language_service_plugin", - srcs = [ - "language_service_plugin.ts", - ], - deps = [ - ":runner", - ":tsetse_lib", - ], -) diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/rules/BUILD b/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/rules/BUILD deleted file mode 100644 index 7df248068e..0000000000 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/rules/BUILD +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -licenses(["notice"]) # Apache 2.0 - -load("//internal:build_defs.bzl", ts_library = "tsc_library") - -ts_library( - name = "rules", - srcs = [ - "ban_expect_truthy_promise_rule.ts", - "check_return_value_rule.ts", - "equals_nan_rule.ts", - "must_use_promises_rule.ts", - ], - tsconfig = "//internal/tsetse:tsconfig.json", - visibility = ["//internal/tsetse:__pkg__"], - deps = [ - "//internal/tsetse:tsetse_lib", - - - - - ], -) diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/ban_expect_truthy_promise/BUILD b/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/ban_expect_truthy_promise/BUILD deleted file mode 100644 index c555622021..0000000000 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/ban_expect_truthy_promise/BUILD +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -licenses(["notice"]) # Apache 2.0 - -load("//:defs.bzl", "ts_library") - -error_message = "error TS21224: Value passed.*" - -ts_library( - name = "jasmine", - testonly = 1, - srcs = [ - "jasmine_types.ts", - ], -) - -ts_library( - name = "positives", - testonly = 1, - tsconfig = "//internal/tsetse:tsconfig.json", - srcs = [ - "positives.ts", - ], - expected_diagnostics = [ - "\(29,5\).*" + error_message, - "\(30,5\).*" + error_message, - "\(31,5\).*" + error_message, - "\(32,5\).*" + error_message, - "\(33,5\).*" + error_message, - "\(34,5\).*" + error_message, - "\(35,5\).*" + error_message, - ], - deps = [ - ":jasmine", - ], -) - -ts_library( - name = "negatives", - testonly = 1, - tsconfig = "//internal/tsetse:tsconfig.json", - srcs = [ - "negatives.ts", - ], - deps = [ - ":jasmine", - ], -) diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/check_return_value/BUILD b/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/check_return_value/BUILD deleted file mode 100644 index 60bc8f89be..0000000000 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/check_return_value/BUILD +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -licenses(["notice"]) # Apache 2.0 - -load("//:defs.bzl", "ts_library") - - -error_message = "TS21222: return value is unused.\\n\\tSee http://tsetse.info/check-return-value" - -ts_library( - name = "no_expected_diagnostics_test", - testonly = 1, - srcs = ["no_expected_diagnostics.ts"], - tsconfig = "//internal/tsetse:tsconfig.json", -) - -ts_library( - name = "expected_diagnostics_test", - testonly = 1, - srcs = ["expected_diagnostics.ts"], - expected_diagnostics = [ - "\(6,1\).*" + error_message, - "\(8,1\).*" + error_message, - "\(12,1\).*" + error_message, - "\(16,1\).*" + error_message, - "\(19,1\).*" + error_message, - ], - tsconfig = "//internal/tsetse:tsconfig.json", -) - -ts_library( - name = "user_defined_check_return_value", - testonly = 1, - srcs = ["user_defined_check_return_value.ts"], - tsconfig = "//internal/tsetse:tsconfig.json", -) - -ts_library( - name = "unused_return_value_user_defined_function", - testonly = 1, - srcs = ["unused_return_value_user_defined_function.ts"], - expected_diagnostics = [ - "\(3,1\).*" + error_message, - "\(4,1\).*" + error_message, - "\(6,1\).*" + error_message, - "\(8,1\).*" + error_message, - "\(14,1\).*" + error_message, - ], - tsconfig = "//internal/tsetse:tsconfig.json", - deps = [":user_defined_check_return_value"], -) diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/equals_nan/BUILD b/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/equals_nan/BUILD deleted file mode 100644 index cf4ff53e20..0000000000 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/equals_nan/BUILD +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -licenses(["notice"]) # Apache 2.0 - -load("//:defs.bzl", "ts_library") - - -ts_library( - name = "positives", - testonly = 1, - srcs = [ - "positives.ts", - ], - expected_diagnostics = [ - "\(2,19\): error TS21223: x === NaN is always false; use isNaN\(x\) instead", - "\(6,5\): error TS21223: x === NaN is always false; use isNaN\(x\) instead", - "\(7,5\): error TS21223: x == NaN is always false; use isNaN\(x\) instead", - "\(8,5\): error TS21223: x !== NaN is always true; use !isNaN\(x\) instead", - "\(9,5\): error TS21223: x != NaN is always true; use !isNaN\(x\) instead", - "\(11,1\): error TS21223: x === NaN is always false; use isNaN\(x\) instead", - "\(12,1\): error TS21223: x === NaN is always false; use isNaN\(x\) instead", - ], -) - -ts_library( - name = "negatives", - testonly = 1, - srcs = [ - "negatives.ts", - ], -) diff --git a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/must_use_promises/BUILD b/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/must_use_promises/BUILD deleted file mode 100644 index fa744bc712..0000000000 --- a/third_party/github.com/bazelbuild/rules_typescript/internal/tsetse/tests/must_use_promises/BUILD +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -licenses(["notice"]) # Apache 2.0 - -load("//:defs.bzl", "ts_library") - - -error_message = "TS21225: All Promises in async functions must either be awaited or used in an expression." - -ts_library( - name = "positives", - testonly = 1, - srcs = [ - "positives.ts", - ], - tsconfig = "//internal/tsetse:tsconfig.json", - expected_diagnostics = [ - "\(29,3\)" + error_message, - "\(30,3\)" + error_message, - "\(31,3\)" + error_message, - "\(32,3\)" + error_message, - "\(34,3\)" + error_message, - ], - -)