From 16420b050145c8b4ec6dc146c4e19006c14e098f Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Sun, 7 Apr 2024 12:36:33 -0700 Subject: [PATCH] refactor: rename npm_link_package_deps to npm_deps and npm_package_store_deps to npm_package_store_infos --- BUILD.bazel | 2 +- docs/js_binary.md | 16 ++++----- docs/js_info_files.md | 4 +-- docs/js_library.md | 4 +-- docs/js_run_binary.md | 6 ++-- docs/npm_package.md | 2 +- js/defs.bzl | 14 ++++++++ js/libs.bzl | 8 ++--- js/private/js_binary.bzl | 6 ++-- js/private/js_helpers.bzl | 36 +++++++++---------- js/private/js_info.bzl | 24 ++++++------- js/private/js_info_files.bzl | 6 ++-- js/private/js_library.bzl | 12 +++---- js/private/js_run_binary.bzl | 8 ++--- js/private/js_run_devserver.bzl | 2 +- .../test/create_launcher/custom_test.bzl | 2 +- npm/private/npm_link_package_store.bzl | 4 +-- npm/private/npm_package.bzl | 14 ++++---- npm/private/npm_package_info.bzl | 2 +- npm/private/npm_package_internal.bzl | 2 +- npm/private/npm_package_store.bzl | 16 ++++----- 21 files changed, 102 insertions(+), 88 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 7ae96ef28..d1da4f59d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -65,7 +65,7 @@ diff_test( ) # Example of manually linking a first-party dependency. Its transitive npm dependencies -# are picked up automatically via 'npm_package_store_deps' in the js_library targets that +# are picked up automatically via 'npm_package_store_infos' in the js_library targets that # the `npm_package` target depends on. npm_link_package( name = "node_modules/@mycorp/pkg-b", diff --git a/docs/js_binary.md b/docs/js_binary.md index 25f469659..b5e9da182 100644 --- a/docs/js_binary.md +++ b/docs/js_binary.md @@ -23,9 +23,9 @@ js_binary(
 js_binary(name, chdir, copy_data_to_bin, data, enable_runfiles, entry_point, env,
-          expected_exit_code, fixed_args, include_declarations, include_npm,
-          include_npm_linked_packages, include_transitive_sources, log_level, no_copy_to_bin,
-          node_options, node_toolchain, patch_node_fs, preserve_symlinks_main)
+          expected_exit_code, fixed_args, include_declarations, include_npm, include_npm_deps,
+          include_transitive_sources, log_level, no_copy_to_bin, node_options, node_toolchain,
+          patch_node_fs, preserve_symlinks_main)
 
Execute a program in the Node.js runtime. @@ -78,7 +78,7 @@ The following environment variables are made available to the Node.js runtime ba | fixed_args | Fixed command line arguments to pass to the Node.js when this binary target is executed.

Subject to [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) and ["Make variable"](https://bazel.build/reference/be/make-variables) substitution.

Unlike the built-in args, which are only passed to the target when it is executed either by the bazel run command or as a test, fixed_args are baked into the generated launcher script so are always passed even when the binary target is run outside of Bazel directly from the launcher script.

fixed_args are passed before the ones specified in args and before ones that are specified on the bazel run or bazel test command line.

See https://bazel.build/reference/be/common-definitions#common-attributes-binaries for more info on the built-in args attribute. | List of strings | optional | [] | | include_declarations | When True, declarations and transitive_declarations from JsInfo providers in data targets are included in the runfiles 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 | When True, npm is included in the runfiles of the target.

An npm binary is also added on the PATH so tools can spawn npm processes. This is a bash script on Linux and MacOS and a batch script on Windows.

A minimum of rules_nodejs version 5.7.0 is required which contains the Node.js toolchain changes to use npm. | Boolean | optional | False | -| include_npm_linked_packages | When True, files in npm_linked_packages from JsInfo providers in data targets are included in the runfiles of the target.

transitive_files from NpmPackageStoreInfo providers in data targets are also included in the runfiles of the target. | Boolean | optional | True | +| include_npm_deps | When True, files in npm_deps from JsInfo providers in data targets are included in the runfiles of the target.

transitive_files from NpmPackageStoreInfo providers in data targets are also included in the runfiles of the target. | Boolean | optional | True | | include_transitive_sources | When True, transitive_sources from JsInfo providers in data targets are included in the runfiles of the target. | Boolean | optional | True | | log_level | Set the logging level.

Log from are written to stderr. They will be supressed on success when running as the tool of a js_run_binary when silent_on_success is True. In that case, they will be shown only on a build failure along with the stdout & stderr of the node tool being run.

Log levels: fatal, error, warn, info, debug | String | optional | "error" | | no_copy_to_bin | List of files to not copy to the Bazel output tree when copy_data_to_bin is True.

This is useful for exceptional cases where a copy_to_bin is not possible or not suitable for an input file such as a file in an external repository. In most cases, this option is not needed. See copy_data_to_bin docstring for more info. | List of labels | optional | [] | @@ -94,9 +94,9 @@ The following environment variables are made available to the Node.js runtime ba
 js_test(name, chdir, copy_data_to_bin, data, enable_runfiles, entry_point, env, expected_exit_code,
-        fixed_args, include_declarations, include_npm, include_npm_linked_packages,
-        include_transitive_sources, log_level, no_copy_to_bin, node_options, node_toolchain,
-        patch_node_fs, preserve_symlinks_main)
+        fixed_args, include_declarations, include_npm, include_npm_deps, include_transitive_sources,
+        log_level, no_copy_to_bin, node_options, node_toolchain, patch_node_fs,
+        preserve_symlinks_main)
 
