diff --git a/js/private/js_helpers.bzl b/js/private/js_helpers.bzl index 96a9aef07..52ef23d59 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 0a756a67c..af2df9f44 100644 --- a/js/private/js_info.bzl +++ b/js/private/js_info.bzl @@ -3,53 +3,59 @@ JsInfo = provider( doc = "Encapsulates information provided by rules in rules_js and derivative rule sets", fields = { + "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(), 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: + 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(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( + 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 400d8cf23..1beedee53 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 98b0a3cbe..d02768d8f 100644 --- a/js/private/js_library.bzl +++ b/js/private/js_library.bzl @@ -214,12 +214,12 @@ def _js_library_impl(ctx): return [ js_info( + 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 f61354895..cc4f3ae6a 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 7ec7e587d..973f85cc6 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, ),