diff --git a/js/private/js_helpers.bzl b/js/private/js_helpers.bzl index 96a9aef07d..52ef23d59b 100644 --- a/js/private/js_helpers.bzl +++ b/js/private/js_helpers.bzl @@ -222,8 +222,8 @@ def gather_runfiles( transitive_files_depsets.append(gather_files_from_js_info( targets = data + deps, include_sources = include_sources, - include_transitive_sources = include_transitive_sources, include_types = include_types, + include_transitive_sources = include_transitive_sources, include_transitive_types = include_transitive_types, include_npm_sources = include_npm_sources, )) @@ -285,8 +285,8 @@ def envs_for_log_level(log_level): def gather_files_from_js_info( targets, include_sources, - include_transitive_sources, include_types, + include_transitive_sources, include_transitive_types, include_npm_sources): """Gathers files from JsInfo and NpmPackageStoreInfo providers. @@ -294,8 +294,8 @@ def gather_files_from_js_info( Args: targets: list of target to gather from include_sources: see js_info_files documentation - include_transitive_sources: see js_info_files documentation include_types: see js_info_files documentation + include_transitive_sources: see js_info_files documentation include_transitive_types: see js_info_files documentation include_npm_sources: see js_info_files documentation @@ -309,18 +309,18 @@ def gather_files_from_js_info( for target in targets if JsInfo in target and hasattr(target[JsInfo], "sources") ] - if include_transitive_sources: - files_depsets.extend([ - target[JsInfo].transitive_sources - for target in targets - if JsInfo in target and hasattr(target[JsInfo], "transitive_sources") - ]) if include_types: files_depsets.extend([ target[JsInfo].types for target in targets if JsInfo in target and hasattr(target[JsInfo], "types") ]) + if include_transitive_sources: + files_depsets.extend([ + target[JsInfo].transitive_sources + for target in targets + if JsInfo in target and hasattr(target[JsInfo], "transitive_sources") + ]) if include_transitive_types: files_depsets.extend([ target[JsInfo].transitive_types diff --git a/js/private/js_info.bzl b/js/private/js_info.bzl index 0a756a67c8..050251a1b0 100644 --- a/js/private/js_info.bzl +++ b/js/private/js_info.bzl @@ -3,53 +3,73 @@ JsInfo = provider( doc = "Encapsulates information provided by rules in rules_js and derivative rule sets", fields = { + "target": "The label of target that created this JsInfo", + "bin_dir": "The root corresponding to bin directory for the target", + "sources": "A depset of source files produced by the target", "types": "A depset of typings files produced by the target", + "transitive_sources": "A depset of source files produced by the target and the target's transitive deps", + "transitive_types": "A depset of declaration files produced by the target and the target's transitive deps", "npm_sources": "A depset of files in npm package dependencies of the target and the target's transitive deps", "npm_package_store_infos": "A depset of NpmPackageStoreInfo providers from non-dev npm dependencies of the target and the target's transitive dependencies to use as direct dependencies when linking downstream npm_package targets with npm_link_package", - "sources": "A depset of source files produced by the target", - "transitive_types": "A depset of declaration files produced by the target and the target's transitive deps", - "transitive_sources": "A depset of source files produced by the target and the target's transitive deps", }, ) def js_info( - types = depset(), - npm_sources = depset(), - npm_package_store_infos = depset(), + target, + bin_dir, sources = depset(), + types = depset(), + transitive_sources = depset(), transitive_types = depset(), - transitive_sources = depset()): + npm_sources = depset(), + npm_package_store_infos = depset()): """Construct a JsInfo. Args: + target: See JsInfo documentation + bin_dir: See JsInfo documentation + sources: See JsInfo documentation types: See JsInfo documentation + transitive_sources: See JsInfo documentation + transitive_types: See JsInfo documentation npm_sources: See JsInfo documentation npm_package_store_infos: See JsInfo documentation - sources: See JsInfo documentation - transitive_types: See JsInfo documentation - transitive_sources: See JsInfo documentation Returns: A JsInfo provider """ + if type(target) != "Label": + msg = "Expected target to be a Label but got {}".format(type(target)) + fail(msg) + if type(bin_dir) != "root": + msg = "Expected bin_dir to be a root type but got {}".format(type(bin_dir)) + fail(msg) + if type(sources) != "depset": + msg = "Expected sources to be a depset but got {}".format(type(sources)) + fail(msg) if type(types) != "depset": - fail("Expected types to be a depset") + msg = "Expected types to be a depset but got {}".format(type(types)) + fail(msg) + if type(transitive_sources) != "depset": + msg = "Expected transitive_sources to be a depset but got {}".format(type(transitive_sources)) + fail(msg) + if type(transitive_types) != "depset": + msg = "Expected transitive_types to be a depset but got {}".format(type(transitive_types)) + fail(msg) if type(npm_sources) != "depset": - fail("Expected npm_sources to be a depset") + msg = "Expected npm_sources to be a depset but got {}".format(type(npm_sources)) + fail(msg) if type(npm_package_store_infos) != "depset": - fail("Expected npm_package_store_infos to be a depset") - if type(sources) != "depset": - fail("Expected sources to be a depset") - if type(transitive_types) != "depset": - fail("Expected transitive_types to be a depset") - if type(transitive_sources) != "depset": - fail("Expected transitive_sources to be a depset") + msg = "Expected npm_package_store_infos to be a depset but got {}".format(type(npm_package_store_infos)) + fail(msg) return JsInfo( + target = target, + bin_dir = bin_dir, + sources = sources, types = types, + transitive_sources = transitive_sources, + transitive_types = transitive_types, npm_sources = npm_sources, npm_package_store_infos = npm_package_store_infos, - sources = sources, - transitive_types = transitive_types, - transitive_sources = transitive_sources, ) diff --git a/js/private/js_info_files.bzl b/js/private/js_info_files.bzl index 400d8cf23e..1beedee535 100644 --- a/js/private/js_info_files.bzl +++ b/js/private/js_info_files.bzl @@ -11,8 +11,8 @@ def _js_info_files_impl(ctx): return DefaultInfo(files = _gather_files_from_js_info( targets = ctx.attr.srcs, include_sources = ctx.attr.include_sources, - include_transitive_sources = ctx.attr.include_transitive_sources, include_types = ctx.attr.include_types, + include_transitive_sources = ctx.attr.include_transitive_sources, include_transitive_types = ctx.attr.include_transitive_types, include_npm_sources = ctx.attr.include_npm_sources, )) diff --git a/js/private/js_library.bzl b/js/private/js_library.bzl index b318a349a6..6ddfa3441c 100644 --- a/js/private/js_library.bzl +++ b/js/private/js_library.bzl @@ -214,12 +214,14 @@ def _js_library_impl(ctx): return [ js_info( + target = ctx.label, + bin_dir = ctx.bin_dir, + sources = sources, types = types, + transitive_sources = transitive_sources, + transitive_types = transitive_types, npm_sources = npm_sources, npm_package_store_infos = npm_package_store_infos, - sources = sources, - transitive_types = transitive_types, - transitive_sources = transitive_sources, ), DefaultInfo( files = sources, diff --git a/js/private/js_run_devserver.bzl b/js/private/js_run_devserver.bzl index 4ca6a165c7..a759d581f3 100644 --- a/js/private/js_run_devserver.bzl +++ b/js/private/js_run_devserver.bzl @@ -43,8 +43,8 @@ def _js_run_devserver_impl(ctx): transitive_runfiles = [_gather_files_from_js_info( targets = ctx.attr.data, include_sources = True, - include_transitive_sources = ctx.attr.include_transitive_sources, include_types = ctx.attr.include_types, + include_transitive_sources = ctx.attr.include_transitive_sources, include_transitive_types = ctx.attr.include_types, include_npm_sources = ctx.attr.include_npm_sources, )] diff --git a/js/private/test/create_launcher/custom_test.bzl b/js/private/test/create_launcher/custom_test.bzl index 7ec7e587d7..973f85cc6f 100644 --- a/js/private/test/create_launcher/custom_test.bzl +++ b/js/private/test/create_launcher/custom_test.bzl @@ -22,8 +22,8 @@ def _custom_test_impl(ctx): transitive_files = js_lib_helpers.gather_files_from_js_info( targets = ctx.attr.data, include_sources = True, - include_transitive_sources = ctx.attr.include_transitive_sources, include_types = ctx.attr.include_types, + include_transitive_sources = ctx.attr.include_transitive_sources, include_transitive_types = ctx.attr.include_types, include_npm_sources = ctx.attr.include_npm_sources, ), diff --git a/npm/private/npm_link_package_store.bzl b/npm/private/npm_link_package_store.bzl index 1ad9ed06a6..a86fdcff05 100644 --- a/npm/private/npm_link_package_store.bzl +++ b/npm/private/npm_link_package_store.bzl @@ -105,6 +105,8 @@ def _npm_link_package_store_impl(ctx): runfiles = ctx.runfiles(transitive_files = transitive_files_depset), ), js_info( + target = ctx.label, + bin_dir = ctx.bin_dir, npm_sources = transitive_files_depset, # only propagate non-dev npm dependencies to use as direct dependencies when linking downstream npm_package targets with npm_link_package npm_package_store_infos = depset([store_info]) if not store_info.dev else depset(),