Identical to js_binary, but usable under `bazel test`. @@ -137,7 +137,7 @@ the contract between Bazel and a test runner. | fixed_args | Fixed command line arguments to pass to the Node.js when this binary target is executed.

Subject to [$(location)](https://bazel.build/reference/be/make-variables#predefined_label_variables) and ["Make variable"](https://bazel.build/reference/be/make-variables) substitution.

Unlike the built-in args, which are only passed to the target when it is executed either by the bazel run command or as a test, fixed_args are baked into the generated launcher script so are always passed even when the binary target is run outside of Bazel directly from the launcher script.

fixed_args are passed before the ones specified in args and before ones that are specified on the bazel run or bazel test command line.

See https://bazel.build/reference/be/common-definitions#common-attributes-binaries for more info on the built-in args attribute. | List of strings | optional | [] | | include_declarations | When True, declarations and transitive_declarations from JsInfo providers in data targets are included in the runfiles 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 | When True, npm is included in the runfiles of the target.

An npm binary is also added on the PATH so tools can spawn npm processes. This is a bash script on Linux and MacOS and a batch script on Windows.

A minimum of rules_nodejs version 5.7.0 is required which contains the Node.js toolchain changes to use npm. | Boolean | optional | False | -| include_npm_linked_packages | When True, files in npm_linked_packages from JsInfo providers in data targets are included in the runfiles of the target.

transitive_files from NpmPackageStoreInfo providers in data targets are also included in the runfiles of the target. | Boolean | optional | True | +| include_npm_deps | When True, files in npm_deps from JsInfo providers in data targets are included in the runfiles of the target.

transitive_files from NpmPackageStoreInfo providers in data targets are also included in the runfiles of the target. | Boolean | optional | True | | include_transitive_sources | When True, transitive_sources from JsInfo providers in data targets are included in the runfiles of the target. | Boolean | optional | True | | log_level | Set the logging level.

Log from are written to stderr. They will be supressed on success when running as the tool of a js_run_binary when silent_on_success is True. In that case, they will be shown only on a build failure along with the stdout & stderr of the node tool being run.

Log levels: fatal, error, warn, info, debug | String | optional | "error" | | no_copy_to_bin | List of files to not copy to the Bazel output tree when copy_data_to_bin is True.

This is useful for exceptional cases where a copy_to_bin is not possible or not suitable for an input file such as a file in an external repository. In most cases, this option is not needed. See copy_data_to_bin docstring for more info. | List of labels | optional | [] | diff --git a/docs/js_info_files.md b/docs/js_info_files.md index c5a8e7f4a..c6baf82e6 100644 --- a/docs/js_info_files.md +++ b/docs/js_info_files.md @@ -7,7 +7,7 @@ Helper rule to gather files from JsInfo providers of targets and provide them as ## js_info_files
-js_info_files(name, include_declarations, include_npm_linked_packages, include_sources,
+js_info_files(name, include_declarations, include_npm_deps, include_sources,
               include_transitive_declarations, include_transitive_sources, srcs)
 
@@ -23,7 +23,7 @@ This helper rule is used by the `js_run_binary` macro. | :------------- | :------------- | :------------- | :------------- | :------------- | | 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_npm_deps | When True, files in npm_deps 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 | diff --git a/docs/js_library.md b/docs/js_library.md index 13d09c0fd..94c4c1759 100644 --- a/docs/js_library.md +++ b/docs/js_library.md @@ -55,9 +55,9 @@ for more context on why we do this. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | copy_data_to_bin | When True, data files are copied to the Bazel output tree before being passed as inputs to runfiles. | Boolean | optional | True | -| data | Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the data attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from the npm_package_store_deps field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used. Gathered NpmPackageStoreInfo providers are propagated to the direct dependencies of downstream linked npm_package targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying npm_package_store target(s) through npm_package_store_deps and will therefore not be propagated to the direct dependencies of downstream linked npm_package targets. npm packages that come in from npm_translate_lock are considered "dev" dependencies if they are have dev: true set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all package.json files within the pnpm workspace. This behavior is intentional to mimic how devDependencies work in published npm packages. | List of labels | optional | [] | +| data | Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the data attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from the npm_package_store_infos field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used. Gathered NpmPackageStoreInfo providers are propagated to the direct dependencies of downstream linked npm_package targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying npm_package_store target(s) through npm_package_store_infos and will therefore not be propagated to the direct dependencies of downstream linked npm_package targets. npm packages that come in from npm_translate_lock are considered "dev" dependencies if they are have dev: true set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all package.json files within the pnpm workspace. This behavior is intentional to mimic how devDependencies work in published npm packages. | List of labels | optional | [] | | declarations | Same as srcs except all files are also provided as "declarations" available to downstream rules for type checking.

For example, a js_library with only .js files that are intended to be imported as .js files by downstream type checking rules such as ts_project would list those files in declarations:

 js_library(     name = "js_lib",     declarations = ["index.js"], ) 
| List of labels | optional | [] | -| deps | Dependencies of this target.

This may include other js_library targets or other targets that provide JsInfo

The transitive npm dependencies, transitive sources & runfiles of targets in the deps attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which is output by or has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from the npm_package_store_deps field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used. Gathered NpmPackageStoreInfo providers are propagated to the direct dependencies of downstream linked npm_package targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying npm_package_store target(s) through npm_package_store_deps and will therefore not be propagated to the direct dependencies of downstream linked npm_package targets. npm packages that come in from npm_translate_lock are considered "dev" dependencies if they are have dev: true set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all package.json files within the pnpm workspace. This behavior is intentional to mimic how devDependencies work in published npm packages. | List of labels | optional | [] | +| deps | Dependencies of this target.

This may include other js_library targets or other targets that provide JsInfo

The transitive npm dependencies, transitive sources & runfiles of targets in the deps attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which is output by or has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from the npm_package_store_infos field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used. Gathered NpmPackageStoreInfo providers are propagated to the direct dependencies of downstream linked npm_package targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying npm_package_store target(s) through npm_package_store_infos and will therefore not be propagated to the direct dependencies of downstream linked npm_package targets. npm packages that come in from npm_translate_lock are considered "dev" dependencies if they are have dev: true set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all package.json files within the pnpm workspace. This behavior is intentional to mimic how devDependencies work in published npm packages. | List of labels | optional | [] | | no_copy_to_bin | List of files to not copy to the Bazel output tree when copy_data_to_bin is True.

This is useful for exceptional cases where a copy_to_bin is not possible or not suitable for an input file such as a file in an external repository. In most cases, this option is not needed. See copy_data_to_bin docstring for more info. | List of labels | optional | [] | | srcs | Source files that are included in this library.

This includes all your checked-in code and any generated source files.

The transitive npm dependencies, transitive sources & runfiles of targets in the srcs attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which is output by or has a runtime dependency on this target.

Source files that are JSON files, declaration files or directory artifacts will be automatically provided as "declarations" available to downstream rules for type checking. To explicitly provide source files as "declarations" available to downstream rules for type checking that do not match these criteria, move those files to the declarations attribute instead. | List of labels | optional | [] | diff --git a/docs/js_run_binary.md b/docs/js_run_binary.md index 7b62a5a03..762efa384 100644 --- a/docs/js_run_binary.md +++ b/docs/js_run_binary.md @@ -19,8 +19,8 @@ load("@aspect_rules_js//js:defs.bzl", "js_run_binary")
 js_run_binary(name, tool, env, srcs, outs, out_dirs, args, chdir, stdout, stderr, exit_code_out,
               silent_on_success, use_execroot_entry_point, copy_srcs_to_bin,
-              include_transitive_sources, include_declarations, include_npm_linked_packages,
-              log_level, mnemonic, progress_message, execution_requirements, stamp, patch_node_fs,
+              include_transitive_sources, include_declarations, include_npm_deps, log_level, mnemonic,
+              progress_message, execution_requirements, stamp, patch_node_fs,
               allow_execroot_entry_point_with_no_copy_data_to_bin, use_default_shell_env, kwargs)
 
@@ -64,7 +64,7 @@ The following environment variables are made available to the Node.js runtime ba | 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_info_files documentation | True | | include_declarations | see js_info_files documentation | False | -| include_npm_linked_packages | see js_info_files documentation | True | +| include_npm_deps | 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/docs/npm_package.md b/docs/npm_package.md index 7f536f9cd..ecd42c4d9 100644 --- a/docs/npm_package.md +++ b/docs/npm_package.md @@ -90,7 +90,7 @@ To stamp the current git tag as the "version" in the package.json file, see | :------------- | :------------- | :------------- | | name | Unique name for this target. | none | | srcs | Files and/or directories or targets that provide DirectoryPathInfo to copy into the output directory. | [] | -| data | Runtime / linktime npm dependencies of this npm package.

NpmPackageStoreInfo providers are gathered from JsInfo of the targets specified. Targets can be linked npm packages, npm package store targets or other targets that provide JsInfo. This is done directly from the npm_package_store_deps field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used.

Gathered NpmPackageStoreInfo providers are used downstream as direct dependencies of this npm package when linking with npm_link_package. | [] | +| data | Runtime / linktime npm dependencies of this npm package.

NpmPackageStoreInfo providers are gathered from JsInfo of the targets specified. Targets can be linked npm packages, npm package store targets or other targets that provide JsInfo. This is done directly from the npm_package_store_infos field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used.

Gathered NpmPackageStoreInfo providers are used downstream as direct dependencies of this npm package when linking with npm_link_package. | [] | | args | Arguments that are passed down to <name>.publish target and npm publish command. | [] | | out | Path of the output directory, relative to this package. | None | | package | The package name. If set, should match the name field in the package.json file for this package.

If set, the package name set here will be used for linking if a npm_link_package does not specify a package name. A npm_link_package that specifies a package name will override the value here when linking.

If unset, a npm_link_package that references this npm_package must define the package name must be for linking. | "" | diff --git a/js/defs.bzl b/js/defs.bzl index 623a4b999..cbc7e4706 100644 --- a/js/defs.bzl +++ b/js/defs.bzl @@ -26,8 +26,21 @@ load( _js_image_layer = "js_image_layer", ) +# buildifier: disable=function-docstring def js_binary(**kwargs): + include_npm_deps = kwargs.pop("include_npm_deps", False) + + # For backward compat + # TODO(3.0): remove backward compat handling + include_npm_linked_packages = kwargs.pop("include_npm_linked_packages", None) + if include_npm_linked_packages != None: + # buildifier: disable=print + print(""" +WARNING: js_library 'include_npm_linked_packages' is deprecated. Use 'include_npm_deps' instead.""") + include_npm_deps = include_npm_linked_packages + _js_binary( + include_npm_deps = include_npm_deps, enable_runfiles = select({ Label("@aspect_bazel_lib//lib:enable_runfiles"): True, "//conditions:default": False, @@ -35,6 +48,7 @@ def js_binary(**kwargs): **kwargs ) +# buildifier: disable=function-docstring def js_test(**kwargs): _js_test( enable_runfiles = select({ diff --git a/js/libs.bzl b/js/libs.bzl index 4aeba4468..eedea36b2 100644 --- a/js/libs.bzl +++ b/js/libs.bzl @@ -15,8 +15,8 @@ load( _LOG_LEVELS = "LOG_LEVELS", _envs_for_log_level = "envs_for_log_level", _gather_files_from_js_info = "gather_files_from_js_info", - _gather_npm_linked_packages = "gather_npm_linked_packages", - _gather_npm_package_store_deps = "gather_npm_package_store_deps", + _gather_npm_deps = "gather_npm_deps", + _gather_npm_package_store_infos = "gather_npm_package_store_infos", _gather_runfiles = "gather_runfiles", _gather_transitive_declarations = "gather_transitive_declarations", _gather_transitive_sources = "gather_transitive_sources", @@ -28,8 +28,8 @@ js_library_lib = _js_library_lib js_lib_helpers = struct( envs_for_log_level = _envs_for_log_level, gather_files_from_js_info = _gather_files_from_js_info, - gather_npm_linked_packages = _gather_npm_linked_packages, - gather_npm_package_store_deps = _gather_npm_package_store_deps, + gather_npm_deps = _gather_npm_deps, + gather_npm_package_store_infos = _gather_npm_package_store_infos, gather_runfiles = _gather_runfiles, gather_transitive_declarations = _gather_transitive_declarations, gather_transitive_sources = _gather_transitive_sources, diff --git a/js/private/js_binary.bzl b/js/private/js_binary.bzl index 365db6fcc..fa5c2e25d 100644 --- a/js/private/js_binary.bzl +++ b/js/private/js_binary.bzl @@ -198,8 +198,8 @@ _ATTRS = { time due to having to generate typings on source file changes.""", default = False, ), - "include_npm_linked_packages": attr.bool( - doc = """When True, files in `npm_linked_packages` from `JsInfo` providers in data targets are included in the runfiles of the target. + "include_npm_deps": attr.bool( + doc = """When True, files in `npm_deps` from `JsInfo` providers in data targets are included in the runfiles of the target. `transitive_files` from `NpmPackageStoreInfo` providers in data targets are also included in the runfiles of the target. """, @@ -517,7 +517,7 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [], no_copy_to_bin = ctx.files.no_copy_to_bin, include_transitive_sources = ctx.attr.include_transitive_sources, include_declarations = ctx.attr.include_declarations, - include_npm_linked_packages = ctx.attr.include_npm_linked_packages, + include_npm_deps = ctx.attr.include_npm_deps, ).merge(ctx.runfiles( files = launcher_files, transitive_files = transitive_launcher_files, diff --git a/js/private/js_helpers.bzl b/js/private/js_helpers.bzl index 45a789aeb..3693af93a 100644 --- a/js/private/js_helpers.bzl +++ b/js/private/js_helpers.bzl @@ -7,12 +7,12 @@ load(":js_info.bzl", "JsInfo") DOWNSTREAM_LINKED_NPM_DEPS_DOCSTRING = """If this list contains linked npm packages, npm package store targets or other targets that provide `JsInfo`, `NpmPackageStoreInfo` providers are gathered from `JsInfo`. This is done directly from -the `npm_package_store_deps` field of these. For linked npm package targets, the underlying +the `npm_package_store_infos` field of these. For linked npm package targets, the underlying `npm_package_store` target(s) that back the links is used. Gathered `NpmPackageStoreInfo` providers are propagated to the direct dependencies of downstream linked `npm_package` targets. NB: Linked npm package targets that are "dev" dependencies do not forward their underlying -`npm_package_store` target(s) through `npm_package_store_deps` and will therefore not be +`npm_package_store` target(s) through `npm_package_store_infos` and will therefore not be propagated to the direct dependencies of downstream linked `npm_package` targets. npm packages that come in from `npm_translate_lock` are considered "dev" dependencies if they are have `dev: true` set in the pnpm lock file. This should be all packages that are only listed as @@ -73,7 +73,7 @@ def gather_transitive_declarations(declarations, targets): ] return depset([], transitive = [declarations] + transitive) -def gather_npm_linked_packages(srcs, deps): +def gather_npm_deps(srcs, deps): """Gathers npm linked packages from a list of srcs and deps targets Args: @@ -85,12 +85,12 @@ def gather_npm_linked_packages(srcs, deps): """ return depset([], transitive = [ - target[JsInfo].npm_linked_packages + target[JsInfo].npm_deps for target in srcs + deps - if JsInfo in target and hasattr(target[JsInfo], "npm_linked_packages") + if JsInfo in target and hasattr(target[JsInfo], "npm_deps") ]) -def gather_npm_package_store_deps(targets): +def gather_npm_package_store_infos(targets): """Gathers NpmPackageStoreInfo providers from the list of targets Args: @@ -100,14 +100,14 @@ def gather_npm_package_store_deps(targets): A depset of npm package stores gathered """ - # npm_package_store_deps - npm_package_store_deps = [ - target[JsInfo].npm_package_store_deps + # npm_package_store_infos + npm_package_store_infos = [ + target[JsInfo].npm_package_store_infos for target in targets if JsInfo in target ] - return depset([], transitive = npm_package_store_deps) + return depset([], transitive = npm_package_store_infos) def copy_js_file_to_bin_action(ctx, file): if ctx.label.workspace_name != file.owner.workspace_name or ctx.label.package != file.owner.package: @@ -157,7 +157,7 @@ def gather_runfiles( include_transitive_sources = True, include_declarations = False, include_transitive_declarations = False, - include_npm_linked_packages = True): + include_npm_deps = True): """Creates a runfiles object containing files in `sources`, default outputs from `data` and transitive runfiles from `data` & `deps`. As a defense in depth against `data` & `deps` targets not supplying all required runfiles, also @@ -201,7 +201,7 @@ def gather_runfiles( include_transitive_declarations: see js_info_files documentation - include_npm_linked_packages: see js_info_files documentation + include_npm_deps: 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). @@ -225,7 +225,7 @@ def gather_runfiles( include_transitive_sources = include_transitive_sources, include_declarations = include_declarations, include_transitive_declarations = include_transitive_declarations, - include_npm_linked_packages = include_npm_linked_packages, + include_npm_deps = include_npm_deps, )) files_runfiles = [] @@ -288,7 +288,7 @@ def gather_files_from_js_info( include_transitive_sources, include_declarations, include_transitive_declarations, - include_npm_linked_packages): + include_npm_deps): """Gathers files from JsInfo and NpmPackageStoreInfo providers. Args: @@ -297,7 +297,7 @@ def gather_files_from_js_info( 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 + include_npm_deps: see js_info_files documentation Returns: A depset of files @@ -327,11 +327,11 @@ def gather_files_from_js_info( for target in targets if JsInfo in target and hasattr(target[JsInfo], "transitive_declarations") ]) - if include_npm_linked_packages: + if include_npm_deps: files_depsets.extend([ - target[JsInfo].npm_linked_packages + target[JsInfo].npm_deps for target in targets - if JsInfo in target and hasattr(target[JsInfo], "npm_linked_packages") + if JsInfo in target and hasattr(target[JsInfo], "npm_deps") ]) files_depsets.extend([ target[NpmPackageStoreInfo].transitive_files diff --git a/js/private/js_info.bzl b/js/private/js_info.bzl index 38f67f044..c893ae086 100644 --- a/js/private/js_info.bzl +++ b/js/private/js_info.bzl @@ -4,8 +4,8 @@ JsInfo = provider( doc = "Encapsulates information provided by rules in rules_js and derivative rule sets", fields = { "declarations": "A depset of declaration files produced by the target", - "npm_linked_packages": "A depset of files in npm linked package dependencies of the target and the target's transitive deps", - "npm_package_store_deps": "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", + "npm_deps": "A depset of files in npm 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_declarations": "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", @@ -14,8 +14,8 @@ JsInfo = provider( def js_info( declarations = depset(), - npm_linked_packages = depset(), - npm_package_store_deps = depset(), + npm_deps = depset(), + npm_package_store_infos = depset(), sources = depset(), transitive_declarations = depset(), transitive_sources = depset()): @@ -23,8 +23,8 @@ def js_info( Args: declarations: See JsInfo documentation - npm_linked_packages: See JsInfo documentation - npm_package_store_deps: See JsInfo documentation + npm_deps: See JsInfo documentation + npm_package_store_infos: See JsInfo documentation sources: See JsInfo documentation transitive_declarations: See JsInfo documentation transitive_sources: See JsInfo documentation @@ -34,10 +34,10 @@ def js_info( """ if type(declarations) != "depset": fail("Expected declarations to be a depset") - if type(npm_linked_packages) != "depset": - fail("Expected npm_linked_packages to be a depset") - if type(npm_package_store_deps) != "depset": - fail("Expected npm_package_store_deps to be a depset") + if type(npm_deps) != "depset": + fail("Expected npm_deps to be a depset") + 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_declarations) != "depset": @@ -47,8 +47,8 @@ def js_info( return JsInfo( declarations = declarations, - npm_linked_packages = npm_linked_packages, - npm_package_store_deps = npm_package_store_deps, + npm_deps = npm_deps, + npm_package_store_infos = npm_package_store_infos, sources = sources, transitive_declarations = transitive_declarations, transitive_sources = transitive_sources, diff --git a/js/private/js_info_files.bzl b/js/private/js_info_files.bzl index 7ddf4be89..a1561fc8f 100644 --- a/js/private/js_info_files.bzl +++ b/js/private/js_info_files.bzl @@ -14,7 +14,7 @@ def _js_info_files_impl(ctx): include_transitive_sources = ctx.attr.include_transitive_sources, include_declarations = ctx.attr.include_declarations, include_transitive_declarations = ctx.attr.include_transitive_declarations, - include_npm_linked_packages = ctx.attr.include_npm_linked_packages, + include_npm_deps = ctx.attr.include_npm_deps, )) js_info_files = rule( @@ -47,8 +47,8 @@ js_info_files = rule( time due to having to generate typings on source file changes.""", default = False, ), - "include_npm_linked_packages": attr.bool( - doc = """When True, files in `npm_linked_packages` from `JsInfo` providers in srcs targets are included in the default outputs of the target. + "include_npm_deps": attr.bool( + doc = """When True, files in `npm_deps` 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. """, diff --git a/js/private/js_library.bzl b/js/private/js_library.bzl index 35f51aa42..fde430278 100644 --- a/js/private/js_library.bzl +++ b/js/private/js_library.bzl @@ -24,7 +24,7 @@ js_library( """ load(":js_info.bzl", "JsInfo", "js_info") -load(":js_helpers.bzl", "DOWNSTREAM_LINKED_NPM_DEPS_DOCSTRING", "JS_LIBRARY_DATA_ATTR", "copy_js_file_to_bin_action", "gather_npm_linked_packages", "gather_npm_package_store_deps", "gather_runfiles", "gather_transitive_declarations", "gather_transitive_sources") +load(":js_helpers.bzl", "DOWNSTREAM_LINKED_NPM_DEPS_DOCSTRING", "JS_LIBRARY_DATA_ATTR", "copy_js_file_to_bin_action", "gather_npm_deps", "gather_npm_package_store_infos", "gather_runfiles", "gather_transitive_declarations", "gather_transitive_sources") load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "COPY_FILE_TO_BIN_TOOLCHAINS") _DOC = """A library of JavaScript sources. Provides JsInfo, the primary provider used in rules_js @@ -190,12 +190,12 @@ def _js_library_impl(ctx): targets = ctx.attr.srcs + ctx.attr.declarations + ctx.attr.deps, ) - npm_linked_packages = gather_npm_linked_packages( + npm_deps = gather_npm_deps( srcs = ctx.attr.srcs + ctx.attr.declarations, deps = ctx.attr.deps, ) - npm_package_store_deps = gather_npm_package_store_deps( + npm_package_store_infos = gather_npm_package_store_infos( targets = ctx.attr.data + ctx.attr.deps, ) @@ -209,14 +209,14 @@ def _js_library_impl(ctx): no_copy_to_bin = ctx.files.no_copy_to_bin, include_transitive_sources = True, include_declarations = False, - include_npm_linked_packages = True, + include_npm_deps = True, ) return [ js_info( declarations = declarations, - npm_linked_packages = npm_linked_packages, - npm_package_store_deps = npm_package_store_deps, + npm_deps = npm_deps, + npm_package_store_infos = npm_package_store_infos, sources = sources, transitive_declarations = transitive_declarations, transitive_sources = transitive_sources, diff --git a/js/private/js_run_binary.bzl b/js/private/js_run_binary.bzl index 35811cb09..13161c48b 100644 --- a/js/private/js_run_binary.bzl +++ b/js/private/js_run_binary.bzl @@ -35,7 +35,7 @@ def js_run_binary( copy_srcs_to_bin = True, include_transitive_sources = True, include_declarations = False, - include_npm_linked_packages = True, + include_npm_deps = True, log_level = None, mnemonic = "JsRunBinary", progress_message = None, @@ -154,7 +154,7 @@ def js_run_binary( include_declarations: see `js_info_files` documentation - include_npm_linked_packages: see `js_info_files` documentation + include_npm_deps: see `js_info_files` documentation log_level: Set the logging level of the `js_binary` tool. @@ -247,7 +247,7 @@ def js_run_binary( # Hoist js provider files to DefaultInfo make_js_info_files_target = (include_transitive_sources or include_declarations or - include_npm_linked_packages) + include_npm_deps) if make_js_info_files_target: js_info_files_name = "{}_js_info_files".format(name) _js_info_files( @@ -255,7 +255,7 @@ def js_run_binary( srcs = srcs, include_transitive_sources = include_transitive_sources, include_declarations = include_declarations, - include_npm_linked_packages = include_npm_linked_packages, + include_npm_deps = include_npm_deps, # Always tag the target manual since we should only build it when the final target is built. tags = kwargs.get("tags", []) + ["manual"], # Always propagate the testonly attribute diff --git a/js/private/js_run_devserver.bzl b/js/private/js_run_devserver.bzl index 904a52f66..9e5b22625 100644 --- a/js/private/js_run_devserver.bzl +++ b/js/private/js_run_devserver.bzl @@ -46,7 +46,7 @@ def _js_run_devserver_impl(ctx): include_transitive_sources = ctx.attr.include_transitive_sources, include_declarations = ctx.attr.include_declarations, include_transitive_declarations = ctx.attr.include_declarations, - include_npm_linked_packages = ctx.attr.include_npm_linked_packages, + include_npm_deps = ctx.attr.include_npm_deps, )] # The .to_list() calls here are intentional and cannot be avoided; they should be small sets of diff --git a/js/private/test/create_launcher/custom_test.bzl b/js/private/test/create_launcher/custom_test.bzl index 62d26b1f6..dc9683e03 100644 --- a/js/private/test/create_launcher/custom_test.bzl +++ b/js/private/test/create_launcher/custom_test.bzl @@ -25,7 +25,7 @@ def _custom_test_impl(ctx): include_transitive_sources = ctx.attr.include_transitive_sources, include_declarations = ctx.attr.include_declarations, include_transitive_declarations = ctx.attr.include_declarations, - include_npm_linked_packages = ctx.attr.include_npm_linked_packages, + include_npm_deps = ctx.attr.include_npm_deps, ), ).merge(launcher.runfiles).merge_all([ target[DefaultInfo].default_runfiles diff --git a/npm/private/npm_link_package_store.bzl b/npm/private/npm_link_package_store.bzl index 70fa03d84..8ecfe8ea3 100644 --- a/npm/private/npm_link_package_store.bzl +++ b/npm/private/npm_link_package_store.bzl @@ -105,9 +105,9 @@ def _npm_link_package_store_impl(ctx): runfiles = ctx.runfiles(transitive_files = transitive_files_depset), ), js_info( - npm_linked_packages = transitive_files_depset, + npm_deps = 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_deps = depset([store_info]) if not store_info.dev else depset(), + npm_package_store_infos = depset([store_info]) if not store_info.dev else depset(), ), ] if OutputGroupInfo in ctx.attr.src: diff --git a/npm/private/npm_package.bzl b/npm/private/npm_package.bzl index 0478be7c3..931230b7d 100644 --- a/npm/private/npm_package.bzl +++ b/npm/private/npm_package.bzl @@ -89,13 +89,13 @@ def _npm_package_files_impl(ctx): def _npm_package_impl(ctx): dst = ctx.actions.declare_directory(ctx.attr.out if ctx.attr.out else ctx.attr.name) - # forward all npm_package_store_deps - npm_package_store_deps = [ - target[JsInfo].npm_package_store_deps + # forward all npm_package_store_infos + npm_package_store_infos = [ + target[JsInfo].npm_package_store_infos for target in ctx.attr.srcs - if JsInfo in target and hasattr(target[JsInfo], "npm_package_store_deps") + if JsInfo in target and hasattr(target[JsInfo], "npm_package_store_infos") ] - npm_package_store_deps.append(js_lib_helpers.gather_npm_package_store_deps( + npm_package_store_infos.append(js_lib_helpers.gather_npm_package_store_infos( targets = ctx.attr.data, )) @@ -129,7 +129,7 @@ def _npm_package_impl(ctx): package = ctx.attr.package, version = ctx.attr.version, src = dst, - npm_package_store_deps = depset([], transitive = npm_package_store_deps), + npm_package_store_infos = depset([], transitive = npm_package_store_infos), ), ] @@ -246,7 +246,7 @@ def npm_package( `NpmPackageStoreInfo` providers are gathered from `JsInfo` of the targets specified. Targets can be linked npm packages, npm package store targets or other targets that provide `JsInfo`. This is done directly from the - `npm_package_store_deps` field of these. For linked npm package targets, the underlying npm_package_store + `npm_package_store_infos` field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used. Gathered `NpmPackageStoreInfo` providers are used downstream as direct dependencies of this npm package when diff --git a/npm/private/npm_package_info.bzl b/npm/private/npm_package_info.bzl index e2550daf7..7b2d799f1 100644 --- a/npm/private/npm_package_info.bzl +++ b/npm/private/npm_package_info.bzl @@ -6,6 +6,6 @@ NpmPackageInfo = provider( "package": "name of this npm package", "version": "version of this npm package", "src": "the sources of this npm package; either a tarball file, a TreeArtifact or a source directory", - "npm_package_store_deps": "A depset of NpmPackageStoreInfo providers from npm dependencies of the package and the packages's transitive deps to use as direct dependencies when linking with npm_link_package", + "npm_package_store_infos": "A depset of NpmPackageStoreInfo providers from npm dependencies of the package and the packages's transitive deps to use as direct dependencies when linking with npm_link_package", }, ) diff --git a/npm/private/npm_package_internal.bzl b/npm/private/npm_package_internal.bzl index 0980debfc..30ab50900 100644 --- a/npm/private/npm_package_internal.bzl +++ b/npm/private/npm_package_internal.bzl @@ -33,7 +33,7 @@ def _npm_package_internal_impl(ctx): package = ctx.attr.package, version = ctx.attr.version, src = dst, - npm_package_store_deps = depset(), + npm_package_store_infos = depset(), ), ] diff --git a/npm/private/npm_package_store.bzl b/npm/private/npm_package_store.bzl index 582361312..cb8e5e08c 100644 --- a/npm/private/npm_package_store.bzl +++ b/npm/private/npm_package_store.bzl @@ -165,7 +165,7 @@ def _npm_package_store_impl(ctx): files = [] direct_ref_deps = {} - npm_package_store_deps = [] + npm_package_store_infos = [] if ctx.attr.src: # output the package as a TreeArtifact to its package store location @@ -242,7 +242,7 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package, # party npm deps; it is not recommended for 1st party deps direct_ref_deps[dep] = dep_aliases - for store in ctx.attr.src[NpmPackageInfo].npm_package_store_deps.to_list(): + for store in ctx.attr.src[NpmPackageInfo].npm_package_store_infos.to_list(): dep_package = store.package dep_package_store_directory = store.package_store_directory @@ -252,7 +252,7 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package, # "node_modules/{package_store_root}/{package_store_name}/node_modules/{package}" dep_symlink_path = paths.join("node_modules", utils.package_store_root, package_store_name, "node_modules", dep_package) files.append(utils.make_symlink(ctx, dep_symlink_path, dep_package_store_directory)) - npm_package_store_deps.append(store) + npm_package_store_infos.append(store) else: # if ctx.attr.src is _not_ set then this is a terminal 3p package with ctx.attr.deps is # being the transitive closure of deps; this pattern is used to break circular dependencies @@ -295,7 +295,7 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package, if package_store_directory: files.append(package_store_directory) - npm_package_store_deps.extend([ + npm_package_store_infos.extend([ target[NpmPackageStoreInfo] for target in ctx.attr.deps ]) @@ -305,19 +305,19 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package, if ctx.attr.src: transitive_files_depset = depset(files, transitive = [ npm_package_store.transitive_files - for npm_package_store in npm_package_store_deps + for npm_package_store in npm_package_store_infos ]) else: # if ctx.attr.src is _not_ set then this is a terminal 3p package with ctx.attr.deps is # being the transitive closure of deps; this pattern is used to break circular dependencies # between 3rd party npm deps; it is not recommended for 1st party deps because - # npm_package_store_deps is the transitive closure of all the entire package store deps, we - # can safely add just `files` from each of these to `transitive_files_depset`. Doing so + # npm_package_store_infos is the transitive closure of the all NpmPackageStoreInfos in deps, + # we can safely add just `files` from each of these to `transitive_files_depset`. Doing so # reduces the size of `transitive_files_depset` significantly and reduces analysis time and # Bazel memory usage during analysis transitive_files_depset = depset(files, transitive = [ npm_package_store.files - for npm_package_store in npm_package_store_deps + for npm_package_store in npm_package_store_infos ]) providers = [