Compare commits
44 Commits
a3591b85a5
...
v0.0.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3edcf4b12f | ||
|
|
8cc901194c | ||
|
|
dbefca4b39 | ||
|
|
3ddd0b77cc | ||
|
|
5fe05921d4 | ||
|
|
a6dedca6f5 | ||
|
|
372a62fa9c | ||
|
|
fd5b5ea8c0 | ||
|
|
0115bb3d27 | ||
|
|
8dbddb635d | ||
|
|
485ccdac7c | ||
|
|
5cb20b96c7 | ||
|
|
3d34ecc9f9 | ||
|
|
f31c88adab | ||
|
|
76a3f2f442 | ||
|
|
4d1be5ada2 | ||
|
|
a3022b4770 | ||
|
|
cf18ebeb79 | ||
|
|
9b2420c9b9 | ||
|
|
92ab71df30 | ||
|
|
55c23fa8b1 | ||
|
|
f59549bebf | ||
|
|
4c87b3cb0f | ||
|
|
2ac5412fb0 | ||
|
|
2e4e211bef | ||
|
|
d62b2e6e0c | ||
|
|
59d5a634d3 | ||
|
|
8f9f0a3653 | ||
|
|
dfc61b6cfc | ||
|
|
a95c09e92c | ||
|
|
ea244a8bb2 | ||
|
|
6cc7204cb3 | ||
|
|
2837127866 | ||
|
|
ef14de881b | ||
|
|
dbc2ca0bc9 | ||
|
|
7a77e04039 | ||
|
|
aa7766eff1 | ||
|
|
198d1dcd18 | ||
|
|
06a8094212 | ||
|
|
74622aba91 | ||
|
|
dfe658763b | ||
|
|
dc0b26c5b5 | ||
|
|
cb5a578600 | ||
|
|
aa6f87bd86 |
@@ -1,19 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
if [[ ! -d "/Users/eric/Projects/rules_bun" ]]; then
|
||||
echo "Cannot find source directory; Did you move it?"
|
||||
echo "(Looking for "/Users/eric/Projects/rules_bun")"
|
||||
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# rebuild the cache forcefully
|
||||
_nix_direnv_force_reload=1 direnv exec "/Users/eric/Projects/rules_bun" true
|
||||
|
||||
# Update the mtime for .envrc.
|
||||
# This will cause direnv to reload again - but without re-building.
|
||||
touch "/Users/eric/Projects/rules_bun/.envrc"
|
||||
|
||||
# Also update the timestamp of whatever profile_rc we have.
|
||||
# This makes sure that we know we are up to date.
|
||||
touch -r "/Users/eric/Projects/rules_bun/.envrc" "/Users/eric/Projects/rules_bun/.direnv"/*.rc
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/7f0478ddr51i3r708dpkljnvmzwc2fhn-source
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/affmc6lhad8f6q3iaa3iydcdjwr8lwgp-source
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/g5v3sgqy6a0fsmas7mnapc196flrplix-source
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/jzfmmjnq1cip816awnliw7ir69pcyg00-source
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/kx00h535s3jzb9803vnylxllij3zhix5-source
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/ngdfag0pfs1h54pbjs9ywah4zhqsphf1-source
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/nk13680f34w3q01a1q69c48my6fi7cxz-source
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/wmfpcy0yqb4igdizfrdcy5i3a9b3yjlg-nix-shell-env
|
||||
File diff suppressed because one or more lines are too long
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
@@ -5,10 +5,6 @@ on:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
permissions:
|
||||
@@ -29,12 +25,6 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: bazel-contrib/setup-bazel@0.15.0
|
||||
with:
|
||||
bazelisk-cache: true
|
||||
repository-cache: true
|
||||
external-cache: true
|
||||
disk-cache: ci-${{ matrix.phase8_target }}
|
||||
cache-save: ${{ github.event_name != 'pull_request' }}
|
||||
- name: Run tests (${{ matrix.phase8_target }})
|
||||
run: |
|
||||
echo "Phase 8 target: ${{ matrix.phase8_target }}"
|
||||
|
||||
10
.github/workflows/pages.yml
vendored
10
.github/workflows/pages.yml
vendored
@@ -3,11 +3,6 @@ name: Docs Pages
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
paths:
|
||||
- "docs/**"
|
||||
- "bun/**/*.bzl"
|
||||
- "internal/**/*.bzl"
|
||||
- ".github/workflows/pages.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
@@ -31,11 +26,6 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: bazel-contrib/setup-bazel@0.15.0
|
||||
with:
|
||||
bazelisk-cache: true
|
||||
repository-cache: true
|
||||
external-cache: true
|
||||
disk-cache: docs-pages
|
||||
|
||||
- name: Generate rule docs
|
||||
run: |
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
/nix/store/wrsbzz8sgxnp8xawaxy8nvc3sdwfl5s6-pre-commit-config.json
|
||||
@@ -1,12 +1,12 @@
|
||||
module(
|
||||
name = "rules_bun",
|
||||
version = "0.1.0",
|
||||
version = "0.0.7",
|
||||
)
|
||||
|
||||
bazel_dep(name = "platforms", version = "1.0.0")
|
||||
bazel_dep(name = "rules_shell", version = "0.6.1")
|
||||
bazel_dep(name = "bazel_skylib", version = "1.8.2")
|
||||
bazel_dep(name = "stardoc", version = "0.7.2")
|
||||
bazel_dep(name = "bazel_skylib", version = "1.8.0")
|
||||
bazel_dep(name = "stardoc", version = "0.7.1")
|
||||
|
||||
bun_ext = use_extension("//bun:extensions.bzl", "bun")
|
||||
use_repo(
|
||||
|
||||
11
MODULE.bazel.lock
generated
11
MODULE.bazel.lock
generated
@@ -48,6 +48,7 @@
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.7.0/MODULE.bazel": "0db596f4563de7938de764cc8deeabec291f55e8ec15299718b93c4423e9796d",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.8.0/MODULE.bazel": "2fb3fb53675f6adfc1ca5bfbd5cfb655ae350fba4706d924a8ec7e3ba945671c",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.8.1/MODULE.bazel": "88ade7293becda963e0e3ea33e7d54d3425127e0a326e0d17da085a5f1f03ff6",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.8.2/MODULE.bazel": "69ad6927098316848b34a9142bcc975e018ba27f08c4ff403f50c1b6e646ca67",
|
||||
"https://bcr.bazel.build/modules/bazel_skylib/1.8.2/source.json": "34a3c8bcf233b835eb74be9d628899bb32999d3e0eadef1947a0a562a2b16ffb",
|
||||
@@ -119,10 +120,13 @@
|
||||
"https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8",
|
||||
"https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74",
|
||||
"https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86",
|
||||
"https://bcr.bazel.build/modules/rules_java/6.0.0/MODULE.bazel": "8a43b7df601a7ec1af61d79345c17b31ea1fedc6711fd4abfd013ea612978e39",
|
||||
"https://bcr.bazel.build/modules/rules_java/6.4.0/MODULE.bazel": "e986a9fe25aeaa84ac17ca093ef13a4637f6107375f64667a15999f77db6c8f6",
|
||||
"https://bcr.bazel.build/modules/rules_java/6.5.2/MODULE.bazel": "1d440d262d0e08453fa0c4d8f699ba81609ed0e9a9a0f02cd10b3e7942e61e31",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.10.0/MODULE.bazel": "530c3beb3067e870561739f1144329a21c851ff771cd752a49e06e3dc9c2e71a",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.12.2/MODULE.bazel": "579c505165ee757a4280ef83cda0150eea193eed3bef50b1004ba88b99da6de6",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.3.2/MODULE.bazel": "50dece891cfdf1741ea230d001aa9c14398062f2b7c066470accace78e412bc2",
|
||||
"https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe",
|
||||
"https://bcr.bazel.build/modules/rules_java/8.3.2/MODULE.bazel": "7336d5511ad5af0b8615fdc7477535a2e4e723a357b6713af439fe8cf0195017",
|
||||
"https://bcr.bazel.build/modules/rules_java/8.5.1/MODULE.bazel": "d8a9e38cc5228881f7055a6079f6f7821a073df3744d441978e7a43e20226939",
|
||||
@@ -132,9 +136,12 @@
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/5.3/MODULE.bazel": "bf93870767689637164657731849fb887ad086739bd5d360d90007a581d5527d",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/6.1/MODULE.bazel": "75b5fec090dbd46cf9b7d8ea08cf84a0472d92ba3585b476f44c326eda8059c4",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/6.3/MODULE.bazel": "c998e060b85f71e00de5ec552019347c8bca255062c990ac02d051bb80a38df0",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/6.7/MODULE.bazel": "e717beabc4d091ecb2c803c2d341b88590e9116b8bf7947915eeb33aab4f96dd",
|
||||
"https://bcr.bazel.build/modules/rules_jvm_external/6.7/source.json": "5426f412d0a7fc6b611643376c7e4a82dec991491b9ce5cb1cfdd25fe2e92be4",
|
||||
"https://bcr.bazel.build/modules/rules_kotlin/1.9.0/MODULE.bazel": "ef85697305025e5a61f395d4eaede272a5393cee479ace6686dba707de804d59",
|
||||
"https://bcr.bazel.build/modules/rules_kotlin/1.9.6/MODULE.bazel": "d269a01a18ee74d0335450b10f62c9ed81f2321d7958a2934e44272fe82dcef3",
|
||||
"https://bcr.bazel.build/modules/rules_kotlin/1.9.6/source.json": "2faa4794364282db7c06600b7e5e34867a564ae91bda7cae7c29c64e9466b7d5",
|
||||
"https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0",
|
||||
@@ -173,7 +180,9 @@
|
||||
"https://bcr.bazel.build/modules/rules_swift/3.1.2/source.json": "e85761f3098a6faf40b8187695e3de6d97944e98abd0d8ce579cb2daf6319a66",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.7.1/MODULE.bazel": "3548faea4ee5dda5580f9af150e79d0f6aea934fc60c1cc50f4efdd9420759e7",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.7.2/MODULE.bazel": "fc152419aa2ea0f51c29583fab1e8c99ddefd5b3778421845606ee628629e0e5",
|
||||
"https://bcr.bazel.build/modules/stardoc/0.7.2/source.json": "58b029e5e901d6802967754adf0a9056747e8176f017cfe3607c0851f4d42216",
|
||||
"https://bcr.bazel.build/modules/swift_argument_parser/1.3.1.1/MODULE.bazel": "5e463fbfba7b1701d957555ed45097d7f984211330106ccd1352c6e0af0dcf91",
|
||||
@@ -190,7 +199,7 @@
|
||||
"//bun:extensions.bzl%bun": {
|
||||
"general": {
|
||||
"bzlTransitiveDigest": "oLR98WtKDCc+zh7Tvu9jtakNg8q/T1IPE38QR1FEQtI=",
|
||||
"usagesDigest": "NfJgMuTjZXXRLr1/kxxFkS1IKV2UyehFyr3fMvAke/k=",
|
||||
"usagesDigest": "9s+/cJR+wTifjBrio71E10Knd41B08/GmW4I9zJmU64=",
|
||||
"recordedInputs": [
|
||||
"REPO_MAPPING:,bazel_tools bazel_tools"
|
||||
],
|
||||
|
||||
44
README.md
44
README.md
@@ -4,7 +4,6 @@ Bazel rules for bun.
|
||||
|
||||
## Rule reference
|
||||
|
||||
- Published docs site: https://eriyc.github.io/rules_bun/
|
||||
- Generated API docs: [docs/rules.md](docs/rules.md)
|
||||
- Regenerate: `bazel build //docs:rules_md && cp bazel-bin/docs/rules.md docs/rules.md`
|
||||
|
||||
@@ -17,24 +16,24 @@ These steps show how to consume a tagged release of `rules_bun` in a separate Ba
|
||||
In your project's `MODULE.bazel`, add:
|
||||
|
||||
```starlark
|
||||
bazel_dep(name = "rules_bun", version = "0.1.0")
|
||||
bazel_dep(name = "rules_bun", version = "0.0.7")
|
||||
|
||||
archive_override(
|
||||
module_name = "rules_bun",
|
||||
urls = ["https://github.com/Eriyc/rules_bun/archiv0.0.5.tar.gz"],
|
||||
strip_prefix = "rules_bun-v0.1.0",
|
||||
strip_prefix = "rules_bun-v0.0.7",
|
||||
)
|
||||
```
|
||||
|
||||
For channel/pre-release tags (for example `v0.1.0-rc.1`), use the matching folder prefix:
|
||||
For channel/pre-release tags (for example `v0.0.7-rc.1`), use the matching folder prefix:
|
||||
|
||||
```starlark
|
||||
bazel_dep(name = "rules_bun", version = "0.1.0-rc.1")
|
||||
bazel_dep(name = "rules_bun", version = "0.0.7-rc.1")
|
||||
|
||||
archive_override(
|
||||
module_name = "rules_bun",
|
||||
urls = ["https://github.com/Eriyc/rules_bun/archiv0.0.5-rc.1.tar.gz"],
|
||||
strip_prefix = "rules_bun-v0.1.0-rc.1",
|
||||
strip_prefix = "rules_bun-v0.0.7-rc.1",
|
||||
)
|
||||
```
|
||||
|
||||
@@ -79,7 +78,6 @@ load(
|
||||
"bun_binary",
|
||||
"bun_bundle",
|
||||
"bun_dev",
|
||||
"bun_script",
|
||||
"bun_test",
|
||||
"js_library",
|
||||
"ts_library",
|
||||
@@ -112,36 +110,6 @@ bazel test //path/to:your_bun_test
|
||||
|
||||
All `rules_bun` rule-driven Bun invocations pass `--bun`.
|
||||
|
||||
## Package scripts (`bun_script`)
|
||||
|
||||
Use `bun_script` to expose a `package.json` script as a Bazel executable target.
|
||||
|
||||
```starlark
|
||||
load("@rules_bun//bun:defs.bzl", "bun_script")
|
||||
|
||||
bun_script(
|
||||
name = "web_dev",
|
||||
script = "dev",
|
||||
package_json = "package.json",
|
||||
node_modules = "@npm//:node_modules",
|
||||
data = glob([
|
||||
"src/**",
|
||||
"static/**",
|
||||
"vite.config.*",
|
||||
"svelte.config.*",
|
||||
"tsconfig*.json",
|
||||
]),
|
||||
)
|
||||
```
|
||||
|
||||
Run it with:
|
||||
|
||||
```bash
|
||||
bazel run //path/to:web_dev -- --host
|
||||
```
|
||||
|
||||
`bun_script` defaults to running from the directory containing `package.json`, which matches the usual expectations for `vite`, `svelte-kit`, and similar package scripts.
|
||||
|
||||
## Development mode (`bun_dev`)
|
||||
|
||||
Use `bun_dev` for long-running local development with Bun watch mode.
|
||||
@@ -175,7 +143,7 @@ bazel run //path/to:web_dev
|
||||
`bun_binary` and `bun_dev` support `working_dir`:
|
||||
|
||||
- `"workspace"` (default): runs from the Bazel runfiles workspace root.
|
||||
- `"entry_point"`: runs from the nearest ancestor of the entry point that contains `.env` or `package.json` (falls back to the entry point directory).
|
||||
- `"entry_point"`: runs from the entry point file's directory.
|
||||
|
||||
Use `"entry_point"` when Bun should resolve local files such as colocated `.env` files relative to the program directory.
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ bzl_library(
|
||||
"//internal:bun_binary_bzl",
|
||||
"//internal:bun_bundle_bzl",
|
||||
"//internal:bun_dev_bzl",
|
||||
"//internal:bun_script_bzl",
|
||||
"//internal:bun_test_bzl",
|
||||
"//internal:js_library_bzl",
|
||||
],
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
load("//internal:bun_binary.bzl", _bun_binary = "bun_binary")
|
||||
load("//internal:bun_bundle.bzl", _bun_bundle = "bun_bundle")
|
||||
load("//internal:bun_dev.bzl", _bun_dev = "bun_dev")
|
||||
load("//internal:bun_script.bzl", _bun_script = "bun_script")
|
||||
load("//internal:bun_test.bzl", _bun_test = "bun_test")
|
||||
load("//internal:js_library.bzl", _js_library = "js_library", _ts_library = "ts_library")
|
||||
load(":toolchain.bzl", _BunToolchainInfo = "BunToolchainInfo", _bun_toolchain = "bun_toolchain")
|
||||
@@ -12,7 +11,6 @@ visibility("public")
|
||||
bun_binary = _bun_binary
|
||||
bun_bundle = _bun_bundle
|
||||
bun_dev = _bun_dev
|
||||
bun_script = _bun_script
|
||||
bun_test = _bun_test
|
||||
js_library = _js_library
|
||||
ts_library = _ts_library
|
||||
|
||||
@@ -10,7 +10,6 @@ stardoc(
|
||||
"bun_binary",
|
||||
"bun_bundle",
|
||||
"bun_dev",
|
||||
"bun_script",
|
||||
"bun_test",
|
||||
"js_library",
|
||||
"ts_library",
|
||||
|
||||
@@ -26,18 +26,6 @@ Attributes:
|
||||
- `data` (label_list, optional): additional runtime files for dev process.
|
||||
- `working_dir` (string, default: `"workspace"`, values: `"workspace" | "entry_point"`): runtime working directory.
|
||||
|
||||
## bun_script
|
||||
|
||||
Runs a named `package.json` script with Bun as an executable target (`bazel run`).
|
||||
|
||||
Attributes:
|
||||
|
||||
- `script` (string, required): package script name passed to `bun run <script>`.
|
||||
- `package_json` (label, required): `package.json` file containing the named script.
|
||||
- `node_modules` (label, optional): Bun/npm package files in runfiles.
|
||||
- `data` (label_list, optional): additional runtime files for the script.
|
||||
- `working_dir` (string, default: `"package"`, values: `"workspace" | "package"`): runtime working directory.
|
||||
|
||||
## bun_bundle
|
||||
|
||||
Bundles one or more JS/TS entry points with Bun build.
|
||||
|
||||
12
flake.lock
generated
12
flake.lock
generated
@@ -9,16 +9,16 @@
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1772815059,
|
||||
"narHash": "sha256-9Mn8t/a7b43omtmKRsF0HmFpCkNpTsvYEq0y85KLL5s=",
|
||||
"ref": "v2.0.1",
|
||||
"rev": "80cc529de7060e079d89a69d8daaf0347b53d8f9",
|
||||
"revCount": 43,
|
||||
"lastModified": 1772613315,
|
||||
"narHash": "sha256-RlPTOsyfVwuwEzvaMpwS+giOqQa6KQXMuSHyh1bctjk=",
|
||||
"ref": "v1.0.5",
|
||||
"rev": "e445e49baf8b44b385108cd4f26a14d8ccf9fd35",
|
||||
"revCount": 35,
|
||||
"type": "git",
|
||||
"url": "https://git.dgren.dev/eric/nix-flake-lib"
|
||||
},
|
||||
"original": {
|
||||
"ref": "v2.0.1",
|
||||
"ref": "v1.0.5",
|
||||
"type": "git",
|
||||
"url": "https://git.dgren.dev/eric/nix-flake-lib"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.0.1";
|
||||
devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v1.0.5";
|
||||
devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ exports_files([
|
||||
"bun_bundle.bzl",
|
||||
"bun_dev.bzl",
|
||||
"bun_install.bzl",
|
||||
"bun_script.bzl",
|
||||
"bun_test.bzl",
|
||||
"js_library.bzl",
|
||||
])
|
||||
@@ -28,11 +27,6 @@ bzl_library(
|
||||
srcs = ["bun_dev.bzl"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "bun_script_bzl",
|
||||
srcs = ["bun_script.bzl"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "bun_test_bzl",
|
||||
srcs = ["bun_test.bzl"],
|
||||
|
||||
@@ -14,31 +14,14 @@ def _bun_binary_impl(ctx):
|
||||
set -euo pipefail
|
||||
|
||||
runfiles_dir="${{RUNFILES_DIR:-$0.runfiles}}"
|
||||
workspace_root="${{runfiles_dir}}/_main"
|
||||
bun_bin="${{runfiles_dir}}/_main/{bun_short_path}"
|
||||
entry_point="${{runfiles_dir}}/_main/{entry_short_path}"
|
||||
|
||||
resolve_entrypoint_workdir() {{
|
||||
local dir
|
||||
dir="$(dirname "${{entry_point}}")"
|
||||
while [[ "${{dir}}" == "${{workspace_root}}"* ]]; do
|
||||
if [[ -f "${{dir}}/.env" || -f "${{dir}}/package.json" ]]; then
|
||||
echo "${{dir}}"
|
||||
return 0
|
||||
fi
|
||||
if [[ "${{dir}}" == "${{workspace_root}}" ]]; then
|
||||
break
|
||||
fi
|
||||
dir="$(dirname "${{dir}}")"
|
||||
done
|
||||
echo "$(dirname "${{entry_point}}")"
|
||||
}}
|
||||
|
||||
working_dir="{working_dir}"
|
||||
if [[ "${{working_dir}}" == "entry_point" ]]; then
|
||||
cd "$(resolve_entrypoint_workdir)"
|
||||
cd "$(dirname "${{entry_point}}")"
|
||||
else
|
||||
cd "${{workspace_root}}"
|
||||
cd "${{runfiles_dir}}/_main"
|
||||
fi
|
||||
|
||||
exec "${{bun_bin}}" --bun run "${{entry_point}}" "$@"
|
||||
@@ -88,7 +71,7 @@ Use this rule for non-test scripts and CLIs that should run via `bazel run`.
|
||||
"working_dir": attr.string(
|
||||
default = "workspace",
|
||||
values = ["workspace", "entry_point"],
|
||||
doc = "Working directory at runtime: `workspace` root or nearest `entry_point` ancestor containing `.env`/`package.json`.",
|
||||
doc = "Working directory at runtime: `workspace` root or `entry_point` directory.",
|
||||
),
|
||||
},
|
||||
executable = True,
|
||||
|
||||
@@ -15,31 +15,14 @@ def _bun_dev_impl(ctx):
|
||||
set -euo pipefail
|
||||
|
||||
runfiles_dir="${{RUNFILES_DIR:-$0.runfiles}}"
|
||||
workspace_root="${{runfiles_dir}}/_main"
|
||||
bun_bin="${{runfiles_dir}}/_main/{bun_short_path}"
|
||||
entry_point="${{runfiles_dir}}/_main/{entry_short_path}"
|
||||
|
||||
resolve_entrypoint_workdir() {{
|
||||
local dir
|
||||
dir="$(dirname "${{entry_point}}")"
|
||||
while [[ "${{dir}}" == "${{workspace_root}}"* ]]; do
|
||||
if [[ -f "${{dir}}/.env" || -f "${{dir}}/package.json" ]]; then
|
||||
echo "${{dir}}"
|
||||
return 0
|
||||
fi
|
||||
if [[ "${{dir}}" == "${{workspace_root}}" ]]; then
|
||||
break
|
||||
fi
|
||||
dir="$(dirname "${{dir}}")"
|
||||
done
|
||||
echo "$(dirname "${{entry_point}}")"
|
||||
}}
|
||||
|
||||
working_dir="{working_dir}"
|
||||
if [[ "${{working_dir}}" == "entry_point" ]]; then
|
||||
cd "$(resolve_entrypoint_workdir)"
|
||||
cd "$(dirname "${{entry_point}}")"
|
||||
else
|
||||
cd "${{workspace_root}}"
|
||||
cd "${{runfiles_dir}}/_main"
|
||||
fi
|
||||
|
||||
watch_mode="{watch_mode}"
|
||||
@@ -178,7 +161,7 @@ watch/HMR plus optional full restarts on selected file changes.
|
||||
"working_dir": attr.string(
|
||||
default = "workspace",
|
||||
values = ["workspace", "entry_point"],
|
||||
doc = "Working directory at runtime: `workspace` root or nearest `entry_point` ancestor containing `.env`/`package.json`.",
|
||||
doc = "Working directory at runtime: `workspace` root or `entry_point` directory.",
|
||||
),
|
||||
},
|
||||
executable = True,
|
||||
|
||||
@@ -19,6 +19,7 @@ def _select_bun_binary(repository_ctx):
|
||||
|
||||
fail("Unsupported host platform: os={}, arch={}".format(repository_ctx.os.name, repository_ctx.os.arch))
|
||||
|
||||
|
||||
def _bun_install_repository_impl(repository_ctx):
|
||||
package_json = repository_ctx.path(repository_ctx.attr.package_json)
|
||||
bun_lockfile = repository_ctx.path(repository_ctx.attr.bun_lockfile)
|
||||
@@ -59,6 +60,7 @@ stderr:
|
||||
""",
|
||||
)
|
||||
|
||||
|
||||
bun_install_repository = repository_rule(
|
||||
implementation = _bun_install_repository_impl,
|
||||
attrs = {
|
||||
@@ -72,6 +74,9 @@ bun_install_repository = repository_rule(
|
||||
},
|
||||
)
|
||||
|
||||
_bun_install_repository = bun_install_repository
|
||||
|
||||
|
||||
def bun_install(name, package_json, bun_lockfile):
|
||||
"""Create an external repository containing installed node_modules.
|
||||
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
"""Rule for running package.json scripts with Bun."""
|
||||
|
||||
|
||||
def _shell_quote(value):
|
||||
return "'" + value.replace("'", "'\"'\"'") + "'"
|
||||
|
||||
|
||||
def _bun_script_impl(ctx):
|
||||
toolchain = ctx.toolchains["//bun:toolchain_type"]
|
||||
bun_bin = toolchain.bun.bun_bin
|
||||
package_json = ctx.file.package_json
|
||||
|
||||
launcher = ctx.actions.declare_file(ctx.label.name)
|
||||
ctx.actions.write(
|
||||
output = launcher,
|
||||
is_executable = True,
|
||||
content = """#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
runfiles_dir="${{RUNFILES_DIR:-$0.runfiles}}"
|
||||
workspace_root="${{runfiles_dir}}/_main"
|
||||
bun_bin="${{runfiles_dir}}/_main/{bun_short_path}"
|
||||
package_json="${{runfiles_dir}}/_main/{package_json_short_path}"
|
||||
package_dir="$(dirname "${{package_json}}")"
|
||||
|
||||
working_dir="{working_dir}"
|
||||
if [[ "${{working_dir}}" == "package" ]]; then
|
||||
cd "${{package_dir}}"
|
||||
else
|
||||
cd "${{workspace_root}}"
|
||||
fi
|
||||
|
||||
exec "${{bun_bin}}" --bun run {script} "$@"
|
||||
""".format(
|
||||
bun_short_path = bun_bin.short_path,
|
||||
package_json_short_path = package_json.short_path,
|
||||
working_dir = ctx.attr.working_dir,
|
||||
script = _shell_quote(ctx.attr.script),
|
||||
),
|
||||
)
|
||||
|
||||
transitive_files = []
|
||||
if ctx.attr.node_modules:
|
||||
transitive_files.append(ctx.attr.node_modules[DefaultInfo].files)
|
||||
|
||||
runfiles = ctx.runfiles(
|
||||
files = [bun_bin, package_json] + ctx.files.data,
|
||||
transitive_files = depset(transitive = transitive_files),
|
||||
)
|
||||
|
||||
return [
|
||||
DefaultInfo(
|
||||
executable = launcher,
|
||||
runfiles = runfiles,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
bun_script = rule(
|
||||
implementation = _bun_script_impl,
|
||||
doc = """Runs a named `package.json` script with Bun as an executable target.
|
||||
|
||||
Use this rule to expose existing package scripts such as `dev`, `build`, or
|
||||
`check` via `bazel run` without adding wrapper shell scripts.
|
||||
""",
|
||||
attrs = {
|
||||
"script": attr.string(
|
||||
mandatory = True,
|
||||
doc = "Name of the `package.json` script to execute via `bun run <script>`.",
|
||||
),
|
||||
"package_json": attr.label(
|
||||
mandatory = True,
|
||||
allow_single_file = True,
|
||||
doc = "Label of the `package.json` file containing the named script.",
|
||||
),
|
||||
"node_modules": attr.label(
|
||||
doc = "Optional label providing Bun/npm package files in runfiles.",
|
||||
),
|
||||
"data": attr.label_list(
|
||||
allow_files = True,
|
||||
doc = "Additional runtime files required by the script.",
|
||||
),
|
||||
"working_dir": attr.string(
|
||||
default = "package",
|
||||
values = ["workspace", "package"],
|
||||
doc = "Working directory at runtime: Bazel runfiles `workspace` root or the directory containing `package.json`.",
|
||||
),
|
||||
},
|
||||
executable = True,
|
||||
toolchains = ["//bun:toolchain_type"],
|
||||
)
|
||||
@@ -1,9 +1,7 @@
|
||||
"""Lightweight JS/TS source grouping rules."""
|
||||
|
||||
BunSourcesInfo = provider(
|
||||
"Provides transitive sources for Bun libraries.",
|
||||
fields = ["transitive_sources"],
|
||||
)
|
||||
BunSourcesInfo = provider(fields = ["transitive_sources"])
|
||||
|
||||
|
||||
def _bun_library_impl(ctx):
|
||||
transitive_sources = [
|
||||
@@ -20,6 +18,7 @@ def _bun_library_impl(ctx):
|
||||
DefaultInfo(files = all_sources),
|
||||
]
|
||||
|
||||
|
||||
js_library = rule(
|
||||
implementation = _bun_library_impl,
|
||||
doc = "Aggregates JavaScript sources and transitive Bun source dependencies.",
|
||||
|
||||
@@ -57,17 +57,3 @@ sh_test(
|
||||
args = ["$(location :env_cwd_bin)"],
|
||||
data = [":env_cwd_bin"],
|
||||
)
|
||||
|
||||
bun_binary(
|
||||
name = "env_parent_cwd_bin",
|
||||
entry_point = "env_parent/src/main.ts",
|
||||
data = ["env_parent/.env"],
|
||||
working_dir = "entry_point",
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_binary_env_parent_cwd_test",
|
||||
srcs = ["run_parent_env_binary.sh"],
|
||||
args = ["$(location :env_parent_cwd_bin)"],
|
||||
data = [":env_parent_cwd_bin"],
|
||||
)
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
const value = process.env.BUN_ENV_PARENT_TEST ?? "missing";
|
||||
console.log(value);
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
output="$(${binary})"
|
||||
|
||||
if [[ ${output} != "from-parent-dotenv" ]]; then
|
||||
echo "Expected .env value from parent directory, got: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,33 +0,0 @@
|
||||
load("//bun:defs.bzl", "bun_script")
|
||||
load("@rules_shell//shell:sh_test.bzl", "sh_test")
|
||||
|
||||
bun_script(
|
||||
name = "hello_script",
|
||||
script = "hello",
|
||||
package_json = "package.json",
|
||||
data = ["hello.ts"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_script_ts_test",
|
||||
srcs = ["run_script.sh"],
|
||||
args = ["$(location :hello_script)", "hello-script"],
|
||||
data = [":hello_script"],
|
||||
)
|
||||
|
||||
bun_script(
|
||||
name = "env_script",
|
||||
script = "print-env",
|
||||
package_json = "package.json",
|
||||
data = [
|
||||
".env",
|
||||
"env.ts",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_script_package_cwd_test",
|
||||
srcs = ["run_env_script.sh"],
|
||||
args = ["$(location :env_script)"],
|
||||
data = [":env_script"],
|
||||
)
|
||||
@@ -1,2 +0,0 @@
|
||||
const value = process.env.BUN_SCRIPT_ENV_TEST ?? "missing";
|
||||
console.log(value);
|
||||
@@ -1 +0,0 @@
|
||||
console.log("hello-script");
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"name": "script-test",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"hello": "bun ./hello.ts",
|
||||
"print-env": "bun ./env.ts"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
output="$(${binary})"
|
||||
|
||||
if [[ ${output} != "from-dotenv" ]]; then
|
||||
echo "Expected .env value from package directory, got: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
binary="$1"
|
||||
expected="$2"
|
||||
output="$(${binary})"
|
||||
|
||||
if [[ ${output} != "${expected}" ]]; then
|
||||
echo "Unexpected output from ${binary}: ${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user