{"id":13450582,"url":"https://github.com/bazelbuild/bazel-watcher","last_synced_at":"2025-07-12T03:04:50.262Z","repository":{"id":37681027,"uuid":"91018552","full_name":"bazelbuild/bazel-watcher","owner":"bazelbuild","description":"Tools for building Bazel targets when source files change.","archived":false,"fork":false,"pushed_at":"2024-09-03T22:11:09.000Z","size":837,"stargazers_count":441,"open_issues_count":17,"forks_count":118,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-28T17:39:20.052Z","etag":null,"topics":["bazel","build","fast"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bazelbuild.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-11T20:01:40.000Z","updated_at":"2024-10-27T18:41:30.000Z","dependencies_parsed_at":"2022-07-13T19:10:28.857Z","dependency_job_id":"4baf413c-ec00-4b70-867c-dc357cdb6cbd","html_url":"https://github.com/bazelbuild/bazel-watcher","commit_stats":{"total_commits":435,"total_committers":91,"mean_commits":4.78021978021978,"dds":0.7172413793103448,"last_synced_commit":"ab9c7d4c172f1bc3e44871a4f91ca933a7eeea72"},"previous_names":[],"tags_count":72,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazelbuild%2Fbazel-watcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazelbuild%2Fbazel-watcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazelbuild%2Fbazel-watcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazelbuild%2Fbazel-watcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bazelbuild","download_url":"https://codeload.github.com/bazelbuild/bazel-watcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224360099,"owners_count":17298319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","build","fast"],"created_at":"2024-07-31T07:00:36.370Z","updated_at":"2024-11-12T23:14:44.988Z","avatar_url":"https://github.com/bazelbuild.png","language":"Go","readme":"# Bazel watcher\n\n[![Build status](https://badge.buildkite.com/7694a2e22dcb7ea2e2ec80bb7e8e0380c700079e761394096f.svg?branch=master)](https://buildkite.com/bazel/bazel-watcher-postsubmit)\n\nNote: This is not an official Google product.\n\nA source file watcher for [Bazel](https://Bazel.build) projects\n\nEver wanted to save a file and have your tests automatically run? How about\nrestart your webserver when one of the source files change? Look no further.\n\nInstall `ibazel` using one of the 3 methods [described below](#installation). Then:\n\n```bash\n$ ibazel build //path/to/my:target\n```\n\nHack hack hack. Save and your target will be rebuilt.\n\nRight now this repo supports `build`, `test`, and `run`.\n\n## Installation\n\nThere are several ways to install iBazel, documented below.\n\n### Mac (Homebrew)\n\nIf you run a macOS you can install it from [homebrew](https://brew.sh).\n\n```sh\n$ brew install ibazel\n```\n\n### NPM\n\nIf you're a JS developer you can install it as a `devDependency` or by calling `npm install` directly in your project\n\n```\n$ npm install @bazel/ibazel\n```\n\n### Linux\n\nPackages are available for the following distributions:\n\n* **Arch Linux**: [`aur/ibazel`][install/linux/archlinux/aur]\n\n[install/linux/archlinux/aur]: https://aur.archlinux.org/packages/ibazel\n\n### Compiling yourself\n\nYou can, of course, build iBazel using Bazel.\n\n```\n$ git clone git@github.com:bazelbuild/bazel-watcher\n$ cd bazel-watcher\n$ bazel build //cmd/ibazel\n```\n\nNow copy the generated binary onto your path:\n\n```bash\n$ export PATH=$PATH:$PWD/bazel-bin/cmd/ibazel/ibazel_\n```\n\n## Running a target\n\nBy default, a target started with `ibazel run` will be terminated and restarted\nwhenever it's notified of source changes. Alternatively, if the build rule for\nyour target contains `ibazel_notify_changes` in its `tags` attribute, then the\ncommand will stay alive and will receive a notification of the source changes on\nstdin.\n\n## Output Runner\n\niBazel is capable of producing and running commands from the output of Bazel\ncommands. If iBazel is run with the flag `--run_output` then it will check for\na `%WORKSPACE%/.bazel_fix_commands.json` and if present run any commands that\nmatch the provided regular expressions.  For example the commands defined by\nthe following file will match `buildozer` commands found in the output and\nprovide a prompt to run the command as well as invoke `bazel run //:gazelle` if\nit detects a missing import for your go code.\n\n```\n[\n  {\n    \"regex\": \"^Check that imports in Go sources match importpath attributes in deps.$\",\n    \"command\": \"bazel\",\n    \"args\": [ \"run\", \"//:gazelle\" ]\n  },\n  {\n    \"regex\": \"^buildozer '(.*)'\\\\s+(.*)$\",\n    \"command\": \"buildozer\",\n    \"args\": [ \"$1\", \"$2\" ]\n  },\n  {\n    \"regex\": \"^(\\\\S+)/[\\\\w-]+\\\\.proto:\\\\d+:\\\\d+: Import \\\"\\\\S+\\\" was not found or had errors\\\\.$\",\n    \"command\": \"bazel\",\n    \"args\": [ \"run\", \"//:gazelle\", \"--\", \"proto/$1\" ]\n  }\n]\n```\n\nAdding the flag `--run_output_interactive=false` will automatically run the\ncommand without prompting for confirmation.  The fields in\n`.bazel_fix_commands.json` are:\n\n* `regex`: a regular expression that will be matched against every line of\n  output.\n    * backslash `\\` characters will need to be escaped once for the regex to be\n      parsed properly.\n* `command`: a command that will be run from the workspace root.\n* `args`: a list of arguments to provide to the command, substituting `$1`\n  with the first match group of `regex`, `$2` with the second, etc., and `$0`\n  for the entire match.\n\nYou can disable this feature by adding flag `--run_output=false` or you can\ncreate a `.bazel_fix_commands.json` that contains an empty json array, `[]`.\nThis will additionally disable the notification providing usage instructions on\nthe first invocation of iBazel.\n\n### Disabling output runner\n\nIf you would like to remove the banner but don't wish to configure the output\nrunner, you can create an empty configuration file like this:\n\n```sh\necho \"[]\" \u003e .bazel_fix_commands.json\n```\n\nYou should no longer be prompted when iBazel starts up.\n\n## Profiling\n\niBazel has a `--profile_dev` flag which turns on a generated profile output file\nabout the build process and timing. To use it include this flag in the command line. For example,\n\n```\nibazel --profile_dev=profile.json run devserver\n```\n\nThe profile outfile is in concatenated JSON format. Events are outputted one per line.\n\n### Profiler events\n\n| Event | Description | Attributes \u003cfont size=1\u003e(* optional)\u003c/font\u003e |\n| ------------- | ------------- | ------------- |\n| `IBAZEL_START` | Emitted when iBazel is started as part of the first iteration | `type`, `iteration`, `time`, `iBazelVersion`, `bazelVersion`, `maxHeapSize`, `committedHeapSize` |\n| `SOURCE_CHANGE` | A source file change was detected | `type`, `iteration`, `time`, `targets`, `elapsed`, `change` |\n| `GRAPH_CHANGE` | A build file change was detected | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `RELOAD_TRIGGERED` | A livereload was triggered to any listening browsers | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `RUN_START` | A run operation started | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `RUN_FAILED` | A run operation failed | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `RUN_DONE` | A run operation completed successfully | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `BUILD_START` | A build operation started | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `BUILD_FAILED` | A build operation failed | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `BUILD_DONE` | A build operation completed successfully | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `TEST_START` | A test operation started | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `TEST_FAILED` | A test operation failed | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `TEST_DONE` | A test operation completed successfully | `type`, `iteration`, `time`, `targets`, `elapsed`, `changes`* |\n| `REMOTE_EVENT` | A remote event was received from the browser | `type`, `iteration`, `time`, `targets`, `elapsed`, `remoteType`, `remoteTime`, `remoteElapsed`, `remoteData` |\n| `REMOTE_EVENT / PAGE_LOAD` | A remote event emitted by the profiler client-side script on the browser's `load` event. `remoteType` is `PAGE_LOAD`. | `type`, `iteration`, `time`, `targets`, `elapsed`, `remoteType`, `remoteTime`, `remoteElapsed`, `remoteData` |\n\n### Event attributes\n\n| Attribute | Type | Description |\n| ------------- | ------------- | ------------- |\n| `type` | string | Event type. |\n| `iteration` | string | Unique build iteration key. |\n| `time` | integer | Time of event. |\n| `targets` | string[] | List of targets that are being built (Note: this is a complete list and includes targets that were already built prior to an iteration). |\n| `elapsed` | integer | Elapsed time in ms since the start of the iteration. |\n| `change` | string | The file changed on a `SOURCE_CHANGE` or `GRAPH_CHANGE` event. |\n| `changes` | string[] | A cumulative list of files changed during a build iteration. |\n| `iBazelVersion` | string | Version of iBazel that generated this event. |\n| `bazelVersion` | string | Version of bazel in use. |\n| `maxHeapSize` | string | Max heap size as reported by Bazel. |\n| `committedHeapSize` | string | Committed heap size as reported by Bazel. |\n| `remoteType` | string | Sub-type for `REMOTE_EVENT` type. |\n| `remoteTime` | number | Browser time for `REMOTE_EVENT` type. |\n| `remoteElapsed` | number | Elapsed time in browser since `navigationStart` for `REMOTE_EVENT` type. |\n| `remoteData` | string | Data sent from browser for `REMOTE_EVENT` type. This may be in escaped JSON format for some remote events. |\n\n### Example profile output file\n\nYou can find an example profile output JSON file [here](https://github.com/bazelbuild/bazel-watcher/blob/master/example.profile.json). Below is the file in pretty print JSON format:\n\n```\n{\n  \"type\": \"IBAZEL_START\",\n  \"iteration\": \"4214114686684e0f\",\n  \"time\": 1513706108351,\n  \"iBazelVersion\": \"v0.2.0-dirty\",\n  \"bazelVersion\": \"release 0.8.1-homebrew\",\n  \"maxHeapSize\": \"3817MB\",\n  \"committedHeapSize\": \"1372MB\"\n}\n{\n  \"type\": \"RUN_START\",\n  \"iteration\": \"4214114686684e0f\",\n  \"time\": 1513706109329,\n  \"targets\": [\n    \"//src:devserver\"\n  ],\n  \"elapsed\": 978\n}\n{\n  \"type\": \"RELOAD_TRIGGERED\",\n  \"iteration\": \"4214114686684e0f\",\n  \"time\": 1513706114595,\n  \"targets\": [\n    \"//src:devserver\"\n  ],\n  \"elapsed\": 6244\n}\n{\n  \"type\": \"RUN_DONE\",\n  \"iteration\": \"4214114686684e0f\",\n  \"time\": 1513706114595,\n  \"targets\": [\n    \"//src:devserver\"\n  ],\n  \"elapsed\": 6244\n}\n{\n  \"type\": \"SOURCE_CHANGE\",\n  \"iteration\": \"7e6f8e150e9a8367\",\n  \"time\": 1513706129384,\n  \"targets\": [\n    \"//src:devserver\"\n  ],\n  \"change\": \"/Users/greg/google/gregmagolan/angular-bazel-example/src/hello-world/hello-world.component.ts\"\n}\n{\n  \"type\": \"RUN_START\",\n  \"iteration\": \"7e6f8e150e9a8367\",\n  \"time\": 1513706129484,\n  \"targets\": [\n    \"//src:devserver\"\n  ],\n  \"elapsed\": 100,\n  \"changes\": [\n    \"/Users/greg/google/gregmagolan/angular-bazel-example/src/hello-world/hello-world.component.ts\"\n  ]\n}\n{\n  \"type\": \"RELOAD_TRIGGERED\",\n  \"iteration\": \"7e6f8e150e9a8367\",\n  \"time\": 1513706133947,\n  \"targets\": [\n    \"//src:devserver\"\n  ],\n  \"elapsed\": 4563,\n  \"changes\": [\n    \"/Users/greg/google/gregmagolan/angular-bazel-example/src/hello-world/hello-world.component.ts\"\n  ]\n}\n{\n  \"type\": \"RUN_DONE\",\n  \"iteration\": \"7e6f8e150e9a8367\",\n  \"time\": 1513706133947,\n  \"targets\": [\n    \"//src:devserver\"\n  ],\n  \"elapsed\": 4563,\n  \"changes\": [\n    \"/Users/greg/google/gregmagolan/angular-bazel-example/src/hello-world/hello-world.component.ts\"\n  ]\n}\n{\n  \"type\": \"REMOTE_EVENT\",\n  \"iteration\": \"7e6f8e150e9a8367\",\n  \"time\": 1513706134297,\n  \"targets\": [\n    \"//src:devserver\"\n  ],\n  \"elapsed\": 4913,\n  \"remoteType\": \"PAGE_LOAD\",\n  \"remoteTime\": 1513706134294,\n  \"remoteElapsed\": 346,\n  \"remoteData\": \"{\\\"pageLoadTime\\\":344,\\\"fetchTime\\\":9,\\\"connectTime\\\":0,\\\"requestTime\\\":6,\\\"responseTime\\\":6,\\\"renderTime\\\":325,\\\"navigationStart\\\":1513706133948,\\\"unloadEventStart\\\":1513706133962,\\\"unloadEventEnd\\\":1513706133962,\\\"redirectStart\\\":0,\\\"redirectEnd\\\":0,\\\"fetchStart\\\":1513706133952,\\\"domainLookupStart\\\":1513706133952,\\\"domainLookupEnd\\\":1513706133952,\\\"connectStart\\\":1513706133952,\\\"connectEnd\\\":1513706133952,\\\"secureConnectionStart\\\":0,\\\"requestStart\\\":1513706133955,\\\"responseStart\\\":1513706133955,\\\"responseEnd\\\":1513706133961,\\\"domLoading\\\":1513706133967,\\\"domInteractive\\\":1513706134222,\\\"domContentLoadedEventStart\\\":1513706134222,\\\"domContentLoadedEventEnd\\\":1513706134222,\\\"domComplete\\\":1513706134292,\\\"loadEventStart\\\":1513706134292}\"\n}\n```\n\n## Remote events\n\nRemote events require the client-side profiling script. If you are using the `ts_devserver` bazel rule, this script will automatically be included in the development bundle so you don't have to worry about including it. If you're not using `ts_devserver` for development mode, you can include the following script tag to pull in the client-side profiling script:\n\n```\n\u003cscript src=\"http://localhost:30000/profiler.js\"\u003e\u003c/script\u003e\n```\n\nThe script is served by iBazel on port 30000 by default. If port 30000 is not available, iBazel will attempt to find another available port between 30001 and 30099.\n\nRemote events in the profiler script are sent using the [Beacon API](https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API). This API is available in Chrome 39, Firefox 31, Edge and Opera 26. It is not available in Internet Explorer or Safari. Browser compatability can be checked [here](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon#Browser_compatibility).\n\nIf your browser does not support the Beacon API, you will see the following error in the console when including the profiler script: `iBazel profiler disabled because Beacon API is not available`.\n\n## Custom remote events\n\nWhen the profiler script is loaded, a `window.IBazelProfileEvent(eventType, data)` public API is made available for generating custom remote events. This function sends a custom REMOTE_EVENT to the iBazel profiler log.\n\n| Param | Type | Description |\n| ------------- | ------------- | ------------- |\n| `eventType` | string | The event type that ends up in the 'remoteType' attribute of the REMOTE_EVENT. |\n| `data` | any | Optional data associated with the event. This is converted to a string. If it is an object it will be converted to escaped JSON in the profiler log. |\n\n## Additional notes\n\n### Termination\n\nSIGINT has to be sent twice to kill ibazel: once to terminate the subprocess,\nand the second time for ibazel itself. Also, ibazel will exit on its own when a\nbazel query fails, but it will stay alive when a build, test, or run fails.\nWe use an exit code of 3 for a signal termination, and 4 for a query failure.\nThese codes are not an API and may change at any point.\n\n### What about the `--watchfs` flag?\n\nBazel has a flag called `--watchfs` which, according to the bazel command-line\nhelp does:\n\n\u003e If true, Bazel tries to use the operating system's file watch service for\n\u003e local changes instead of scanning every file for a change\n\nUnfortunately, this option does not rebuild the project on save like the Bazel\nwatcher does, but instead queries the file system for a list of files that have\nbeen invalidated since last build and will require reinspection by the Bazel\nserver.\n\n### Big thanks\n\n * [Google](http://opensource.google.com) for cross-platform build/test CI instances.\n * [Sauce Labs](https://saucelabs.com) for cross-browser testing.\n\nCopyright 2017 The Bazel Authors. All right reserved.\n","funding_links":[],"categories":["Tooling","Go"],"sub_categories":["General"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbazelbuild%2Fbazel-watcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbazelbuild%2Fbazel-watcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbazelbuild%2Fbazel-watcher/lists"}