alexeagle | c5d98ba | 2017-04-28 20:42:26 +0200 | [diff] [blame] | 1 | # 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 Eagle | ab375ad | 2017-11-13 17:23:47 +0100 | [diff] [blame] | 15 | # gazelle:exclude worker_protocol.proto |
| 16 | |
Alex Eagle | 54a3c5b | 2019-05-23 19:02:22 -0700 | [diff] [blame] | 17 | load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") |
alexeagle | 6c23d7e | 2019-03-06 09:30:48 -0800 | [diff] [blame] | 18 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") |
Alex Eagle | 54a3c5b | 2019-05-23 19:02:22 -0700 | [diff] [blame] | 19 | load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test") |
alexeagle | f86f2f2 | 2019-09-20 14:19:43 -0700 | [diff] [blame] | 20 | load("@npm_bazel_typescript//:index.bzl", "ts_library") |
Wassim Chegham | bef0cb4 | 2018-12-19 14:42:25 -0800 | [diff] [blame] | 21 | |
alexeagle | c028da6 | 2017-04-27 17:18:39 +0200 | [diff] [blame] | 22 | package(default_visibility = ["//visibility:public"]) |
| 23 | |
Alex Eagle | 2cd949c | 2019-03-11 15:17:25 -0700 | [diff] [blame] | 24 | exports_files(["tsetse/tsconfig.json"]) |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 25 | |
alexeagle | 6c23d7e | 2019-03-06 09:30:48 -0800 | [diff] [blame] | 26 | bzl_library( |
| 27 | name = "bzl", |
| 28 | srcs = glob(["common/*.bzl"]), |
| 29 | visibility = ["//visibility:public"], |
| 30 | ) |
| 31 | |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 32 | # Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript |
| 33 | nodejs_binary( |
| 34 | name = "tsc", |
Greg Magolan | b3f8140 | 2018-09-25 13:18:13 -0700 | [diff] [blame] | 35 | data = [ |
Greg Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 36 | "@npm//source-map-support", |
| 37 | "@npm//typescript", |
Greg Magolan | b3f8140 | 2018-09-25 13:18:13 -0700 | [diff] [blame] | 38 | ], |
Greg Magolan | 4d88224 | 2019-06-19 12:23:05 -0700 | [diff] [blame] | 39 | entry_point = "@npm//:node_modules/typescript/lib/tsc.js", |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 40 | visibility = ["//internal:__subpackages__"], |
| 41 | ) |
| 42 | |
| 43 | # Build our custom compiler using the vanilla one |
| 44 | ts_library( |
| 45 | name = "tsc_wrapped", |
Alex Eagle | 71a24a9 | 2018-07-20 22:25:22 +0200 | [diff] [blame] | 46 | srcs = glob( |
| 47 | [ |
| 48 | "tsc_wrapped/*.ts", |
rjamet | 50b0337 | 2019-05-10 05:10:24 -0700 | [diff] [blame] | 49 | "tsetse/**/*.ts", |
Alex Eagle | 71a24a9 | 2018-07-20 22:25:22 +0200 | [diff] [blame] | 50 | ], |
| 51 | exclude = [ |
| 52 | "**/test_support.ts", |
| 53 | "**/*_test.ts", |
| 54 | ], |
| 55 | ), |
Greg Magolan | 9269f6c | 2018-03-05 20:06:22 +0100 | [diff] [blame] | 56 | compiler = ":tsc", |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 57 | data = [ |
alexeagle | 4aaa96b | 2018-07-19 19:21:45 +0200 | [diff] [blame] | 58 | "//third_party/github.com/bazelbuild/bazel/src/main/protobuf:worker_protocol.proto", |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 59 | ], |
Alex Eagle | 71a24a9 | 2018-07-20 22:25:22 +0200 | [diff] [blame] | 60 | module_name = "@bazel/typescript", |
| 61 | module_root = "tsc_wrapped/index.d.ts", |
Alex Eagle | 71a24a9 | 2018-07-20 22:25:22 +0200 | [diff] [blame] | 62 | supports_workers = False, |
| 63 | tsconfig = "//internal:tsc_wrapped/tsconfig.json", |
| 64 | visibility = ["//visibility:public"], |
Greg Magolan | b3f8140 | 2018-09-25 13:18:13 -0700 | [diff] [blame] | 65 | # Cannot have any deps (except npm fine grained deps) because it doesn't |
| 66 | # work with vanilla tsc. |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 67 | # Workaround for https://github.com/Microsoft/TypeScript/issues/22208 |
| 68 | deps = [ |
Greg Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 69 | "@npm//@types/node", |
martinprobst | 6fb705c | 2019-03-28 08:14:59 -0700 | [diff] [blame] | 70 | "@npm//protobufjs", |
Greg Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 71 | "@npm//tsickle", |
| 72 | "@npm//tsutils", |
| 73 | "@npm//typescript", |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 74 | ], |
| 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 Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 79 | # TODO(gregmagolan): make @npm//tsickle dependency optional |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 80 | nodejs_binary( |
| 81 | name = "tsc_wrapped_bin", |
| 82 | data = [ |
| 83 | ":tsc_wrapped", |
Greg Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 84 | "@npm//protobufjs", |
| 85 | "@npm//source-map-support", |
| 86 | "@npm//tsickle", |
| 87 | "@npm//tsutils", |
| 88 | "@npm//typescript", |
Alex Eagle | d92ffa5 | 2019-05-31 13:20:45 -0700 | [diff] [blame] | 89 | "//third_party/github.com/bazelbuild/bazel/src/main/protobuf:worker_protocol.proto", |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 90 | ], |
Greg Magolan | 716e45d | 2019-06-07 10:50:13 -0700 | [diff] [blame] | 91 | entry_point = ":tsc_wrapped/tsc_wrapped.ts", |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 92 | visibility = ["//visibility:public"], |
| 93 | ) |
| 94 | |
| 95 | ts_library( |
| 96 | name = "test_lib", |
rjamet | 50b0337 | 2019-05-10 05:10:24 -0700 | [diff] [blame] | 97 | 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 Eagle | 9cfa567 | 2019-04-01 16:20:13 -0700 | [diff] [blame] | 104 | compiler = "@build_bazel_rules_typescript//internal:tsc_wrapped_bin", |
rjamet | 50b0337 | 2019-05-10 05:10:24 -0700 | [diff] [blame] | 105 | tsconfig = "//internal:tsc_wrapped/tsconfig.json", |
Greg Magolan | b3f8140 | 2018-09-25 13:18:13 -0700 | [diff] [blame] | 106 | deps = [ |
| 107 | ":tsc_wrapped", |
Greg Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 108 | "@npm//@types/jasmine", |
| 109 | "@npm//@types/node", |
alexeagle | 8c1630b | 2018-12-10 13:14:33 -0800 | [diff] [blame] | 110 | "@npm//tsickle", |
Greg Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 111 | "@npm//typescript", |
Greg Magolan | b3f8140 | 2018-09-25 13:18:13 -0700 | [diff] [blame] | 112 | ], |
alexeagle | 249a43a | 2018-03-01 16:31:18 +0100 | [diff] [blame] | 113 | ) |
| 114 | |
| 115 | jasmine_node_test( |
| 116 | name = "test", |
| 117 | srcs = [], |
Greg Magolan | b3f8140 | 2018-09-25 13:18:13 -0700 | [diff] [blame] | 118 | deps = [ |
| 119 | ":test_lib", |
Greg Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 120 | "@npm//jasmine", |
alexeagle | ba3f819 | 2018-11-15 15:10:53 -0800 | [diff] [blame] | 121 | "@npm//protobufjs", |
| 122 | "@npm//source-map", |
Greg Magolan | 0e70c11 | 2018-10-04 07:44:14 -0700 | [diff] [blame] | 123 | "@npm//typescript", |
Greg Magolan | b3f8140 | 2018-09-25 13:18:13 -0700 | [diff] [blame] | 124 | ], |
| 125 | ) |
| 126 | |
alexeagle | b0daa89 | 2019-02-04 11:45:53 -0800 | [diff] [blame] | 127 | # 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 |
| 129 | genrule( |
| 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 Magolan | a8f559a | 2019-02-01 16:10:36 -0800 | [diff] [blame] | 137 | filegroup( |
| 138 | name = "npm_package_assets", |
Greg Magolan | b3f8140 | 2018-09-25 13:18:13 -0700 | [diff] [blame] | 139 | srcs = [ |
Minko Gechev | 18f5df6 | 2018-12-12 15:22:45 -0800 | [diff] [blame] | 140 | "common/compilation.bzl", |
| 141 | "common/json_marshal.bzl", |
| 142 | "common/module_mappings.bzl", |
| 143 | "common/tsconfig.bzl", |
Wassim Chegham | bef0cb4 | 2018-12-19 14:42:25 -0800 | [diff] [blame] | 144 | ], |
Minko Gechev | 18f5df6 | 2018-12-12 15:22:45 -0800 | [diff] [blame] | 145 | ) |