From b14537a004c359fa5823e842ba7b8e26f979b9fb Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 2 Apr 2019 11:42:58 -0700 Subject: [PATCH] fix(bazel): use //:tsconfig.json as the default for ng_module (#29670) This matches the behavior of ts_library PR Close #29670 --- BUILD.bazel | 6 +++++- packages/bazel/index.bzl | 2 +- packages/bazel/src/ng_module.bzl | 18 ++++++++++++++++++ .../bazel/ng_module/BUILD.bazel | 1 + tools/defaults.bzl | 16 +++++----------- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 09ebe562dd..0ade4f4beb 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -5,13 +5,17 @@ package(default_visibility = ["//visibility:public"]) load("//tools:defaults.bzl", "karma_web_test") exports_files([ - "tsconfig.json", "LICENSE", "protractor-perf.conf.js", "karma-js.conf.js", "browser-providers.conf.js", ]) +alias( + name = "tsconfig.json", + actual = "//packages:tsconfig-build.json", +) + filegroup( name = "web_test_bootstrap_scripts", # do not sort diff --git a/packages/bazel/index.bzl b/packages/bazel/index.bzl index 11c5eb8509..9a7098e141 100644 --- a/packages/bazel/index.bzl +++ b/packages/bazel/index.bzl @@ -13,7 +13,7 @@ load( _protractor_web_test = "protractor_web_test", _protractor_web_test_suite = "protractor_web_test_suite", ) -load("//packages/bazel/src:ng_module.bzl", _ng_module = "ng_module") +load("//packages/bazel/src:ng_module.bzl", _ng_module = "ng_module_macro") ng_module = _ng_module ng_package = _ng_package diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index 75bb8b10fc..8dd1061f14 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -736,3 +736,21 @@ This rule extends the [ts_library] rule. [ts_library]: http://tsetse.info/api/build_defs.html#ts_library """ + +def ng_module_macro(tsconfig = None, **kwargs): + """Wraps `ng_module` to set the default for the `tsconfig` attribute. + + This must be a macro so that the string is converted to a label in the context of the + workspace that declares the `ng_module` target, rather than the workspace that defines + `ng_module`, or the workspace where the build is taking place. + + This macro is re-exported as `ng_module` in the public API. + + Args: + tsconfig: the label pointing to a tsconfig.json file + **kwargs: remaining args to pass to the ng_module rule + """ + if not tsconfig: + tsconfig = "//:tsconfig.json" + + ng_module(tsconfig = tsconfig, **kwargs) diff --git a/packages/compiler-cli/integrationtest/bazel/ng_module/BUILD.bazel b/packages/compiler-cli/integrationtest/bazel/ng_module/BUILD.bazel index 10d4f052be..fae0105f2b 100644 --- a/packages/compiler-cli/integrationtest/bazel/ng_module/BUILD.bazel +++ b/packages/compiler-cli/integrationtest/bazel/ng_module/BUILD.bazel @@ -21,6 +21,7 @@ ng_module( deps = [ "//packages/core", "@npm//@types", + "@npm//tslib", ], ) diff --git a/tools/defaults.bzl b/tools/defaults.bzl index 038c22506f..c3ad35e90d 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -7,7 +7,6 @@ load("@npm_bazel_typescript//:index.bzl", _ts_library = "ts_library") load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package") load("//packages/bazel/src:ng_rollup_bundle.bzl", _ng_rollup_bundle = "ng_rollup_bundle") -_DEFAULT_TSCONFIG_BUILD = "//packages:tsconfig-build.json" _DEFAULT_TSCONFIG_TEST = "//packages:tsconfig-test" _INTERNAL_NG_MODULE_API_EXTRACTOR = "//packages/bazel/src/api-extractor:api_extractor" _INTERNAL_NG_MODULE_COMPILER = "//packages/bazel/src/ngc-wrapped" @@ -84,11 +83,8 @@ def ts_library(tsconfig = None, testonly = False, deps = [], module_name = None, # Match the types[] in //packages:tsconfig-test.json deps.append("@npm//@types/jasmine") deps.append("@npm//@types/node") - if not tsconfig: - if testonly: - tsconfig = _DEFAULT_TSCONFIG_TEST - else: - tsconfig = _DEFAULT_TSCONFIG_BUILD + if not tsconfig and testonly: + tsconfig = _DEFAULT_TSCONFIG_TEST if not module_name: module_name = _default_module_name(testonly) @@ -108,11 +104,9 @@ def ng_module(name, tsconfig = None, entry_point = None, testonly = False, deps # Match the types[] in //packages:tsconfig-test.json deps.append("@npm//@types/jasmine") deps.append("@npm//@types/node") - if not tsconfig: - if testonly: - tsconfig = _DEFAULT_TSCONFIG_TEST - else: - tsconfig = _DEFAULT_TSCONFIG_BUILD + if not tsconfig and testonly: + tsconfig = _DEFAULT_TSCONFIG_TEST + if not module_name: module_name = _default_module_name(testonly) if not entry_point: