Skip to content

Commit 1429e15

Browse files
authored
Add support for *.MODULE.bazel files (#1266)
After bazelbuild/bazel#22075, these are the files that can be `include()`ed into `MODULE.bazel` files and should be formatted and edited just like them.
1 parent fa8c825 commit 1429e15

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

build/lex.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242
TypeWorkspace
4343
// TypeBzl represents .bzl files
4444
TypeBzl
45-
//TypeModule represents MODULE.bazel files
45+
//TypeModule represents MODULE.bazel and *.MODULE.bazel files
4646
TypeModule
4747
)
4848

@@ -130,7 +130,7 @@ func getFileType(filename string) FileType {
130130
if strings.HasSuffix(basename, ".oss") {
131131
basename = basename[:len(basename)-4]
132132
}
133-
if basename == "module.bazel" {
133+
if basename == "module.bazel" || strings.HasSuffix(basename, ".module.bazel") {
134134
return TypeModule
135135
}
136136
ext := filepath.Ext(basename)

buildozer/buildozer_test.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,36 @@ EOF
20382038
diff -u MODULE.bazel.expected MODULE.bazel || fail "Output didn't match"
20392039
}
20402040

2041+
function test_module_bazel_segment() {
2042+
cat > go.MODULE.bazel <<EOF
2043+
module(
2044+
name = "foo",
2045+
version = "0.27.0",
2046+
)
2047+
2048+
bazel_dep(name = "gazelle", version = "0.30.0")
2049+
2050+
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
2051+
go_deps.from_file(go_mod = "//:go.mod")
2052+
use_repo(go_deps, "com_example_foo")
2053+
EOF
2054+
2055+
cat > go.MODULE.bazel.expected <<EOF
2056+
module(
2057+
name = "foo",
2058+
version = "0.27.0",
2059+
)
2060+
2061+
bazel_dep(name = "gazelle", version = "0.30.0")
2062+
2063+
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
2064+
go_deps.from_file(go_mod = "//:go.mod")
2065+
EOF
2066+
2067+
$buildozer 'delete' //go.MODULE.bazel:%10
2068+
diff -u go.MODULE.bazel.expected go.MODULE.bazel || fail "Output didn't match"
2069+
}
2070+
20412071
function test_module_bazel_new() {
20422072
cat > MODULE.bazel <<EOF
20432073
bazel_dep(name = "gazelle", version = "0.30.0")

0 commit comments

Comments
 (0)