blob: eb0fb54bc98ef85eee40a6386e1a034ba352b4b6 [file] [log] [blame]
# 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
package(default_visibility = ["//visibility:public"])
exports_files([
# Exported to be consumed for generating skydoc.
"build_defs.bzl",
"ts_config.bzl",
"ts_repositories.bzl",
"tsetse/tsconfig.json",
])
load("//internal:defaults.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "jasmine_node_test", "npm_package")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
# Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript
nodejs_binary(
name = "tsc",
data = [
"@npm//source-map-support",
"@npm//typescript",
],
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",
],
),
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//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",
"@npm//protobufjs",
"@npm//source-map-support",
"@npm//tsickle",
"@npm//tsutils",
"@npm//typescript",
],
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"],
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//bytebuffer",
"@npm//jasmine",
"@npm//protobufjs",
"@npm//source-map",
"@npm//typescript",
],
)
genrule(
name = "license_copy",
srcs = ["//:LICENSE"],
outs = ["LICENSE"],
cmd = "cp $< $@",
)
genrule(
name = "worker_protocol_copy",
srcs = ["//third_party/github.com/bazelbuild/bazel/src/main/protobuf:worker_protocol.proto"],
outs = ["worker_protocol.proto"],
cmd = "cp $< $@",
)
genrule(
name = "check_version_copy",
srcs = ["//tools:check_version.js"],
outs = ["check_version.js"],
cmd = "cp $< $@",
)
npm_package(
name = "npm_package",
srcs = [
"README.md",
"package.json",
],
deps = [
":check_version_copy",
":license_copy",
":tsc_wrapped",
":worker_protocol_copy",
],
)
pkg_tar(
name = "tsc_wrapped_pkg",
srcs = glob([
"tsc_wrapped/**",
]),
package_dir = "tsc_wrapped",
)
pkg_tar(
name = "common_pkg",
srcs = [
"common/compilation.bzl",
"common/json_marshal.bzl",
"common/module_mappings.bzl",
"common/tsconfig.bzl",
],
package_dir = "common",
)
pkg_tar(
name = "package",
srcs = [
"build_defs.bzl",
"ts_config.bzl",
"ts_repositories.bzl",
"BUILD.bazel",
"yarn.lock",
"package.json",
],
package_dir = "internal",
deps = [
":tsc_wrapped_pkg",
":common_pkg",
"//internal/karma:package",
"//internal/protobufjs:package",
"//internal/devserver:package",
]
)