From cf9f953ce3e334a7ab0af5eef94ea1e7e6d557a2 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Sun, 7 Apr 2024 15:44:43 -0700 Subject: [PATCH] refactor: rename js_filegroup to js_info_files (#1615) --- docs/BUILD.bazel | 4 +-- docs/js_filegroup.md | 32 ------------------- docs/js_info_files.md | 32 +++++++++++++++++++ docs/js_run_binary.md | 6 ++-- js/defs.bzl | 6 ++-- js/private/BUILD.bazel | 6 ++-- js/private/js_helpers.bzl | 20 ++++++------ .../{js_filegroup.bzl => js_info_files.bzl} | 6 ++-- js/private/js_run_binary.bzl | 24 +++++++------- 9 files changed, 68 insertions(+), 68 deletions(-) delete mode 100644 docs/js_filegroup.md create mode 100644 docs/js_info_files.md rename js/private/{js_filegroup.bzl => js_info_files.bzl} (96%) diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index ec5b8cd3c..17ce79702 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -22,8 +22,8 @@ stardoc_with_diff_test( ) stardoc_with_diff_test( - name = "js_filegroup", - bzl_library_target = "//js/private:js_filegroup", + name = "js_info_files", + bzl_library_target = "//js/private:js_info_files", ) stardoc_with_diff_test( diff --git a/docs/js_filegroup.md b/docs/js_filegroup.md deleted file mode 100644 index 2cca482d9..000000000 --- a/docs/js_filegroup.md +++ /dev/null @@ -1,32 +0,0 @@ - - -Helper rule to gather files from JsInfo providers of targets and provide them as default outputs - - - -## js_filegroup - -
-js_filegroup(name, include_declarations, include_npm_linked_packages, include_sources,
-             include_transitive_declarations, include_transitive_sources, srcs)
-
- -Gathers files from the JsInfo providers from targets in srcs and provides them as default outputs. - -This helper rule is used by the `js_run_binary` macro. - - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| include_declarations | When True, declarations from JsInfo providers in srcs targets are included in the default outputs of the target.

Defaults to False since declarations are generally not needed at runtime and introducing them could slow down developer round trip time due to having to generate typings on source file changes. | Boolean | optional | False | -| include_npm_linked_packages | When True, files in npm_linked_packages from JsInfo providers in srcs targets are included in the default outputs of the target.

transitive_files from NpmPackageStoreInfo providers in data targets are also included in the default outputs of the target. | Boolean | optional | True | -| include_sources | When True, sources from JsInfo providers in srcs targets are included in the default outputs of the target. | Boolean | optional | True | -| include_transitive_declarations | When True, transitive_declarations from JsInfo providers in srcs targets are included in the default outputs of the target.

Defaults to False since declarations are generally not needed at runtime and introducing them could slow down developer round trip time due to having to generate typings on source file changes. | Boolean | optional | False | -| include_transitive_sources | When True, transitive_sources from JsInfo providers in srcs targets are included in the default outputs of the target. | Boolean | optional | True | -| srcs | List of targets to gather files from. | List of labels | optional | [] | - - diff --git a/docs/js_info_files.md b/docs/js_info_files.md new file mode 100644 index 000000000..c5a8e7f4a --- /dev/null +++ b/docs/js_info_files.md @@ -0,0 +1,32 @@ + + +Helper rule to gather files from JsInfo providers of targets and provide them as default outputs + + + +## js_info_files + +
+js_info_files(name, include_declarations, include_npm_linked_packages, include_sources,
+              include_transitive_declarations, include_transitive_sources, srcs)
+
+ +Gathers files from the JsInfo providers from targets in srcs and provides them as default outputs. + +This helper rule is used by the `js_run_binary` macro. + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| include_declarations | When True, declarations from JsInfo providers in srcs targets are included in the default outputs of the target.

Defaults to False since declarations are generally not needed at runtime and introducing them could slow down developer round trip time due to having to generate typings on source file changes. | Boolean | optional | False | +| include_npm_linked_packages | When True, files in npm_linked_packages from JsInfo providers in srcs targets are included in the default outputs of the target.

transitive_files from NpmPackageStoreInfo providers in data targets are also included in the default outputs of the target. | Boolean | optional | True | +| include_sources | When True, sources from JsInfo providers in srcs targets are included in the default outputs of the target. | Boolean | optional | True | +| include_transitive_declarations | When True, transitive_declarations from JsInfo providers in srcs targets are included in the default outputs of the target.

Defaults to False since declarations are generally not needed at runtime and introducing them could slow down developer round trip time due to having to generate typings on source file changes. | Boolean | optional | False | +| include_transitive_sources | When True, transitive_sources from JsInfo providers in srcs targets are included in the default outputs of the target. | Boolean | optional | True | +| srcs | List of targets to gather files from. | List of labels | optional | [] | + + diff --git a/docs/js_run_binary.md b/docs/js_run_binary.md index b97e1d996..7b62a5a03 100644 --- a/docs/js_run_binary.md +++ b/docs/js_run_binary.md @@ -62,9 +62,9 @@ The following environment variables are made available to the Node.js runtime ba | silent_on_success | produce no output on stdout nor stderr when program exits with status code 0.

This makes node binaries match the expected bazel paradigm. | True | | use_execroot_entry_point | Use the entry_point script of the js_binary tool that is in the execroot output tree instead of the copy that is in runfiles.

Runfiles of tool are all hoisted to srcs of the underlying run_binary so they are included as execroot inputs to the action.

Using the entry point script that is in the execroot output tree means that there will be no conflicting runfiles node_modules in the node_modules resolution path which can confuse npm packages such as next and react that don't like being resolved in multiple node_modules trees. This more closely emulates the environment that tools such as Next.js see when they are run outside of Bazel.

When True, the js_binary tool must have copy_data_to_bin set to True (the default) so that all data files needed by the binary are available in the execroot output tree. This requirement can be turned off with by setting allow_execroot_entry_point_with_no_copy_data_to_bin to True. | True | | copy_srcs_to_bin | When True, all srcs files are copied to the output tree that are not already there. | True | -| include_transitive_sources | see js_filegroup documentation | True | -| include_declarations | see js_filegroup documentation | False | -| include_npm_linked_packages | see js_filegroup documentation | True | +| include_transitive_sources | see js_info_files documentation | True | +| include_declarations | see js_info_files documentation | False | +| include_npm_linked_packages | see js_info_files documentation | True | | log_level | Set the logging level of the js_binary tool.

This overrides the log level set on the js_binary tool target. | None | | mnemonic | A one-word description of the action, for example, CppCompile or GoLink. | "JsRunBinary" | | progress_message | Progress message to show to the user during the build, for example, "Compiling foo.cc to create foo.o". The message may contain %{label}, %{input}, or %{output} patterns, which are substituted with label string, first input, or output's path, respectively. Prefer to use patterns instead of static strings, because the former are more efficient. | None | diff --git a/js/defs.bzl b/js/defs.bzl index 12f80edd9..623a4b999 100644 --- a/js/defs.bzl +++ b/js/defs.bzl @@ -14,8 +14,8 @@ load( _js_run_binary = "js_run_binary", ) load( - "//js/private:js_filegroup.bzl", - _js_filegroup = "js_filegroup", + "//js/private:js_info_files.bzl", + _js_info_files = "js_info_files", ) load( "//js/private:js_run_devserver.bzl", @@ -45,7 +45,7 @@ def js_test(**kwargs): ) js_run_devserver = _js_run_devserver -js_filegroup = _js_filegroup +js_info_files = _js_info_files js_library = _js_library js_run_binary = _js_run_binary js_image_layer = _js_image_layer diff --git a/js/private/BUILD.bazel b/js/private/BUILD.bazel index b223fea54..16e59b39c 100644 --- a/js/private/BUILD.bazel +++ b/js/private/BUILD.bazel @@ -20,8 +20,8 @@ exports_files([ ]) bzl_library( - name = "js_filegroup", - srcs = ["js_filegroup.bzl"], + name = "js_info_files", + srcs = ["js_info_files.bzl"], visibility = [ "//docs:__subpackages__", "//js:__subpackages__", @@ -87,8 +87,8 @@ bzl_library( "//js:__subpackages__", ], deps = [ - ":js_filegroup", ":js_helpers", + ":js_info_files", ":js_library", "@aspect_bazel_lib//lib:copy_to_bin", "@aspect_bazel_lib//lib:run_binary", diff --git a/js/private/js_helpers.bzl b/js/private/js_helpers.bzl index f202ac72e..d7a5f5008 100644 --- a/js/private/js_helpers.bzl +++ b/js/private/js_helpers.bzl @@ -193,15 +193,15 @@ def gather_runfiles( file such as a file in an external repository. In most cases, this option is not needed. See `copy_data_files_to_bin` docstring for more info. - include_sources: see js_filegroup documentation + include_sources: see js_info_files documentation - include_transitive_sources: see js_filegroup documentation + include_transitive_sources: see js_info_files documentation - include_declarations: see js_filegroup documentation + include_declarations: see js_info_files documentation - include_transitive_declarations: see js_filegroup documentation + include_transitive_declarations: see js_info_files documentation - include_npm_linked_packages: see js_filegroup documentation + include_npm_linked_packages: see js_info_files documentation Returns: A [runfiles](https://bazel.build/rules/lib/runfiles) object created with [ctx.runfiles](https://bazel.build/rules/lib/ctx#runfiles). @@ -293,11 +293,11 @@ def gather_files_from_js_providers( Args: targets: list of target to gather from - include_sources: see js_filegroup documentation - include_transitive_sources: see js_filegroup documentation - include_declarations: see js_filegroup documentation - include_transitive_declarations: see js_filegroup documentation - include_npm_linked_packages: see js_filegroup documentation + include_sources: see js_info_files documentation + include_transitive_sources: see js_info_files documentation + include_declarations: see js_info_files documentation + include_transitive_declarations: see js_info_files documentation + include_npm_linked_packages: see js_info_files documentation Returns: A depset of files diff --git a/js/private/js_filegroup.bzl b/js/private/js_info_files.bzl similarity index 96% rename from js/private/js_filegroup.bzl rename to js/private/js_info_files.bzl index 6425bd37c..924094665 100644 --- a/js/private/js_filegroup.bzl +++ b/js/private/js_info_files.bzl @@ -7,7 +7,7 @@ _DOC = """Gathers files from the JsInfo providers from targets in srcs and provi This helper rule is used by the `js_run_binary` macro. """ -def _js_filegroup_impl(ctx): +def _js_info_files_impl(ctx): return DefaultInfo(files = _gather_files_from_js_providers( targets = ctx.attr.srcs, include_sources = ctx.attr.include_sources, @@ -17,9 +17,9 @@ def _js_filegroup_impl(ctx): include_npm_linked_packages = ctx.attr.include_npm_linked_packages, )) -js_filegroup = rule( +js_info_files = rule( doc = _DOC, - implementation = _js_filegroup_impl, + implementation = _js_info_files_impl, attrs = { "srcs": attr.label_list( doc = """List of targets to gather files from.""", diff --git a/js/private/js_run_binary.bzl b/js/private/js_run_binary.bzl index c07a8ddbd..35811cb09 100644 --- a/js/private/js_run_binary.bzl +++ b/js/private/js_run_binary.bzl @@ -15,7 +15,7 @@ load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils") load("@aspect_bazel_lib//lib:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin") load("@bazel_skylib//lib:dicts.bzl", "dicts") load(":js_helpers.bzl", _envs_for_log_level = "envs_for_log_level") -load(":js_filegroup.bzl", _js_filegroup = "js_filegroup") +load(":js_info_files.bzl", _js_info_files = "js_info_files") load(":js_library.bzl", _js_library = "js_library") def js_run_binary( @@ -150,11 +150,11 @@ def js_run_binary( copy_srcs_to_bin: When True, all srcs files are copied to the output tree that are not already there. - include_transitive_sources: see `js_filegroup` documentation + include_transitive_sources: see `js_info_files` documentation - include_declarations: see `js_filegroup` documentation + include_declarations: see `js_info_files` documentation - include_npm_linked_packages: see `js_filegroup` documentation + include_npm_linked_packages: see `js_info_files` documentation log_level: Set the logging level of the `js_binary` tool. @@ -245,13 +245,13 @@ def js_run_binary( extra_srcs = [] # Hoist js provider files to DefaultInfo - make_js_filegroup_target = (include_transitive_sources or - include_declarations or - include_npm_linked_packages) - if make_js_filegroup_target: - js_filegroup_name = "{}_js_filegroup".format(name) - _js_filegroup( - name = js_filegroup_name, + make_js_info_files_target = (include_transitive_sources or + include_declarations or + include_npm_linked_packages) + if make_js_info_files_target: + js_info_files_name = "{}_js_info_files".format(name) + _js_info_files( + name = js_info_files_name, srcs = srcs, include_transitive_sources = include_transitive_sources, include_declarations = include_declarations, @@ -261,7 +261,7 @@ def js_run_binary( # Always propagate the testonly attribute testonly = kwargs.get("testonly", False), ) - extra_srcs.append(":{}".format(js_filegroup_name)) + extra_srcs.append(":{}".format(js_info_files_name)) # Copy srcs to bin if copy_srcs_to_bin: