| # 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. |
| |
| # gazelle:exclude worker_protocol.proto |
| |
| load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") |
| load("@bazel_skylib//:bzl_library.bzl", "bzl_library") |
| load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test") |
| load("@npm_bazel_typescript//:index.bzl", "ts_library") |
| |
| package(default_visibility = ["//visibility:public"]) |
| |
| exports_files(["tsetse/tsconfig.json"]) |
| |
| bzl_library( |
| name = "bzl", |
| srcs = glob(["common/*.bzl"]), |
| visibility = ["//visibility:public"], |
| ) |
| |
| # Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript |
| nodejs_binary( |
| name = "tsc", |
| data = [ |
| "@npm//source-map-support", |
| "@npm//typescript", |
| ], |
| entry_point = "@npm//:node_modules/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", |
| ], |
| exclude = [ |
| "**/test_support.ts", |
| "**/*_test.ts", |
| ], |
| ), |
| compiler = ":tsc", |
| data = [ |
| "//third_party/github.com/bazelbuild/bazel/src/main/protobuf:worker_protocol.proto", |
| ], |
| module_name = "@bazel/typescript", |
| module_root = "tsc_wrapped/index.d.ts", |
| supports_workers = False, |
| tsconfig = "//internal:tsc_wrapped/tsconfig.json", |
| visibility = ["//visibility:public"], |
| # Cannot have any deps (except npm fine grained deps) because it doesn't |
| # work with vanilla tsc. |
| # Workaround for https://github.com/Microsoft/TypeScript/issues/22208 |
| deps = [ |
| "@npm//@types/node", |
| "@npm//protobufjs", |
| "@npm//tsickle", |
| "@npm//tsutils", |
| "@npm//typescript", |
| ], |
| ) |
| |
| # Other ts_library rules will use this custom compiler, which calls the |
| # TypeScript APIs to act like tsc, but adds capabilities like Bazel workers. |
| # TODO(gregmagolan): make @npm//tsickle dependency optional |
| nodejs_binary( |
| name = "tsc_wrapped_bin", |
| data = [ |
| ":tsc_wrapped", |
| "//third_party/github.com/bazelbuild/bazel/src/main/protobuf:worker_protocol.proto", |
| "@npm//protobufjs", |
| "@npm//source-map-support", |
| "@npm//tsickle", |
| "@npm//tsutils", |
| "@npm//typescript", |
| ], |
| entry_point = ":tsc_wrapped/tsc_wrapped.ts", |
| visibility = ["//visibility:public"], |
| ) |
| |
| ts_library( |
| name = "test_lib", |
| srcs = glob([ |
| "tsc_wrapped/*_test.ts", |
| "tsetse/**/*_test.ts", |
| ]) + [ |
| "tsc_wrapped/test_support.ts", |
| "tsetse/util/testing/test_support.ts", |
| ], |
| compiler = "@build_bazel_rules_typescript//internal:tsc_wrapped_bin", |
| tsconfig = "//internal:tsc_wrapped/tsconfig.json", |
| deps = [ |
| ":tsc_wrapped", |
| "@npm//@types/jasmine", |
| "@npm//@types/node", |
| "@npm//tsickle", |
| "@npm//typescript", |
| ], |
| ) |
| |
| jasmine_node_test( |
| name = "test", |
| srcs = [], |
| deps = [ |
| ":test_lib", |
| "@npm//jasmine", |
| "@npm//protobufjs", |
| "@npm//source-map", |
| "@npm//typescript", |
| ], |
| ) |
| |
| # We don't need to distribute any of the content of the BUILD.bazel file in this package |
| # So generate an empty marker file |
| genrule( |
| name = "generated_BUILD", |
| srcs = [], |
| # Name the output "BUILD" so it doesn't collide with InputArtifact "BUILD.bazel" |
| outs = ["BUILD"], |
| cmd = "echo \"# Marker that this directory is a Bazel package\" > $@", |
| ) |
| |
| filegroup( |
| name = "npm_package_assets", |
| srcs = [ |
| "common/compilation.bzl", |
| "common/json_marshal.bzl", |
| "common/module_mappings.bzl", |
| "common/tsconfig.bzl", |
| ], |
| ) |