blob: 5eb31904f053d9a0910148b7081679ee0e6612be [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
Alex Eagle54a3c5b2019-05-23 19:02:22 -070017load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
alexeagle6c23d7e2019-03-06 09:30:48 -080018load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
Alex Eagle54a3c5b2019-05-23 19:02:22 -070019load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
alexeaglef86f2f22019-09-20 14:19:43 -070020load("@npm_bazel_typescript//:index.bzl", "ts_library")
Wassim Cheghambef0cb42018-12-19 14:42:25 -080021
alexeaglec028da62017-04-27 17:18:39 +020022package(default_visibility = ["//visibility:public"])
23
Alex Eagle2cd949c2019-03-11 15:17:25 -070024exports_files(["tsetse/tsconfig.json"])
alexeagle249a43a2018-03-01 16:31:18 +010025
alexeagle6c23d7e2019-03-06 09:30:48 -080026bzl_library(
27 name = "bzl",
28 srcs = glob(["common/*.bzl"]),
29 visibility = ["//visibility:public"],
30)
31
alexeagle249a43a2018-03-01 16:31:18 +010032# Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript
33nodejs_binary(
34 name = "tsc",
Greg Magolanb3f81402018-09-25 13:18:13 -070035 data = [
Greg Magolan0e70c112018-10-04 07:44:14 -070036 "@npm//source-map-support",
37 "@npm//typescript",
Greg Magolanb3f81402018-09-25 13:18:13 -070038 ],
Greg Magolan4d882242019-06-19 12:23:05 -070039 entry_point = "@npm//:node_modules/typescript/lib/tsc.js",
alexeagle249a43a2018-03-01 16:31:18 +010040 visibility = ["//internal:__subpackages__"],
41)
42
43# Build our custom compiler using the vanilla one
44ts_library(
45 name = "tsc_wrapped",
Alex Eagle71a24a92018-07-20 22:25:22 +020046 srcs = glob(
47 [
48 "tsc_wrapped/*.ts",
rjamet50b03372019-05-10 05:10:24 -070049 "tsetse/**/*.ts",
Alex Eagle71a24a92018-07-20 22:25:22 +020050 ],
51 exclude = [
52 "**/test_support.ts",
53 "**/*_test.ts",
54 ],
55 ),
Greg Magolan9269f6c2018-03-05 20:06:22 +010056 compiler = ":tsc",
alexeagle249a43a2018-03-01 16:31:18 +010057 data = [
alexeagle4aaa96b2018-07-19 19:21:45 +020058 "//third_party/github.com/bazelbuild/bazel/src/main/protobuf:worker_protocol.proto",
alexeagle249a43a2018-03-01 16:31:18 +010059 ],
Alex Eagle71a24a92018-07-20 22:25:22 +020060 module_name = "@bazel/typescript",
61 module_root = "tsc_wrapped/index.d.ts",
Alex Eagle71a24a92018-07-20 22:25:22 +020062 supports_workers = False,
63 tsconfig = "//internal:tsc_wrapped/tsconfig.json",
64 visibility = ["//visibility:public"],
Greg Magolanb3f81402018-09-25 13:18:13 -070065 # Cannot have any deps (except npm fine grained deps) because it doesn't
66 # work with vanilla tsc.
alexeagle249a43a2018-03-01 16:31:18 +010067 # Workaround for https://github.com/Microsoft/TypeScript/issues/22208
68 deps = [
Greg Magolan0e70c112018-10-04 07:44:14 -070069 "@npm//@types/node",
martinprobst6fb705c2019-03-28 08:14:59 -070070 "@npm//protobufjs",
Greg Magolan0e70c112018-10-04 07:44:14 -070071 "@npm//tsickle",
72 "@npm//tsutils",
73 "@npm//typescript",
alexeagle249a43a2018-03-01 16:31:18 +010074 ],
75)
76
77# Other ts_library rules will use this custom compiler, which calls the
78# TypeScript APIs to act like tsc, but adds capabilities like Bazel workers.
Greg Magolan0e70c112018-10-04 07:44:14 -070079# TODO(gregmagolan): make @npm//tsickle dependency optional
alexeagle249a43a2018-03-01 16:31:18 +010080nodejs_binary(
81 name = "tsc_wrapped_bin",
82 data = [
83 ":tsc_wrapped",
Greg Magolan0e70c112018-10-04 07:44:14 -070084 "@npm//protobufjs",
85 "@npm//source-map-support",
86 "@npm//tsickle",
87 "@npm//tsutils",
88 "@npm//typescript",
Alex Eagled92ffa52019-05-31 13:20:45 -070089 "//third_party/github.com/bazelbuild/bazel/src/main/protobuf:worker_protocol.proto",
alexeagle249a43a2018-03-01 16:31:18 +010090 ],
Greg Magolan716e45d2019-06-07 10:50:13 -070091 entry_point = ":tsc_wrapped/tsc_wrapped.ts",
alexeagle249a43a2018-03-01 16:31:18 +010092 visibility = ["//visibility:public"],
93)
94
95ts_library(
96 name = "test_lib",
rjamet50b03372019-05-10 05:10:24 -070097 srcs = glob([
98 "tsc_wrapped/*_test.ts",
99 "tsetse/**/*_test.ts",
100 ]) + [
101 "tsc_wrapped/test_support.ts",
102 "tsetse/util/testing/test_support.ts",
103 ],
Alex Eagle9cfa5672019-04-01 16:20:13 -0700104 compiler = "@build_bazel_rules_typescript//internal:tsc_wrapped_bin",
rjamet50b03372019-05-10 05:10:24 -0700105 tsconfig = "//internal:tsc_wrapped/tsconfig.json",
Greg Magolanb3f81402018-09-25 13:18:13 -0700106 deps = [
107 ":tsc_wrapped",
Greg Magolan0e70c112018-10-04 07:44:14 -0700108 "@npm//@types/jasmine",
109 "@npm//@types/node",
alexeagle8c1630b2018-12-10 13:14:33 -0800110 "@npm//tsickle",
Greg Magolan0e70c112018-10-04 07:44:14 -0700111 "@npm//typescript",
Greg Magolanb3f81402018-09-25 13:18:13 -0700112 ],
alexeagle249a43a2018-03-01 16:31:18 +0100113)
114
115jasmine_node_test(
116 name = "test",
117 srcs = [],
Greg Magolanb3f81402018-09-25 13:18:13 -0700118 deps = [
119 ":test_lib",
Greg Magolan0e70c112018-10-04 07:44:14 -0700120 "@npm//jasmine",
alexeagleba3f8192018-11-15 15:10:53 -0800121 "@npm//protobufjs",
122 "@npm//source-map",
Greg Magolan0e70c112018-10-04 07:44:14 -0700123 "@npm//typescript",
Greg Magolanb3f81402018-09-25 13:18:13 -0700124 ],
125)
126
alexeagleb0daa892019-02-04 11:45:53 -0800127# We don't need to distribute any of the content of the BUILD.bazel file in this package
128# So generate an empty marker file
129genrule(
130 name = "generated_BUILD",
131 srcs = [],
132 # Name the output "BUILD" so it doesn't collide with InputArtifact "BUILD.bazel"
133 outs = ["BUILD"],
134 cmd = "echo \"# Marker that this directory is a Bazel package\" > $@",
135)
136
Greg Magolana8f559a2019-02-01 16:10:36 -0800137filegroup(
138 name = "npm_package_assets",
Greg Magolanb3f81402018-09-25 13:18:13 -0700139 srcs = [
Minko Gechev18f5df62018-12-12 15:22:45 -0800140 "common/compilation.bzl",
141 "common/json_marshal.bzl",
142 "common/module_mappings.bzl",
143 "common/tsconfig.bzl",
Wassim Cheghambef0cb42018-12-19 14:42:25 -0800144 ],
Minko Gechev18f5df62018-12-12 15:22:45 -0800145)