Skip to content

Commit ad64858

Browse files
authored
feat: add more utility tools (#350)
* feat: add more utility tools pnpm is especially useful for frontend engineers Also run 'multitool update' to get newer versions * refactor: simplify * chore: update bazel readme * Update README.bazel.md
1 parent a48216d commit ad64858

File tree

12 files changed

+182
-36
lines changed

12 files changed

+182
-36
lines changed

README.bazel.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,34 @@ For a more robust developer experience, see the [sample shell script](https://gi
3939
For developers to be able to run a CLI tool without needing manual installation:
4040

4141
1. Add the tool to `tools/tools.lock.json`
42-
2. `cd tools; ln -s _multitool_run_under_cwd.sh name_of_tool`
42+
2. `cd tools; ln -s _run_under_cwd.sh name_of_tool`
4343
3. Instruct developers to run `./tools/name_of_tool` rather than install that tool on their machine.
4444

45+
To update the versions of installed tools, run:
46+
47+
```shell
48+
% cd $(bazel info workspace)/tools; ./multitool --lockfile tools.lock.json update
49+
```
50+
4551
See https://blog.aspect.build/run-tools-installed-by-bazel for details.
4652

4753
## Working with npm packages
4854

49-
To install a `node_modules` tree locally for the editor or other tooling outside of Bazel:
55+
To install a `node_modules` tree locally for the editor or other tooling outside of Bazel,
56+
run this command from any folder with a `package.json` file:
5057

58+
```shell
59+
% $(bazel info workspace)/tools/pnpm install
5160
```
52-
bazel run -- @pnpm --dir $PWD install
61+
62+
> NB: `bazel info workspace` avoids having a bunch of `../` segments when running tools from a subdirectory.
63+
64+
Similarly, you can run other `pnpm` commands to add or remove packages.
65+
66+
```shell
67+
% $(bazel info workspace)/tools/pnpm add http-server
5368
```
5469

55-
Similarly, you can run other `pnpm` commands to install or remove packages.
5670
This ensures you use the same pnpm version as other developers, and the lockfile format will stay constant.
5771

5872
## Working with Python packages
@@ -88,11 +102,12 @@ Then edit the new entry in `tools/BUILD` to replace `package_name_snake_case` wi
88102

89103
After adding a new `import` statement in Go code, run `bazel configure` to update the BUILD file.
90104

91-
If the package is not already a dependency of the project, you'll have to do some additional steps:
105+
If the package is not already a dependency of the project, you'll have to do some additional steps.
106+
Run these commands from the workspace root:
92107

93108
```shell
94109
# Update go.mod and go.sum, using same Go SDK as Bazel
95-
% bazel run @rules_go//go -- mod tidy -v
110+
% $(bazel info workspace)/tools/go mod tidy -v
96111
# Update MODULE.bazel to include the package in `use_repo`
97112
% bazel mod tidy
98113
# Repeat

tools/_multitool_run_under_cwd.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

tools/_run_under_cwd.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
# See https://blog.aspect.build/run-tools-installed-by-bazel
3+
case "$(basename "$0")" in
4+
go)
5+
# https://github.com/bazelbuild/rules_go/blob/master/docs/go/core/bzlmod.md#using-a-go-sdk
6+
target="@rules_go//go"
7+
;;
8+
pnpm)
9+
# https://github.com/aspect-build/rules_js/blob/main/docs/faq.md#can-i-use-bazel-managed-pnpm
10+
target="@pnpm"
11+
;;
12+
*)
13+
target="@multitool//tools/$(basename "$0")"
14+
;;
15+
esac
16+
# NB: we don't use 'bazel run' because it may leave behind zombie processes under ibazel
17+
bazel 2>/dev/null build "$target" && BAZEL_BINDIR=. exec $(bazel info execution_root)/$(bazel 2>/dev/null cquery --output=files "$target") "$@"

tools/buf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./_run_under_cwd.sh

tools/buildozer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./_multitool_run_under_cwd.sh
1+
./_run_under_cwd.sh

tools/docker-compose

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./_run_under_cwd.sh

tools/go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./_run_under_cwd.sh

tools/ibazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./_multitool_run_under_cwd.sh
1+
./_run_under_cwd.sh

tools/multitool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./_run_under_cwd.sh

tools/pnpm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./_run_under_cwd.sh

0 commit comments

Comments
 (0)