bazelbuild / bazelbuild/bazel-watcher
labelsToWatch() silently skips packages whose name starts with "external"
- Dominant language
- Go
- Stars
- 513
- Forks
- 143
- PR merge metrics
- No merged PRs in 30d
Description
## Description
`labelsToWatch()` in `ibazel.go` has an overly broad prefix check that silently drops **all** source file labels from any Bazel package whose name starts with `external` — not just actual external-repository labels like `//external/some_dep`.
This means that if you have a package such as `//external_api_v3`, `//externalization`, or any other package whose name happens to begin with `external`, ibazel will never set up file watches for its sources. Hot reload silently does nothing, with no warning or error message.
## Root Cause
https://github.com/bazelbuild/bazel-watcher/blob/v0.21.4/internal/ibazel/ibazel.go#L509
```go
if strings.HasPrefix(label, "//external") {
continue
}
```
This matches `//external_api_v3/src/main.ts`, `//externals/lib.go`, etc. — not just `//external/...` or `//external:...`.
## Suggested Fix
Narrow the prefix check to only match actual external-repository label prefixes:
```go
if strings.HasPrefix(label, "//external/") || strings.HasPrefix(label, "//external:") {
continue
}
```
This preserves the original intent (filtering out legacy external-repository paths) without silently breaking packages that merely start with the word "external".
## Reproduction
1. Create a Bazel workspace with a package whose name starts with `external` (e.g. `external_api`):
```
# Directory structure
external_api/
BUILD.bazel
src/
main.ts
# external_api/BUILD.bazel
js_binary(
name = "external-api",
entry_point = "src/main.ts",
# ...
)
```
2. Run `ibazel run //external_api:external-api`
3. Edit `external_api/src/main.ts`
4. Observe that ibazel does **not** detect the change or rebuild
A package with a name that does not start with `external` (e.g. `my_api`) works correctly with the same setup.
## Impact
This is a silent failure — there is no log message, warning, or error. The user sees ibazel start normally and assumes hot reload is working, but file changes are never detected. Debugging requires tracing through ibazel internals to discover that source files are being silently filtered out.
## Version
- ibazel: v0.21.4 (bug also present on current `main`)
- Bazel: 7.x / 8.x / 9.x (not version-specific)
- OS: macOS / Linux
## Related
This is a distinct issue from #825, which covers a different filtering bug in `labelsToWatch()` related to `@`-prefixed external targets and the `localRepositories` break logic.
Contributor guide
Research direction
Start in internal/ibazel/ibazel.go at labelsToWatch(), especially the prefix check around line 509. Reproduce with a package such as //external_api and verify that source labels are watched while //external/... and //external:... labels remain filtered; done means edits trigger rebuilding without affecting the intended external-repository filtering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100