Skip to content

Commit

Permalink
fix: allow root repositories to override esbuild toolchain version un…
Browse files Browse the repository at this point in the history
…der bzlmod (#164)
  • Loading branch information
satajo authored Nov 20, 2023
1 parent b388fb7 commit fe7efca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit fe7efca

Please sign in to comment.