From d271e4bde6ec976661454c297f4442f65724e43c Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 4 Mar 2026 07:52:24 +0000 Subject: [PATCH] feat: add phase 7 bun_install module extension --- README.md | 5 ++++ bun/BUILD.bazel | 5 +++- bun/extensions.bzl | 25 +++++++++++++++++++ tests/install_extension_test/BUILD.bazel | 8 ++++++ .../extension_shape_test.sh | 9 +++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/install_extension_test/BUILD.bazel create mode 100755 tests/install_extension_test/extension_shape_test.sh diff --git a/README.md b/README.md index 43598c1..f65b7fc 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,8 @@ Phase 6 bootstrap is in place: - Source grouping rules `js_library` / `ts_library` (`/internal/js_library.bzl`) - Transitive `deps` propagation wired into `bun_bundle` and `bun_test` - Focused dependency-propagation tests (`//tests/library_test:all`) + +Phase 7 bootstrap is in place: + +- Bzlmod `bun_install` module extension (`/bun/extensions.bzl`) using Bazel 9-compatible extension/tag syntax +- Focused module-extension shape test (`//tests/install_extension_test:all`) diff --git a/bun/BUILD.bazel b/bun/BUILD.bazel index ba771e6..c1895c7 100644 --- a/bun/BUILD.bazel +++ b/bun/BUILD.bazel @@ -1,7 +1,10 @@ load(":toolchain.bzl", "bun_toolchain") load(":version.bzl", "BUN_VERSION") -exports_files(["defs.bzl"]) +exports_files([ + "defs.bzl", + "extensions.bzl", +]) toolchain_type(name = "toolchain_type") diff --git a/bun/extensions.bzl b/bun/extensions.bzl index bb9ea75..cb25371 100644 --- a/bun/extensions.bzl +++ b/bun/extensions.bzl @@ -1,4 +1,5 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("//internal:bun_install.bzl", _bun_install_repository = "_bun_install_repository") load(":version.bzl", "BUN_VERSION") _BUN_ARCHIVES = { @@ -53,3 +54,27 @@ filegroup( bun = module_extension( implementation = _bun_repos_impl, ) + +_install = tag_class( + attrs = { + "name": attr.string(default = "node_modules"), + "package_json": attr.string(mandatory = True), + "bun_lockfile": attr.string(mandatory = True), + }, +) + + +def _bun_install_impl(ctx): + for mod in ctx.modules: + for install in mod.tags.install: + _bun_install_repository( + name = install.name, + package_json = install.package_json, + bun_lockfile = install.bun_lockfile, + ) + + +bun_install = module_extension( + implementation = _bun_install_impl, + tag_classes = {"install": _install}, +) diff --git a/tests/install_extension_test/BUILD.bazel b/tests/install_extension_test/BUILD.bazel new file mode 100644 index 0000000..bdf75d8 --- /dev/null +++ b/tests/install_extension_test/BUILD.bazel @@ -0,0 +1,8 @@ +load("@rules_shell//shell:sh_test.bzl", "sh_test") + +sh_test( + name = "bun_install_extension_shape_test", + srcs = ["extension_shape_test.sh"], + args = ["$(location //bun:extensions.bzl)"], + data = ["//bun:extensions.bzl"], +) diff --git a/tests/install_extension_test/extension_shape_test.sh b/tests/install_extension_test/extension_shape_test.sh new file mode 100755 index 0000000..a2f9aa1 --- /dev/null +++ b/tests/install_extension_test/extension_shape_test.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail + +extension_file="$1" + +grep -q 'bun_install = module_extension(' "${extension_file}" +grep -q 'tag_classes = {"install": _install}' "${extension_file}" +grep -q '"package_json": attr.string(mandatory = True)' "${extension_file}" +grep -q '"bun_lockfile": attr.string(mandatory = True)' "${extension_file}"