Skip to content

Commit

Permalink
refactor: remove unused NpmLinkedPackageInfo provider and correspondi…
Browse files Browse the repository at this point in the history
…ng unused npm_linked_packages from JsInfo; rename load bearing npm_linked_package_files to npm_linked_packages (#1588)
  • Loading branch information
gregmagolan committed Apr 28, 2024
1 parent db30040 commit 5b644ba
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 105 deletions.
4 changes: 2 additions & 2 deletions docs/js_binary.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/js_filegroup.md

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

2 changes: 1 addition & 1 deletion js/private/js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ _ATTRS = {
default = False,
),
"include_npm_linked_packages": attr.bool(
doc = """When True, files in `npm_linked_packages` and `transitive_npm_linked_packages` from `JsInfo` providers in data targets are included in the runfiles of the target.
doc = """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.
""",
Expand Down
2 changes: 1 addition & 1 deletion js/private/js_filegroup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ js_filegroup = rule(
default = False,
),
"include_npm_linked_packages": attr.bool(
doc = """When True, files in `npm_linked_packages` and `transitive_npm_linked_packages` from `JsInfo` providers in srcs targets are included in the default outputs of the target.
doc = """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.
""",
Expand Down
39 changes: 5 additions & 34 deletions js/private/js_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,44 +81,15 @@ def gather_npm_linked_packages(srcs, deps):
deps: dep targets; these typically come from the `deps` attribute of a rule
Returns:
A `struct(direct, direct_files, transitive, transitive_files)` of direct and transitive npm linked packages & underlying files gathered
Depset of npm linked package files
"""

# npm_linked_packages
npm_linked_packages = [
return depset([], transitive = [
target[JsInfo].npm_linked_packages
for target in srcs
if JsInfo in target and hasattr(target[JsInfo], "npm_linked_packages")
]

# npm_linked_package_files
npm_linked_package_files = [
target[JsInfo].npm_linked_package_files
for target in srcs
if JsInfo in target and hasattr(target[JsInfo], "npm_linked_package_files")
]

# transitive_npm_linked_packages
transitive_npm_linked_packages = depset([], transitive = npm_linked_packages + [
target[JsInfo].transitive_npm_linked_packages
for target in srcs + deps
if JsInfo in target and hasattr(target[JsInfo], "transitive_npm_linked_packages")
])

# transitive_npm_linked_package_files
transitive_npm_linked_package_files = depset([], transitive = npm_linked_package_files + [
target[JsInfo].transitive_npm_linked_package_files
for target in srcs + deps
if JsInfo in target and hasattr(target[JsInfo], "transitive_npm_linked_package_files")
if JsInfo in target and hasattr(target[JsInfo], "npm_linked_packages")
])

return struct(
direct = depset([], transitive = npm_linked_packages),
direct_files = depset([], transitive = npm_linked_package_files),
transitive = transitive_npm_linked_packages,
transitive_files = transitive_npm_linked_package_files,
)

def gather_npm_package_store_deps(targets):
"""Gathers NpmPackageStoreInfo providers from the list of targets
Expand Down Expand Up @@ -358,9 +329,9 @@ def gather_files_from_js_providers(
])
if include_npm_linked_packages:
files_depsets.extend([
target[JsInfo].transitive_npm_linked_package_files
target[JsInfo].npm_linked_packages
for target in targets
if JsInfo in target and hasattr(target[JsInfo], "transitive_npm_linked_package_files")
if JsInfo in target and hasattr(target[JsInfo], "npm_linked_packages")
])
files_depsets.extend([
target[NpmPackageStoreInfo].transitive_files
Expand Down
20 changes: 1 addition & 19 deletions js/private/js_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,36 @@ 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_package_files": "A depset of node_modules links and bin files produced by the target",
"npm_linked_packages": "A depset of NpmLinkedPackageInfo providers that are dependencies of 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",
"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_npm_linked_package_files": "A depset of files in npm linked package dependencies of the target and the target's transitive deps",
"transitive_npm_linked_packages": "A depset of NpmLinkedPackageInfo providers that are dependencies of 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(
declarations = depset(),
npm_linked_package_files = depset(),
npm_linked_packages = depset(),
npm_package_store_deps = depset(),
sources = depset(),
transitive_declarations = depset(),
transitive_npm_linked_package_files = depset(),
transitive_npm_linked_packages = depset(),
transitive_sources = depset()):
"""Construct a JsInfo.
Args:
declarations: See JsInfo documentation
npm_linked_package_files: See JsInfo documentation
npm_linked_packages: See JsInfo documentation
npm_package_store_deps: See JsInfo documentation
sources: See JsInfo documentation
transitive_declarations: See JsInfo documentation
transitive_npm_linked_package_files: See JsInfo documentation
transitive_npm_linked_packages: See JsInfo documentation
transitive_sources: See JsInfo documentation
Returns:
A JsInfo provider
"""
if type(declarations) != "depset":
fail("Expected declarations to be a depset")
if type(npm_linked_package_files) != "depset":
fail("Expected npm_linked_package_files 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":
Expand All @@ -53,21 +42,14 @@ def js_info(
fail("Expected sources to be a depset")
if type(transitive_declarations) != "depset":
fail("Expected transitive_declarations to be a depset")
if type(transitive_npm_linked_package_files) != "depset":
fail("Expected transitive_npm_linked_package_files to be a depset")
if type(transitive_npm_linked_packages) != "depset":
fail("Expected transitive_npm_linked_packages to be a depset")
if type(transitive_sources) != "depset":
fail("Expected transitive_sources to be a depset")

return JsInfo(
declarations = declarations,
npm_linked_package_files = npm_linked_package_files,
npm_linked_packages = npm_linked_packages,
npm_package_store_deps = npm_package_store_deps,
sources = sources,
transitive_declarations = transitive_declarations,
transitive_npm_linked_package_files = transitive_npm_linked_package_files,
transitive_npm_linked_packages = transitive_npm_linked_packages,
transitive_sources = transitive_sources,
)
5 changes: 1 addition & 4 deletions js/private/js_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,10 @@ def _js_library_impl(ctx):
return [
js_info(
declarations = declarations,
npm_linked_package_files = npm_linked_packages.direct_files,
npm_linked_packages = npm_linked_packages.direct,
npm_linked_packages = npm_linked_packages,
npm_package_store_deps = npm_package_store_deps,
sources = sources,
transitive_declarations = transitive_declarations,
transitive_npm_linked_package_files = npm_linked_packages.transitive_files,
transitive_npm_linked_packages = npm_linked_packages.transitive,
transitive_sources = transitive_sources,
),
DefaultInfo(
Expand Down
1 change: 0 additions & 1 deletion npm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ bzl_library(
srcs = ["providers.bzl"],
visibility = ["//visibility:public"],
deps = [
"//npm/private:npm_linked_package_info",
"//npm/private:npm_package_info",
"//npm/private:npm_package_store_info",
],
Expand Down
Loading

0 comments on commit 5b644ba

Please sign in to comment.