From 66f45c14be80e779d643ce4d83811ff9eb84fca5 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Tue, 2 Apr 2024 19:36:26 -0400 Subject: [PATCH] refactor: rename directory attribute of NpmPackageInfo to src (#1575) --- npm/private/npm_package.bzl | 2 +- npm/private/npm_package_info.bzl | 4 ++-- npm/private/npm_package_internal.bzl | 3 +-- npm/private/npm_package_store.bzl | 16 ++++++++-------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/npm/private/npm_package.bzl b/npm/private/npm_package.bzl index a65a94674..0478be7c3 100644 --- a/npm/private/npm_package.bzl +++ b/npm/private/npm_package.bzl @@ -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), ), ] diff --git a/npm/private/npm_package_info.bzl b/npm/private/npm_package_info.bzl index 9e9798c7c..e2550daf7 100644 --- a/npm/private/npm_package_info.bzl +++ b/npm/private/npm_package_info.bzl @@ -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", }, ) diff --git a/npm/private/npm_package_internal.bzl b/npm/private/npm_package_internal.bzl index 2407e1a89..0980debfc 100644 --- a/npm/private/npm_package_internal.bzl +++ b/npm/private/npm_package_internal.bzl @@ -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(), ), ] diff --git a/npm/private/npm_package_store.bzl b/npm/private/npm_package_store.bzl index d134a82ee..486efc0d6 100644 --- a/npm/private/npm_package_store.bzl +++ b/npm/private/npm_package_store.bzl @@ -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 = {} @@ -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() @@ -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", @@ -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