From 6898eab9465bf4b9d4981cc442832987fb3bb536 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 30 Mar 2020 14:35:11 -0700 Subject: [PATCH] feat(bazel): provide LinkablePackageInfo from ng_module (#37623) Adds the `LinkablePackageInfo` to the `ng_module` rule. This allows the linker to properly link `ng_module` targets in Node runtime actions. Currently this does not work properly and packages like `@angular/core` are not linked, so we cannot rely on the linker. https://github.com/bazelbuild/rules_nodejs/blob/9a5de3728b05bf1647bbb87ad99f54e626604705/internal/linker/link_node_modules.bzl#L144-L146. PR Close #37623 --- packages/bazel/src/external.bzl | 2 ++ packages/bazel/src/ng_module.bzl | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/bazel/src/external.bzl b/packages/bazel/src/external.bzl index 73c74ddf59..982d654eea 100644 --- a/packages/bazel/src/external.bzl +++ b/packages/bazel/src/external.bzl @@ -19,12 +19,14 @@ load( ) load( "@build_bazel_rules_nodejs//:providers.bzl", + _LinkablePackageInfo = "LinkablePackageInfo", _NpmPackageInfo = "NpmPackageInfo", _js_ecma_script_module_info = "js_ecma_script_module_info", _js_named_module_info = "js_named_module_info", _node_modules_aspect = "node_modules_aspect", ) +LinkablePackageInfo = _LinkablePackageInfo NpmPackageInfo = _NpmPackageInfo node_modules_aspect = _node_modules_aspect diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index 309d69c1e7..db11f59ca5 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -14,6 +14,7 @@ load( "DEFAULT_NG_COMPILER", "DEFAULT_NG_XI18N", "DEPS_ASPECTS", + "LinkablePackageInfo", "NpmPackageInfo", "TsConfigInfo", "compile_ts", @@ -650,6 +651,15 @@ def _ng_module_impl(ctx): # once it is no longer needed. ]) + if ctx.attr.module_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, + path = path, + files = ts_providers["typescript"]["es5_sources"], + _tslibrary = True, + )) + return ts_providers_dict_to_struct(ts_providers) local_deps_aspects = [node_modules_aspect, _collect_summaries_aspect]