aspect-build / rules_js

High-performance Bazel rules for running Node.js tools and building JavaScript projects
https://docs.aspect.build/rules/aspect_rules_js
Apache License 2.0
306 stars 106 forks source link

[FR]: Support for other runtimes like Bun #1258

Open pattrickrice opened 1 year ago

pattrickrice commented 1 year ago

What is the current behavior?

Uses NodeJS as runtime.

Describe the feature

This is more a question than a feature request, I didn't see mention of it when searching.

alexeagle commented 1 year ago

We already offer https://gitlab.com/aspect-build/rules_deno so that answers half your question, I'll repurpose your issue for the other half.

we had a couple questions recently about bun, and it does seem feasible to add a small amount of starlark to be able to run their bundler and devserver. I'm not sure if that merits a separate rules_bun or not yet. We need some funding to make it happen.

alexeagle commented 12 months ago

I started some simple experimentation: https://github.com/aspect-build/rules_js/compare/bun

So far the issue is that bun isn't writing to the --outdir that was specified.

SUBCOMMAND: # //examples/bun:run_with_bun [action 'RunBinary examples/bun/out', configuration: d900f2c6675f9abd37dca719ba1580b468bdfd633f18aefa2143fe33f1de18bf, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_alexeagle/deecfabe94c39fb88a37966b779aac74/execroot/aspect_rules_js && \
  exec env - \
    PATH=/bin:/usr/bin:/usr/local/bin \
  bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/bun_darwin_aarch64/bun_exe build examples/bun/a.ts --outdir ./bazel-out/darwin_arm64-fastbuild/bin/examples/bun/out)
# Configuration: d900f2c6675f9abd37dca719ba1580b468bdfd633f18aefa2143fe33f1de18bf
# Execution platform: @local_config_platform//:host
INFO: From RunBinary examples/bun/out:

  ../../../../../../../../../../../../Users/alexeagle/Projects/rules_js/examples/bun/a.js  0.18 KB

[2ms] bundle 1 modules
Target //examples/bun:run_with_bun up-to-date:
  bazel-bin/examples/bun/out
INFO: Elapsed time: 0.106s, Critical Path: 0.02s
INFO: 2 processes: 1 internal, 1 darwin-sandbox.
INFO: Build completed successfully, 2 total actions

alexeagle@MacBook-Pro-8 rules_js % ls bazel-bin/examples/bun/out   # it's empty :(
vkbansal-rubrik commented 5 months ago

I tried using bun as follows but it fails

# BUILD.bazel
load("@npm//:bun/package_json.bzl", bun_bin = "bin")

bun_bin.bin(
  name = "dummy-script",
  args = ["dummy-script.ts"]
)

bun@1.1.9 rules_js@1.42.3

Error: Your package manager doesn't seem to support bun. To use bun, install using the following command: curl -fsSL https://bun.sh/install | bash

> bun@1.1.9 postinstall 
> node install.js

===============================================================
Failure while running lifecycle hook for package 'bun@1.1.9':

  Script:  'postinstall'
  Command: `node install.js`

Stack trace:

Exit status 1