wip: show how to create rules_license PackageInfo
diff --git a/MODULE.bazel b/MODULE.bazel
index b94a1a7..b7d590b 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -13,6 +13,7 @@
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "rules_nodejs", version = "5.8.2")
bazel_dep(name = "platforms", version = "0.0.5")
+bazel_dep(name = "rules_license", version = "0.0.7")
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
use_repo(node, "nodejs_linux_amd64")
diff --git a/npm/private/npm_import.bzl b/npm/private/npm_import.bzl
index 2247a99..7a7b3ee 100644
--- a/npm/private/npm_import.bzl
+++ b/npm/private/npm_import.bzl
@@ -351,6 +351,7 @@
src = ":{extract_to_dirname}",
package = "{package}",
version = "{version}",
+ license = "{license}",
visibility = ["//visibility:public"],
)
@@ -359,6 +360,7 @@
src = ":{extract_to_dirname}",
package = "{package}",
version = "{version}",
+ license = "{license}",
visibility = ["//visibility:public"],
)
"""
@@ -522,6 +524,7 @@
extract_to_dirname = _EXTRACT_TO_DIRNAME,
package = rctx.attr.package,
version = rctx.attr.version,
+ license = pkg_json["license"],
))
if rctx.attr.extra_build_content:
diff --git a/npm/private/npm_package_info.bzl b/npm/private/npm_package_info.bzl
index 20583ed..985118a 100644
--- a/npm/private/npm_package_info.bzl
+++ b/npm/private/npm_package_info.bzl
@@ -8,5 +8,6 @@
"directory": "the directory (typically a TreeArtifact) that contains the package sources",
"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",
"hardlink": "internal use only",
+ "license": "TODO",
},
)
diff --git a/npm/private/npm_package_internal.bzl b/npm/private/npm_package_internal.bzl
index f4120e9..ee8cca4 100644
--- a/npm/private/npm_package_internal.bzl
+++ b/npm/private/npm_package_internal.bzl
@@ -16,6 +16,7 @@
doc = """The package version.""",
mandatory = True,
),
+ "license": attr.string(doc = "todo"),
}
def _impl(ctx):
@@ -35,6 +36,7 @@
directory = dst,
npm_package_store_deps = depset(),
hardlink = True, # always hardlink downstream
+ license = ctx.attr.license,
),
]
diff --git a/npm/private/npm_package_store.bzl b/npm/private/npm_package_store.bzl
index 229f5d3..f8dd28c 100644
--- a/npm/private/npm_package_store.bzl
+++ b/npm/private/npm_package_store.bzl
@@ -2,6 +2,7 @@
load("@aspect_bazel_lib//lib:copy_directory.bzl", "copy_directory_bin_action")
load("@bazel_skylib//lib:paths.bzl", "paths")
+load("@rules_license//rules:providers.bzl", "PackageInfo")
load(":utils.bzl", "utils")
load(":npm_package_info.bzl", "NpmPackageInfo")
load(":npm_package_store_info.bzl", "NpmPackageStoreInfo")
@@ -160,6 +161,7 @@
def _impl(ctx):
package = ctx.attr.package if ctx.attr.package else ctx.attr.src[NpmPackageInfo].package
version = ctx.attr.version if ctx.attr.version else ctx.attr.src[NpmPackageInfo].version
+ license = getattr(ctx.attr.src[NpmPackageInfo], "license", "") if ctx.attr.src else None
if not package:
fail("No package name specified to link to. Package name must either be specified explicitly via 'package' attribute or come from the 'src' 'NpmPackageInfo', typically a 'npm_package' target")
@@ -306,6 +308,19 @@
transitive_files = transitive_files_depset,
dev = ctx.attr.dev,
),
+ PackageInfo(
+ # Metadata providers must include a type discriminator. We don't need it
+ # to collect the providers, but we do need it to write the JSON. We
+ # key on the type field to look up the correct block of code to pull
+ # data out and format it. We can't to the lookup on the provider class.
+ type = "package_info",
+ label = ctx.label,
+ package_name = package,
+ #package_url = ctx.attr.package_url,
+ package_version = version,
+ # TODO: need to provide a LicenseInfo also?
+ # license = license,
+ ),
]
if virtual_store_directory:
# Provide an output group that provides a single file which is the