blob: d2d76af1619a8972b03db06104b6ee19ae8610c6 [file] [log] [blame]
alexeaglec5d98ba2017-04-28 20:42:26 +02001# Copyright 2017 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Alex Eagleab375ad2017-11-13 17:23:47 +010015# gazelle:exclude worker_protocol.proto
16
alexeaglec028da62017-04-27 17:18:39 +020017package(default_visibility = ["//visibility:public"])
18
alexeagle793b15e2017-08-23 00:58:40 +020019exports_files(["worker_protocol.proto"])
alexeagle249a43a2018-03-01 16:31:18 +010020
Greg Magolan9269f6c2018-03-05 20:06:22 +010021load("//internal:build_defs.bzl", "ts_library")
alexeagle249a43a2018-03-01 16:31:18 +010022load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "jasmine_node_test")
23
24# Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript
25nodejs_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
33ts_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"]),
Greg Magolan9269f6c2018-03-05 20:06:22 +010040 supports_workers = False,
41 compiler = ":tsc",
42 node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
alexeagle249a43a2018-03-01 16:31:18 +010043 module_name = "@bazel/typescript",
alexeagle164adc42018-03-02 01:35:20 +010044 module_root = "tsc_wrapped/index.d.ts",
alexeagle249a43a2018-03-01 16:31:18 +010045 tsconfig = "//internal:tsc_wrapped/tsconfig.json",
46 visibility = ["//visibility:public"],
47 data = [
48 # Should be @bazel_tools//src/main/protobuf:worker_protocol.proto
49 # see https://github.com/bazelbuild/bazel/issues/3155#issuecomment-308156976
50 ":worker_protocol.proto",
51 ],
52 # Cannot have any deps because it doesn't work with vanilla tsc
53 # Workaround for https://github.com/Microsoft/TypeScript/issues/22208
54 deps = [
55 ],
56)
57
58# Other ts_library rules will use this custom compiler, which calls the
59# TypeScript APIs to act like tsc, but adds capabilities like Bazel workers.
60nodejs_binary(
61 name = "tsc_wrapped_bin",
62 data = [
63 ":tsc_wrapped",
64 ],
65 node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
66 entry_point = "build_bazel_rules_typescript/internal/tsc_wrapped/tsc_wrapped.js",
67 templated_args = ["--node_options=--expose-gc"],
68 visibility = ["//visibility:public"],
69)
70
71ts_library(
72 name = "test_lib",
73 srcs = glob(["tsc_wrapped/*_test.ts"]) + ["tsc_wrapped/test_support.ts"],
74 deps = [":tsc_wrapped"],
75 tsconfig = "//internal:tsc_wrapped/tsconfig.json",
76)
77
78jasmine_node_test(
79 name = "test",
80 srcs = [],
81 deps = [":test_lib"],
82)