From 9da68a77e612d8f9e8ecdc9f77a43444d0e95461 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 6 Jul 2021 15:42:32 +0200 Subject: [PATCH] refactor(bazel): compatibility with `rules_nodejs` v4.0.0 (#42760) This commit applies changes to `@angular/bazel` which are necessary to support the Bazel NodeJS rules v4.0.0. The Bazel NodeJS rules no longer support the `_tslibrary` option for the `LinkablePackageInfo` provider and therefore we need to stop using it. Due to this removal, we also need to add two new attributes called `package_name` and `package_path` so that the API of `ng_module` matches `ts_library`. Note: This is denoted as `refactor` as we currently are not able to merge feature commits into patch branches, but we want the tooling to not diverge significantly between the patch and next branch. It is planned to update the merge tooling to allow for such changes to land. PR Close #42760 --- packages/bazel/src/ng_module.bzl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index c5a295f7be..bd20218a7f 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -682,13 +682,13 @@ def _ng_module_impl(ctx): # once it is no longer needed. ]) - if ctx.attr.module_name: + if ctx.attr.package_name: path = "/".join([p for p in [ctx.bin_dir.path, ctx.label.workspace_root, ctx.label.package] if p]) ts_providers["providers"].append(LinkablePackageInfo( - package_name = ctx.attr.module_name, + package_name = ctx.attr.package_name, + package_path = ctx.attr.package_path, path = path, files = ts_providers["typescript"]["es5_sources"], - _tslibrary = True, )) return ts_providers_dict_to_struct(ts_providers) @@ -750,6 +750,22 @@ NG_MODULE_ATTRIBUTES = { doc = "Private API to control production of performance metric JSON files", ), "_supports_workers": attr.bool(default = True), + + # Matches the API of the `ts_library` rule from `@bazel/typescript`. + # https://github.com/bazelbuild/rules_nodejs/blob/398d351a3f2a9b2ebf6fc31fb5882cce7eedfd7b/packages/typescript/internal/build_defs.bzl#L435-L446. + "package_name": attr.string( + doc = """The package name that the linker will link this `ng_module` output as. + If `package_path` is set, the linker will link this package under `/node_modules/`. + If `package_path` is not set, the package will be linked in the top-level workspace node_modules folder.""", + ), + + # Matches the API of the `ts_library` rule from `@bazel/typescript`. + # https://github.com/bazelbuild/rules_nodejs/blob/398d351a3f2a9b2ebf6fc31fb5882cce7eedfd7b/packages/typescript/internal/build_defs.bzl#L435-L446. + "package_path": attr.string( + doc = """The package path in the workspace that the linker will link this `ng_module` output to. + If `package_path` is set, the linker will link this package under `/node_modules/`. + If `package_path` is not set, the package will be linked in the top-level workspace node_modules folder.""", + ), } NG_MODULE_RULE_ATTRS = dict(dict(COMMON_ATTRIBUTES, **NG_MODULE_ATTRIBUTES), **{