Repository navigation
fix(gazelle): keep another language's Bazel package out of a package's srcs - #418
Merged
aronstrandberg merged 3 commits intoDec 2, 2026
Merged
Conversation
…s srcs A package's srcs take every regular file under its directory that no deeper TypeScript package owns. A Go go_binary in a subdirectory therefore had its .go, go.mod and go.sum files written into the TypeScript package above it, as labels Bazel refuses because they reach into a subpackage. A directory whose BUILD file holds a rule of a kind this extension does not write stays a Bazel package whatever a run writes, so it and its subtree add no files to the package above. A BUILD file that holds only this extension's rules still does not, since a run can withdraw them all.
… under the directory's kind map Read each BUILD file's rules with its own directory's configuration, so a mapped or aliased TypeScript kind counts as this extension's. A BUILD file on disk with no rules stays a Bazel package too, including one whose rules a run withdrew.
Member
Author
|
@claude review always |
…dary A hand-written filegroup or exports_files, or any rule of this extension's kinds that a run does not withdraw from a directory without a program, keeps its directory a Bazel package, so its files stay out of the package above.
ignaciofernandez-l5e
approved these changes
Dec 2, 2026
aherrmann-lov
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stop Gazelle from listing another language's files as a TypeScript package's
srcs. Today a Go package in a subdirectory of a TypeScript package gets its.go,go.modandgo.sumfiles written into the package above, as labels such ascmd/tool/main.gothat Bazel refuses because they reach into a subpackage. In the lovable monorepo this blocks any Go code underinfra/buildkite, which is itself a TypeScript package.Claude Opus 5.5, high
Cause.
dataFilestakes every regular file under a package's tree that no listing decides, and skips only directories that belong to a deeper TypeScript package (nearestPackage). A directory whose BUILD file holds Go rules is no TypeScript package, so its files land in the package above.Change.
dataFilesalso skips a directory when it, or a directory between it and the package, has a BUILD file that stays a Bazel package whatever this run writes: one on disk with no rules, or one with any rule other than those a run withdraws from a directory without a program (ownedRuleNames, matched by kind under that directory's own kind map, and by name). No label of the package above can name a file in it or below it. A BUILD file that holds only such rules is still no boundary while it holds them; a hand-writtenfilegrouporexports_files, or ats_codegen, is one.One consequence to check: when a run withdraws all of a directory's TypeScript rules, Gazelle leaves its BUILD file on disk, empty, so the next read treats it as a package and its files leave the parent's
srcs. Before this change they went into the parent, where Bazel refuses them because the empty BUILD file is still a package.TestGenerate_AProgramWithNoInputsIsNoPackagestill passes, because its harness does not write files back.Not covered: a
.tsfile inside such a foreign Bazel package that a program above it lists is still claimed throughowner. That needs its own decision, since the program does list it.Tests.
TestGenerate_AnotherLanguagesBazelPackageKeepsItsFilesputs ago_binaryunder a TypeScript package; without the changesrcsheldcmd/tool/go.mod cmd/tool/main.go cmd/tool/sub/x.go.TestGenerate_ABuildFileWithNoRulesKeepsItsFilesruns the real binary over an emptyBUILD.bazelbeside a.bzlfile, a hand-writtenfilegroupand a withdrawn mappedts_compile; without the changesrcsheldbzl/defs.bzl data/d.txt mapped/m.txt. Both pass with it.Not covered either: a run where the other language's BUILD file does not exist yet when this extension reads the tree (a binary that lists TypeScript first, or a TypeScript-only run before the other language's). In the lovable monorepo the Go Gazelle runs first. On my machine
TestProgram_ExitCodePolicyandTestProgram_TheTraceIsDecodedWhileTsgoRunsfail onmainand with this change alike (tsgo exits 127 there), so//gazelle:typescript_testfails 4 of 8 shards either way; I have not looked into why.In the monorepo. With the change applied on the current pin (
1583e19a) through--override_module,//:gazelle_typescriptwritessrcs = ["read.ts"]forinfra/buildkite/packages/secretsnext to a Gazelle-written Go package inpackages/secrets/cmd/bk-secrets, and both build and test.