Skip to content

Commit f8d22a9

Browse files
devversionjosephperrott
authored andcommitted
fix(bazel): allow ng_package to work with rules_js dependencies (angular#59316)
Currently the module mapping aspect fails when it transitively discovers a node module target managed by `rules_js`. That is because the targets don't have a `deps` attribute as part of their rule definition. PR Close angular#59316
1 parent 8c5db3c commit f8d22a9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/bazel/src/ng_package/ng_package.bzl

+12-7
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ _NG_PACKAGE_MODULE_MAPPINGS_ATTR = "ng_package_module_mappings"
3737

3838
def _ng_package_module_mappings_aspect_impl(target, ctx):
3939
mappings = dict()
40-
for dep in ctx.rule.attr.deps:
41-
if hasattr(dep, _NG_PACKAGE_MODULE_MAPPINGS_ATTR):
42-
for k, v in getattr(dep, _NG_PACKAGE_MODULE_MAPPINGS_ATTR).items():
43-
if k in mappings and mappings[k] != v:
44-
fail(("duplicate module mapping at %s: %s maps to both %s and %s" %
45-
(target.label, k, mappings[k], v)), "deps")
46-
mappings[k] = v
40+
41+
# Note: the target might not have `deps`. e.g.
42+
# in `rules_js`, node module targets don't have such attribute.
43+
if hasattr(ctx.rule.attr, "deps"):
44+
for dep in ctx.rule.attr.deps:
45+
if hasattr(dep, _NG_PACKAGE_MODULE_MAPPINGS_ATTR):
46+
for k, v in getattr(dep, _NG_PACKAGE_MODULE_MAPPINGS_ATTR).items():
47+
if k in mappings and mappings[k] != v:
48+
fail(("duplicate module mapping at %s: %s maps to both %s and %s" %
49+
(target.label, k, mappings[k], v)), "deps")
50+
mappings[k] = v
51+
4752
if ((hasattr(ctx.rule.attr, "module_name") and ctx.rule.attr.module_name) or
4853
(hasattr(ctx.rule.attr, "module_root") and ctx.rule.attr.module_root)):
4954
mn = ctx.rule.attr.module_name

0 commit comments

Comments
 (0)