diff --git a/packages/concatjs/third_party/google3/rules_typescript/defs.bzl b/packages/concatjs/third_party/google3/rules_typescript/defs.bzl index 4c29df52d2..5c537d6d07 100644 --- a/packages/concatjs/third_party/google3/rules_typescript/defs.bzl +++ b/packages/concatjs/third_party/google3/rules_typescript/defs.bzl @@ -17,3 +17,4 @@ Users should not load files under "/internal" """ load("//internal:build_defs.bzl", "ts_library") +load("//internal:ts_config.bzl", "ts_config") diff --git a/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/BUILD.bazel b/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/BUILD.bazel new file mode 100644 index 0000000000..e1d13f65bf --- /dev/null +++ b/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/BUILD.bazel @@ -0,0 +1,35 @@ +# 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. + +package(default_visibility = ["//visibility:public"]) + +load("//:defs.bzl", "ts_config", "ts_library") + +# Because our tsconfig.json has an extends property, we must also tell the +# ts_library to include the extended tsconfig file in compilations. +# The ts_library rule will generate its own tsconfig which extends from the +# src file. +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = ["tsconfig-base.json"], +) + +ts_library( + name = "tsconfig_extends", + srcs = [ + "uses_promise.ts", + ], + tsconfig = ":tsconfig", +) diff --git a/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/tsconfig-base.json b/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/tsconfig-base.json new file mode 100644 index 0000000000..b549881810 --- /dev/null +++ b/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/tsconfig-base.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "lib": ["es2015.promise", "es5"] + } +} \ No newline at end of file diff --git a/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/tsconfig.json b/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/tsconfig.json new file mode 100644 index 0000000000..712de299b0 --- /dev/null +++ b/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig-base" +} + diff --git a/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/uses_promise.ts b/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/uses_promise.ts new file mode 100644 index 0000000000..4d2e73b457 --- /dev/null +++ b/packages/concatjs/third_party/google3/rules_typescript/examples/tsconfig_extends/uses_promise.ts @@ -0,0 +1,3 @@ +export function hiLater(): Promise { + return Promise.resolve('hi'); +} diff --git a/packages/concatjs/third_party/google3/rules_typescript/internal/build_defs.bzl b/packages/concatjs/third_party/google3/rules_typescript/internal/build_defs.bzl index a79ffb8fb7..ed80d0d118 100644 --- a/packages/concatjs/third_party/google3/rules_typescript/internal/build_defs.bzl +++ b/packages/concatjs/third_party/google3/rules_typescript/internal/build_defs.bzl @@ -19,6 +19,7 @@ load(":common/compilation.bzl", "COMMON_ATTRIBUTES", "compile_ts", "ts_providers_dict_to_struct") load(":executables.bzl", "get_tsc") load(":common/tsconfig.bzl", "create_tsconfig") +load(":ts_config.bzl", "TsConfig") def _compile_action(ctx, inputs, outputs, config_file_path): externs_files = [] @@ -39,6 +40,8 @@ def _compile_action(ctx, inputs, outputs, config_file_path): if f.path.endswith(".ts") or f.path.endswith(".json")] if ctx.file.tsconfig: action_inputs += [ctx.file.tsconfig] + if TsConfig in ctx.attr.tsconfig: + action_inputs += ctx.attr.tsconfig[TsConfig].deps # One at-sign makes this a params-file, enabling the worker strategy. # Two at-signs escapes the argument so it's passed through to tsc_wrapped @@ -103,7 +106,7 @@ def tsc_wrapped_tsconfig(ctx, # this gives extra error-checking. if ctx.file.tsconfig: workspace_path = config["compilerOptions"]["rootDir"] - config["extends"] = "/".join([workspace_path, ctx.file.tsconfig.path[:-5]]) + config["extends"] = "/".join([workspace_path, ctx.file.tsconfig.path[:-len(".json")]]) return config @@ -141,14 +144,14 @@ ts_library = rule( # be portable across internal/external, so we need this attribute # internally as well. "tsconfig": - attr.label(allow_files = True, single_file=True), + attr.label(allow_files = True, single_file = True), "compiler": attr.label( default=get_tsc(), single_file=False, allow_files=True, executable=True, - cfg="host",), + cfg="host"), "supports_workers": attr.bool(default = True), # @// is special syntax for the "main" repository # The default assumes the user specified a target "node_modules" in their diff --git a/packages/concatjs/third_party/google3/rules_typescript/internal/ts_config.bzl b/packages/concatjs/third_party/google3/rules_typescript/internal/ts_config.bzl new file mode 100644 index 0000000000..0aa4690dde --- /dev/null +++ b/packages/concatjs/third_party/google3/rules_typescript/internal/ts_config.bzl @@ -0,0 +1,31 @@ +# 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. + +"""The ts_config rule allows users to express tsconfig.json file groups. +""" + +TsConfig = provider() + +def _ts_config_impl(ctx): + files = depset() + files += [ctx.file.src] + return [DefaultInfo(files = files), TsConfig(deps = ctx.files.deps)] + +ts_config = rule( + implementation = _ts_config_impl, + attrs = { + "src": attr.label(allow_files = True, single_file = True, mandatory = True), + "deps": attr.label_list(allow_files = True, mandatory = True), + }, +)