Skip to content

Commit

Permalink
refactor: rename JsInfo npm_package_store_deps to npm_package_store_i…
Browse files Browse the repository at this point in the history
…nfos (#1620)
  • Loading branch information
gregmagolan committed May 10, 2024
1 parent 25b1976 commit ae60be0
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions docs/js_library.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/npm_package.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/libs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load(
_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_package_store_infos = "gather_npm_package_store_infos",
_gather_runfiles = "gather_runfiles",
_gather_transitive_declarations = "gather_transitive_declarations",
_gather_transitive_sources = "gather_transitive_sources",
Expand All @@ -29,7 +29,7 @@ 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_package_store_infos = _gather_npm_package_store_infos,
gather_runfiles = _gather_runfiles,
gather_transitive_declarations = _gather_transitive_declarations,
gather_transitive_sources = _gather_transitive_sources,
Expand Down
14 changes: 7 additions & 7 deletions js/private/js_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +90,7 @@ def gather_npm_linked_packages(srcs, deps):
if JsInfo in target and hasattr(target[JsInfo], "npm_linked_packages")
])

def gather_npm_package_store_deps(targets):
def gather_npm_package_store_infos(targets):
"""Gathers NpmPackageStoreInfo providers from the list of targets
Args:
Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions js/private/js_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ JsInfo = provider(
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_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",
Expand All @@ -15,7 +15,7 @@ JsInfo = provider(
def js_info(
declarations = depset(),
npm_linked_packages = depset(),
npm_package_store_deps = depset(),
npm_package_store_infos = depset(),
sources = depset(),
transitive_declarations = depset(),
transitive_sources = depset()):
Expand All @@ -24,7 +24,7 @@ def js_info(
Args:
declarations: See JsInfo documentation
npm_linked_packages: See JsInfo documentation
npm_package_store_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
Expand All @@ -36,8 +36,8 @@ def js_info(
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_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":
Expand All @@ -48,7 +48,7 @@ def js_info(
return JsInfo(
declarations = declarations,
npm_linked_packages = npm_linked_packages,
npm_package_store_deps = npm_package_store_deps,
npm_package_store_infos = npm_package_store_infos,
sources = sources,
transitive_declarations = transitive_declarations,
transitive_sources = transitive_sources,
Expand Down
6 changes: 3 additions & 3 deletions js/private/js_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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_linked_packages", "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
Expand Down Expand Up @@ -195,7 +195,7 @@ def _js_library_impl(ctx):
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.srcs + ctx.attr.data + ctx.attr.deps,
)

Expand All @@ -216,7 +216,7 @@ def _js_library_impl(ctx):
js_info(
declarations = declarations,
npm_linked_packages = npm_linked_packages,
npm_package_store_deps = npm_package_store_deps,
npm_package_store_infos = npm_package_store_infos,
sources = sources,
transitive_declarations = transitive_declarations,
transitive_sources = transitive_sources,
Expand Down
Loading

0 comments on commit ae60be0

Please sign in to comment.