Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename directory attribute of NpmPackageInfo to src #1575

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion npm/private/npm_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _npm_package_impl(ctx):
NpmPackageInfo(
package = ctx.attr.package,
version = ctx.attr.version,
directory = dst,
src = dst,
npm_package_store_deps = depset([], transitive = npm_package_store_deps),
),
]
Expand Down
4 changes: 2 additions & 2 deletions npm/private/npm_package_info.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"NpmPackageInfo provider"

NpmPackageInfo = provider(
doc = "Provides the output directory (TreeArtifact) of an npm package containing the packages sources along with the package name and version",
doc = "Provides the sources of an npm package along with the package name and version",
fields = {
"package": "name of this npm package",
"version": "version of this npm package",
"directory": "the directory (typically a TreeArtifact) that contains the package sources",
"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",
},
)
3 changes: 1 addition & 2 deletions npm/private/npm_package_internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def _npm_package_internal_impl(ctx):
NpmPackageInfo(
package = ctx.attr.package,
version = ctx.attr.version,
# TODO(2.0): rename `directory` to `src` since it may now be an archive file
directory = dst,
src = dst,
npm_package_store_deps = depset(),
),
]
Expand Down
16 changes: 8 additions & 8 deletions npm/private/npm_package_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _npm_package_store_impl(ctx):

virtual_store_name = utils.virtual_store_name(package, version)

src_directory = None
src = None
virtual_store_directory = None
transitive_files = []
direct_ref_deps = {}
Expand All @@ -188,14 +188,14 @@ def _npm_package_store_impl(ctx):
expected_short_path = paths.join("..", ctx.label.workspace_name, ctx.label.package, virtual_store_directory_path)
else:
expected_short_path = paths.join(ctx.label.package, virtual_store_directory_path)
src_directory = ctx.attr.src[NpmPackageInfo].directory
if src_directory.short_path == expected_short_path:
src = ctx.attr.src[NpmPackageInfo].src
if src.short_path == expected_short_path:
# the input is already the desired output; this is the pattern for
# packages with lifecycle hooks
virtual_store_directory = src_directory
virtual_store_directory = src
else:
virtual_store_directory = ctx.actions.declare_directory(virtual_store_directory_path)
if utils.is_tarball_extension(src_directory.extension):
if utils.is_tarball_extension(src.extension):
# npm packages are always published with one top-level directory inside the tarball, tho the name is not predictable
# we can use the --strip-components 1 argument with tar to strip one directory level
args = ctx.actions.args()
Expand All @@ -205,14 +205,14 @@ def _npm_package_store_impl(ctx):
args.add("--strip-components")
args.add(str(1))
args.add("--file")
args.add(src_directory.path)
args.add(src.path)
args.add("--directory")
args.add(virtual_store_directory.path)

bsdtar = ctx.toolchains["@aspect_bazel_lib//lib:tar_toolchain_type"]
ctx.actions.run(
executable = bsdtar.tarinfo.binary,
inputs = depset(direct = [src_directory], transitive = [bsdtar.default.files]),
inputs = depset(direct = [src], transitive = [bsdtar.default.files]),
outputs = [virtual_store_directory],
arguments = [args],
mnemonic = "NpmPackageExtract",
Expand All @@ -221,7 +221,7 @@ def _npm_package_store_impl(ctx):
else:
copy_directory_bin_action(
ctx,
src = src_directory,
src = src,
dst = virtual_store_directory,
copy_directory_bin = ctx.toolchains["@aspect_bazel_lib//lib:copy_directory_toolchain_type"].copy_directory_info.bin,
# Hardlinking source files in external repositories as was done under the hood
Expand Down