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

fix: allow root repositories to override esbuild toolchain version under bzlmod #164

Merged
merged 1 commit into from
Nov 20, 2023
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
14 changes: 12 additions & 2 deletions esbuild/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"extensions for bzlmod"

load(":repositories.bzl", "esbuild_register_toolchains")
load(":repositories.bzl", "DEFAULT_ESBUILD_REPOSITORY", "esbuild_register_toolchains")

esbuild_toolchain = tag_class(attrs = {
"name": attr.string(doc = "Base name for generated repositories"),
"name": attr.string(
doc = "Base name for generated repositories",
default = DEFAULT_ESBUILD_REPOSITORY,
),
"esbuild_version": attr.string(doc = "Explicit version of esbuild."),
# TODO: support this variant
# "esbuild_version_from": attr.string(doc = "Location of package.json which may have a version for @esbuild/core."),
Expand All @@ -13,7 +16,14 @@ def _toolchain_extension(module_ctx):
registrations = {}
for mod in module_ctx.modules:
for toolchain in mod.tags.toolchain:
if toolchain.name != DEFAULT_ESBUILD_REPOSITORY and not mod.is_root:
fail("Only the root module may provide a name for the esbuild toolchain.")

if toolchain.name in registrations.keys():
if toolchain.name == DEFAULT_ESBUILD_REPOSITORY:
# Prioritize the root-most registration of the default esbuild toolchain version and
# ignore any further registrations (modules are processed breadth-first)
continue
if toolchain.esbuild_version == registrations[toolchain.name]:
# No problem to register a matching toolchain twice
continue
Expand Down
4 changes: 4 additions & 0 deletions esbuild/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ load("//esbuild/private:versions.bzl", "TOOL_VERSIONS")

LATEST_ESBUILD_VERSION = TOOL_VERSIONS.keys()[-1]

# Default base name for esbuild toolchain repositories
# created by the module extension
DEFAULT_ESBUILD_REPOSITORY = "esbuild"

_DOC = "Fetch external tools needed for esbuild toolchain"
_ATTRS = {
"esbuild_version": attr.string(mandatory = True, values = TOOL_VERSIONS.keys()),
Expand Down