bundlebun 0.5.0.1.3.13-aarch64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +69 -0
- data/LICENSE.txt +98 -0
- data/README.md +225 -0
- data/exe/bundlebun +27 -0
- data/lib/bundlebun/env_path.rb +54 -0
- data/lib/bundlebun/integrations/cssbundling.rb +50 -0
- data/lib/bundlebun/integrations/execjs.rb +46 -0
- data/lib/bundlebun/integrations/jsbundling.rb +50 -0
- data/lib/bundlebun/integrations/vite_ruby.rb +58 -0
- data/lib/bundlebun/integrations.rb +31 -0
- data/lib/bundlebun/platform.rb +19 -0
- data/lib/bundlebun/runner.rb +278 -0
- data/lib/bundlebun/vendor/bun/LICENSE.md +73 -0
- data/lib/bundlebun/vendor/bun/bun +0 -0
- data/lib/bundlebun/version.rb +12 -0
- data/lib/bundlebun.rb +130 -0
- data/lib/tasks/bun.rake +21 -0
- data/lib/tasks/install.rake +305 -0
- data/lib/templates/bundling-rails/bundlebun.rake +10 -0
- data/lib/templates/vite-ruby/bun-vite +13 -0
- data/lib/templates/vite-ruby/vite.json +16 -0
- data/sig/bundlebun/env_path.rbs +8 -0
- data/sig/bundlebun/integrations/cssbundling.rbs +12 -0
- data/sig/bundlebun/integrations/execjs.rbs +7 -0
- data/sig/bundlebun/integrations/jsbundling.rbs +12 -0
- data/sig/bundlebun/integrations/vite_ruby.rbs +12 -0
- data/sig/bundlebun/integrations.rbs +5 -0
- data/sig/bundlebun/platform.rbs +5 -0
- data/sig/bundlebun/runner.rbs +35 -0
- data/sig/bundlebun/version.rbs +3 -0
- data/sig/bundlebun.rbs +18 -0
- metadata +113 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6142fa5f87f08ab0c546236b979120cefe3f131483c39c14bac19b62d837794c
|
|
4
|
+
data.tar.gz: 709ea8c7db3aebbab2e3708a202185926682ed1ea8e5da5d9d6e288dc4881b6e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b9b209bccbac818f68cf8ae5f1b156c5d6a6497e6ec47d2df3172e0721ac5513c5f012e8f440b40465a06176d2cb72146c9e154870c60ba7cdbd25b05836bd31
|
|
7
|
+
data.tar.gz: a7d466831d2e25ecebbed25f19a622e4123c6169d6b902ee5a5fdc1dbb42850f69b253fe08837a3398625eb1fb65ab04888454df8cc6a0497f585c18eddd8196
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
## [0.5.0] - 2026-04-30
|
|
2
|
+
|
|
3
|
+
- Now including Bun builds for `linux-musl` Linux variants [#16].
|
|
4
|
+
- Existing Linux variants are now labeled as `linux-gnu`
|
|
5
|
+
- No code changes.
|
|
6
|
+
|
|
7
|
+
## [0.4.2] - 2026-04-12
|
|
8
|
+
|
|
9
|
+
- It makes no sense to run Bun without arguments, so no-argument `Bundlebun.call` / `exec` / `system` calls now raise `ArgumentError`.
|
|
10
|
+
- `Bundlebun::Runner.binstub_path` and `full_binstub_path` are now memoized, matching the existing pattern used by `binary_path` and `full_directory`. Avoids redundant string and `File.expand_path` work on every integration command build.
|
|
11
|
+
|
|
12
|
+
## [0.4.1] - 2026-03-08
|
|
13
|
+
|
|
14
|
+
- Bun is now executed with argv-safe `exec` / `system` calls instead of flattening arguments into a single string to preserve values with spaces correctly.
|
|
15
|
+
- `rake bun:install:package` and `rake bun:install:procfile` no longer crash in non-interactive environments when stdin is closed.
|
|
16
|
+
|
|
17
|
+
## [0.4.0] - 2026-02-01
|
|
18
|
+
|
|
19
|
+
- `Bundlebun.system(args)` method: runs Bun as a subprocess and returns to Ruby. Returns `true` if Bun exited successfully. Use this when you need to continue executing Ruby code after Bun finishes.
|
|
20
|
+
- Default behaviour remains: `Bundlebun.()` / `Bundlebun.call` / `Bundlebun.exec` all replace the current Ruby process with Bun (never return). This is what binstubs and wrappers use.
|
|
21
|
+
|
|
22
|
+
- ActiveSupport::Notifications instrumentation added. `system.bundlebun` for `Bundlebun.system` calls, `exec.bundlebun` for exec calls (binstubs, wrappers). Payload: `{ command: args }`.
|
|
23
|
+
- Added RBS type signatures for the public API
|
|
24
|
+
|
|
25
|
+
## [0.3.0] - 2026-01-29
|
|
26
|
+
|
|
27
|
+
- New `rake bun:install:package` task: automatically migrates `package.json` scripts to use `bin/bun`. Replaces calls to `bun`, `bunx`, `npx`, `npm run`, `yarn run`, `pnpm run`, and `pnpm exec` with their `bin/bun` equivalents. Asks for confirmation.
|
|
28
|
+
- New `rake bun:install:procfile` task: automatically migrates `Procfile` and `Procfile.*` files to use `bin/bun`. Same as above.
|
|
29
|
+
- Both tasks are automatically invoked by `rake bun:install` when the relevant files are detected.
|
|
30
|
+
|
|
31
|
+
## [0.2.3] - 2025-12-17
|
|
32
|
+
|
|
33
|
+
- Update dependencies
|
|
34
|
+
- Minor documentation changes
|
|
35
|
+
|
|
36
|
+
## [0.2.2] - 2025-12-07
|
|
37
|
+
|
|
38
|
+
- Bundler 4.0 spec fixes
|
|
39
|
+
- Update dependencies
|
|
40
|
+
|
|
41
|
+
## [0.2.1] - 2025-05-28
|
|
42
|
+
|
|
43
|
+
- Update dependencies
|
|
44
|
+
|
|
45
|
+
## [0.2.0] - 2025-01-30
|
|
46
|
+
|
|
47
|
+
- It is now recommended to include `gem bundlebun` after other existing frontend-related gems in your `Gemfile`. That removes the need to install one-liner initializer monkeypatches for most cases. The gem detects and loads all integrations when loaded. Alternatively, the developer can call integration monkey-patches (`Bundlebun::Integrations::Something.bun!`) directly.
|
|
48
|
+
- bundlebun now adds the bundled bun executable to `PATH`, both on Unix-like and Windows environments. This improves the support for other frontend-related libraries and gems: we don't have to monkey-patch libraries _all the time_, just when we need it.
|
|
49
|
+
- While there still might be some issues, I am trying to ensure proper Windows (non-WSL) support for this gem, for a plug&play experience for Windows Ruby developers.
|
|
50
|
+
- The vite-ruby integration is reworked. We don't touch the existing `bin/vite` binstub anymore. Instead, we install `bin/bun-vite` that will run Vite with Bun and use it with ruby-vite's `vite.json`. We modify the existing config file, or install a sample one.
|
|
51
|
+
- The `bun:install:rails` Rake task is now `bun:install:bundling-rails`, as it only activates from `bun:install` if Cssbundling or Jsbundling are detected, does not have to do a lot with Rails itself.
|
|
52
|
+
- For Windows, the gem now installs a `bin/bun.cmd` binstub, as well as `bin/bun-vite.cmd` for use with vite-ruby. If the integration was already installed, but there are no Windows binstubs in sight, run `rake bun:install` again.
|
|
53
|
+
- The ExecJS test is now a proper integration test, like the other integration tests.
|
|
54
|
+
- bundlebun is now properly tested on Windows (Windows Server 2025 on GitHub Actions).
|
|
55
|
+
|
|
56
|
+
## [0.1.2] - 2024-12-21
|
|
57
|
+
|
|
58
|
+
- Integration specs now test bundlebun + Bun against vite-ruby and cssbundling-rails + jsbundling-rails with positive real-world scenarios
|
|
59
|
+
- Minor internal task changes
|
|
60
|
+
- No major code changes
|
|
61
|
+
|
|
62
|
+
## [0.1.1] - 2024-12-17
|
|
63
|
+
|
|
64
|
+
- Switch to Yard documentation format from RDoc
|
|
65
|
+
- No major code changes
|
|
66
|
+
|
|
67
|
+
## [0.1.0] - 2024-12-15
|
|
68
|
+
|
|
69
|
+
- Initial release
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Yaroslav Markin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Bun is licensed under the MIT License (https://github.com/oven-sh/bun/blob/main/LICENSE.md)
|
|
25
|
+
|
|
26
|
+
Bun itself is MIT-licensed.
|
|
27
|
+
|
|
28
|
+
## JavaScriptCore
|
|
29
|
+
|
|
30
|
+
Bun statically links JavaScriptCore (and WebKit) which is LGPL-2 licensed. WebCore files from WebKit are also licensed under LGPL2. Per LGPL2:
|
|
31
|
+
|
|
32
|
+
> (1) If you statically link against an LGPL’d library, you must also provide your application in an object (not necessarily source) format, so that a user has the opportunity to modify the library and relink the application.
|
|
33
|
+
|
|
34
|
+
You can find the patched version of WebKit used by Bun here: <https://github.com/oven-sh/webkit>. If you would like to relink Bun with changes:
|
|
35
|
+
|
|
36
|
+
- `git submodule update --init --recursive`
|
|
37
|
+
- `make jsc`
|
|
38
|
+
- `zig build`
|
|
39
|
+
|
|
40
|
+
This compiles JavaScriptCore, compiles Bun’s `.cpp` bindings for JavaScriptCore (which are the object files using JavaScriptCore) and outputs a new `bun` binary with your changes.
|
|
41
|
+
|
|
42
|
+
## Linked libraries
|
|
43
|
+
|
|
44
|
+
Bun statically links these libraries:
|
|
45
|
+
|
|
46
|
+
| Library | License |
|
|
47
|
+
|---------|---------|
|
|
48
|
+
| [`boringssl`](https://boringssl.googlesource.com/boringssl/) | [several licenses](https://boringssl.googlesource.com/boringssl/+/refs/heads/master/LICENSE) |
|
|
49
|
+
| [`brotli`](https://github.com/google/brotli) | MIT |
|
|
50
|
+
| [`libarchive`](https://github.com/libarchive/libarchive) | [several licenses](https://github.com/libarchive/libarchive/blob/master/COPYING) |
|
|
51
|
+
| [`lol-html`](https://github.com/cloudflare/lol-html/tree/master/c-api) | BSD 3-Clause |
|
|
52
|
+
| [`mimalloc`](https://github.com/microsoft/mimalloc) | MIT |
|
|
53
|
+
| [`picohttp`](https://github.com/h2o/picohttpparser) | dual-licensed under the Perl License or the MIT License |
|
|
54
|
+
| [`zstd`](https://github.com/facebook/zstd) | dual-licensed under the BSD License or GPLv2 license |
|
|
55
|
+
| [`simdutf`](https://github.com/simdutf/simdutf) | Apache 2.0 |
|
|
56
|
+
| [`tinycc`](https://github.com/tinycc/tinycc) | LGPL v2.1 |
|
|
57
|
+
| [`uSockets`](https://github.com/uNetworking/uSockets) | Apache 2.0 |
|
|
58
|
+
| [`zlib-cloudflare`](https://github.com/cloudflare/zlib) | zlib |
|
|
59
|
+
| [`c-ares`](https://github.com/c-ares/c-ares) | MIT licensed |
|
|
60
|
+
| [`libicu`](https://github.com/unicode-org/icu) 72 | [license here](https://github.com/unicode-org/icu/blob/main/icu4c/LICENSE) |
|
|
61
|
+
| [`libbase64`](https://github.com/aklomp/base64/blob/master/LICENSE) | BSD 2-Clause |
|
|
62
|
+
| [`libuv`](https://github.com/libuv/libuv) (on Windows) | MIT |
|
|
63
|
+
| [`libdeflate`](https://github.com/ebiggers/libdeflate) | MIT |
|
|
64
|
+
| A fork of [`uWebsockets`](https://github.com/jarred-sumner/uwebsockets) | Apache 2.0 licensed |
|
|
65
|
+
| Parts of [Tigerbeetle's IO code](https://github.com/tigerbeetle/tigerbeetle/blob/532c8b70b9142c17e07737ab6d3da68d7500cbca/src/io/windows.zig#L1) | Apache 2.0 licensed |
|
|
66
|
+
|
|
67
|
+
## Polyfills
|
|
68
|
+
|
|
69
|
+
For compatibility reasons, the following packages are embedded into Bun's binary and injected if imported.
|
|
70
|
+
|
|
71
|
+
| Package | License |
|
|
72
|
+
|---------|---------|
|
|
73
|
+
| [`assert`](https://npmjs.com/package/assert) | MIT |
|
|
74
|
+
| [`browserify-zlib`](https://npmjs.com/package/browserify-zlib) | MIT |
|
|
75
|
+
| [`buffer`](https://npmjs.com/package/buffer) | MIT |
|
|
76
|
+
| [`constants-browserify`](https://npmjs.com/package/constants-browserify) | MIT |
|
|
77
|
+
| [`crypto-browserify`](https://npmjs.com/package/crypto-browserify) | MIT |
|
|
78
|
+
| [`domain-browser`](https://npmjs.com/package/domain-browser) | MIT |
|
|
79
|
+
| [`events`](https://npmjs.com/package/events) | MIT |
|
|
80
|
+
| [`https-browserify`](https://npmjs.com/package/https-browserify) | MIT |
|
|
81
|
+
| [`os-browserify`](https://npmjs.com/package/os-browserify) | MIT |
|
|
82
|
+
| [`path-browserify`](https://npmjs.com/package/path-browserify) | MIT |
|
|
83
|
+
| [`process`](https://npmjs.com/package/process) | MIT |
|
|
84
|
+
| [`punycode`](https://npmjs.com/package/punycode) | MIT |
|
|
85
|
+
| [`querystring-es3`](https://npmjs.com/package/querystring-es3) | MIT |
|
|
86
|
+
| [`stream-browserify`](https://npmjs.com/package/stream-browserify) | MIT |
|
|
87
|
+
| [`stream-http`](https://npmjs.com/package/stream-http) | MIT |
|
|
88
|
+
| [`string_decoder`](https://npmjs.com/package/string_decoder) | MIT |
|
|
89
|
+
| [`timers-browserify`](https://npmjs.com/package/timers-browserify) | MIT |
|
|
90
|
+
| [`tty-browserify`](https://npmjs.com/package/tty-browserify) | MIT |
|
|
91
|
+
| [`url`](https://npmjs.com/package/url) | MIT |
|
|
92
|
+
| [`util`](https://npmjs.com/package/util) | MIT |
|
|
93
|
+
| [`vm-browserify`](https://npmjs.com/package/vm-browserify) | MIT |
|
|
94
|
+
|
|
95
|
+
## Additional credits
|
|
96
|
+
|
|
97
|
+
- Bun's JS transpiler, CSS lexer, and Node.js module resolver source code is a Zig port of [@evanw](https://github.com/evanw)’s [esbuild](https://github.com/evanw/esbuild) project.
|
|
98
|
+
- Credit to [@kipply](https://github.com/kipply) for the name "Bun"!
|
data/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# bundlebun
|
|
2
|
+
|
|
3
|
+
**bundlebun** bundles [Bun](https://bun.sh)—the all-in-one JavaScript runtime, package manager, and build tool—directly into your Ruby gem bundle. No Docker, no `curl | sh`, no Homebrew required.
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<img src="https://raw.githubusercontent.com/yaroslav/bundlebun/refs/heads/main/assets/mr-bundlebun-512.png" width="256" height="256" alt="Mr. Bundlebun" title="Mr. Bundlebun">
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
* **Zero setup.** `bundle add bundlebun && rake bun:install` and you're done.
|
|
10
|
+
* **Team-friendly.** Everyone runs the same Bun version, pinned in `Gemfile.lock`.
|
|
11
|
+
* **Auto-updating.** New Bun release? bundlebun ships it automatically. Or freeze your preferred version.
|
|
12
|
+
* **Integrates automatically.** Works out of the box with vite-ruby, cssbundling-rails, jsbundling-rails, and ExecJS.
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
bundle add bundlebun
|
|
16
|
+
rake bun:install
|
|
17
|
+
bin/bun --version
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
[](https://github.com/yaroslav/bundlebun/releases)
|
|
21
|
+
[](https://rubydoc.info/gems/bundlebun)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Table of Contents
|
|
26
|
+
|
|
27
|
+
- [Rationale](#rationale)
|
|
28
|
+
- [Install](#install)
|
|
29
|
+
- [Usage](#usage)
|
|
30
|
+
- [Integrations](#integrations)
|
|
31
|
+
- [Versioning](#versioning)
|
|
32
|
+
- [Uninstall](#uninstall)
|
|
33
|
+
- [Acknowledgements](#acknowledgements)
|
|
34
|
+
- [Contributing](#contributing)
|
|
35
|
+
- [License](#license)
|
|
36
|
+
|
|
37
|
+
## Rationale
|
|
38
|
+
|
|
39
|
+
**Modern frontend setup is needlessly complex** and may involve a lot of maintenance. Developers need _at the very least_ a JavaScript runtime (typically, Node.js), a package manager (could be npm, yarn, or pnpm), and a build tool (Vite, Webpack, esbuild, Parcel—dozens of them).
|
|
40
|
+
|
|
41
|
+
- One way forward is to dockerize development environments, creating unnecessary headaches for the development team—both frontend and backend engineers (especially if the team is not that large and the project is not that complex).
|
|
42
|
+
- Another approach is to declare front-ops bankruptcy and pursue the "no-build" route.
|
|
43
|
+
|
|
44
|
+
**What if we could simplify this?** **Bun** is a **JavaScript runtime**, optimized for speed and developer experience. Bun is _also_ a fast JavaScript **package manager**. Bun is _also_ a **build tool**. Bun is also distributed as a single executable file.
|
|
45
|
+
|
|
46
|
+
However, Bun still requires [some installation](https://bun.sh/docs/installation), and we need to make sure everyone on the team is using the same version.
|
|
47
|
+
|
|
48
|
+
So, how about we just pack it into a Ruby gem as a binary and allow developers to stay updated? Then, we'll be ready every time a new Bun version is out—or the user can freeze their desired version within their Ruby project. There are no setups, large READMEs with instructions, and no enforcing the Docker workflow.
|
|
49
|
+
|
|
50
|
+
**Enter bundlebun**. With a fast JavaScript runtime and a package manager included, you can even skip the build tool and use Bun itself.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
bundlebun gem releases include a binary distribution of Bun for each supported Bun platform (macOS, Linux, Windows) and architecture. bundlebun is tested for Unix-like environments and Windows.
|
|
55
|
+
|
|
56
|
+
Add bundlebun to your `Gemfile`, placing it _after_ your existing frontend-related gems:
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
# Frontend-related gems go here
|
|
60
|
+
# gem "vite_rails"
|
|
61
|
+
|
|
62
|
+
gem "bundlebun"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Then run:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
bundle add bundlebun
|
|
69
|
+
rake bun:install
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`rake bun:install` creates a `bin/bun` binstub and auto-detects which integrations to enable. It will also offer to migrate `package.json` scripts and `Procfile` entries to use `bin/bun`.
|
|
73
|
+
|
|
74
|
+
_If you're seeing a message like `Could not find gems matching 'bundlebun' valid for all resolution platforms (aarch64-linux, aarch64-linux-gnu <...> )`, [check this article](https://github.com/yaroslav/bundlebun/wiki/Could-not-find-gems-matching-'bundlebun'-valid-for-all-resolution-platforms)._
|
|
75
|
+
|
|
76
|
+
_Windows:_ `bin\bun.cmd` is created instead. If you joined a project with only the Unix binstub, run `rake bun:install` again.
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
### Binstub
|
|
81
|
+
|
|
82
|
+
The easiest way to run Bun is via the `bin/bun` binstub:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
bin/bun install
|
|
86
|
+
bin/bun add postcss
|
|
87
|
+
bin/bun run build
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### PATH
|
|
91
|
+
|
|
92
|
+
bundlebun prepends the bundled Bun directory to your application's `PATH`. Tools that detect a `bun` executable (like vite-ruby) find it automatically—no extra configuration needed.
|
|
93
|
+
|
|
94
|
+
### Rake
|
|
95
|
+
|
|
96
|
+
Alternatively, you can use a Rake task. The syntax is far from perfect—that's a limitation of Rake—but it's an option if you cannot install the binstub. Note the quotes around the parameters:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
rake bun[command] # Run bundled Bun with parameters
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
> rake "bun[outdated]"
|
|
104
|
+
bun outdated v1.1.38 (bf2f153f)
|
|
105
|
+
...
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Ruby API
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
Bundlebun.('install') # exec: replaces the current Ruby process with Bun
|
|
112
|
+
Bundlebun.call(['add', 'postcss']) # same thing, array form
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Note:** `Bundlebun.call` (and the `()` shortcut) replaces the current process—it never returns. Use `Bundlebun.system` to run Bun and continue executing Ruby:
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
if Bundlebun.system('install')
|
|
119
|
+
puts 'Dependencies installed!'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
success = Bundlebun.system('test')
|
|
123
|
+
# => true if Bun exited successfully, false or nil otherwise
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
See the [API documentation](https://rubydoc.info/gems/bundlebun) for full details on `Bundlebun::Runner`.
|
|
127
|
+
|
|
128
|
+
### Instrumentation
|
|
129
|
+
|
|
130
|
+
When ActiveSupport is available, bundlebun emits events you can subscribe to:
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
ActiveSupport::Notifications.subscribe('system.bundlebun') do |event|
|
|
134
|
+
Rails.logger.info "Bun: #{event.payload[:command]} (#{event.duration.round(1)}ms)"
|
|
135
|
+
end
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Events: `system.bundlebun` (for `Bundlebun.system`) and `exec.bundlebun` (for `Bundlebun.call`). Payload: `{ command: args }`.
|
|
139
|
+
|
|
140
|
+
## Integrations
|
|
141
|
+
|
|
142
|
+
bundlebun auto-detects and loads integrations when you run `rake bun:install`—as long as `gem "bundlebun"` is placed _after_ the relevant gems in your `Gemfile`.
|
|
143
|
+
|
|
144
|
+
### vite-ruby / vite-rails
|
|
145
|
+
|
|
146
|
+
[vite-ruby](https://github.com/ElMassimo/vite_ruby) and [vite-rails](https://vite-ruby.netlify.app/) are gems that make Ruby and Rails integration with [Vite](https://vite.dev/), a great JavaScript build tool and platform, seamless and easy.
|
|
147
|
+
|
|
148
|
+
The bundlebun integration is installed automatically with `rake bun:install`, or you can run it explicitly:
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
rake bun:install:vite
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
That will make sure you have a `bin/bun` binstub. Next, it installs a custom `bin/bun-vite` binstub to use in build scripts, and creates or updates `vite.json` to use that binstub for building. See the [Vite Ruby configuration manual](https://vite-ruby.netlify.app/config/index.html) for details on `vite.json`.
|
|
155
|
+
|
|
156
|
+
To enable the integration manually:
|
|
157
|
+
|
|
158
|
+
```ruby
|
|
159
|
+
Bundlebun::Integrations::ViteRuby.bun!
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### cssbundling-rails / jsbundling-rails
|
|
163
|
+
|
|
164
|
+
[cssbundling-rails](https://github.com/rails/cssbundling-rails) and [jsbundling-rails](https://github.com/rails/jsbundling-rails) are Rails gems that support the traditional CSS and JS building pipeline for Ruby on Rails.
|
|
165
|
+
|
|
166
|
+
Be sure to check both gems for documentation on bootstrapping your frontend build pipeline instead of duplicating approaches here. cssbundling-rails, for instance, includes an excellent sample build configuration for Bun.
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
# Bootstrap cssbundling-rails
|
|
170
|
+
bundle add cssbundling-rails
|
|
171
|
+
bin/rails css:install:[tailwind|bootstrap|bulma|postcss|sass]
|
|
172
|
+
|
|
173
|
+
# Bootstrap jsbundling-rails
|
|
174
|
+
bundle add jsbundling-rails
|
|
175
|
+
bin/rails javascript:install:bun
|
|
176
|
+
|
|
177
|
+
# Ensure bundlebun integration
|
|
178
|
+
rake bun:install:bundling-rails
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### ExecJS
|
|
182
|
+
|
|
183
|
+
[ExecJS](https://github.com/rails/execjs) runs JavaScript code straight from Ruby. It supports a number of runtimes it can launch—and get a result from. Bun runtime support already exists in ExecJS; bundlebun just ensures it uses the bundled version.
|
|
184
|
+
|
|
185
|
+
Works automatically when bundlebun loads after ExecJS in your `Gemfile`. To enable manually:
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
Bundlebun::Integrations::ExecJS.bun!
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Versioning
|
|
192
|
+
|
|
193
|
+
bundlebun versions follow the `#{gem.version}.#{bun.version}` scheme. For example, `0.1.0.1.1.38` = gem version `0.1.0` + Bun `1.1.38`.
|
|
194
|
+
|
|
195
|
+
New gem versions are published automatically on each Bun release. Lock to a specific Bun version in your `Gemfile`, or leave it unspecified to always get the latest.
|
|
196
|
+
|
|
197
|
+
## Uninstall
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
bundle remove bundlebun
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Then clean up:
|
|
204
|
+
|
|
205
|
+
- `bin/bun` (and `bin\bun.cmd` on Windows)
|
|
206
|
+
- `bin/bun-vite` if present
|
|
207
|
+
- `tasks/bundlebun.rake` if present
|
|
208
|
+
- Any `bin/bun` references in scripts and configs
|
|
209
|
+
- Any `Bundlebun` references in your code
|
|
210
|
+
|
|
211
|
+
## Acknowledgements
|
|
212
|
+
|
|
213
|
+
Bun binaries are sourced directly from [oven-sh/bun releases](https://github.com/oven-sh/bun/releases). [Bun](https://bun.sh) was created by Jarred Sumner ([@jarred-sumner](https://github.com/jarred-sumner)) and distributed under MIT.
|
|
214
|
+
|
|
215
|
+
Big thanks to Jason Meller ([@terracatta](https://github.com/terracatta)) for his work on Bun's Ruby on Rails ecosystem integration—jsbundling-rails, cssbundling-rails, turbo-rails, stimulus-rails, and ExecJS support—in [this Pull Request](https://github.com/rails/rails/pull/49241).
|
|
216
|
+
|
|
217
|
+
## Contributing
|
|
218
|
+
|
|
219
|
+
Make sure you have up-to-date Ruby. Run `bin/setup` to install gems, install [lefthook](https://github.com/evilmartians/lefthook), and run `rake bundlebun:download` to fetch a local Bun build for tests.
|
|
220
|
+
|
|
221
|
+
Run `rake rspec` to check tests. Open an issue or a PR.
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
The gem is available as open source under the terms of the MIT License. See [LICENSE.txt](LICENSE.txt).
|
data/exe/bundlebun
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# Install the gem first, then create a binstub.
|
|
4
|
+
#
|
|
5
|
+
# Add to your Gemfile:
|
|
6
|
+
#
|
|
7
|
+
# gem 'bundlebun'
|
|
8
|
+
#
|
|
9
|
+
# Then:
|
|
10
|
+
#
|
|
11
|
+
# bundle install
|
|
12
|
+
# rake bun:install
|
|
13
|
+
#
|
|
14
|
+
# And then:
|
|
15
|
+
#
|
|
16
|
+
# bin/bun ...
|
|
17
|
+
#
|
|
18
|
+
# If you're looking at this file in your `bin/` directory and you're
|
|
19
|
+
# no longer using bundlebun, it should be safe to delete.
|
|
20
|
+
begin
|
|
21
|
+
require 'bundler/setup'
|
|
22
|
+
rescue LoadError
|
|
23
|
+
# Continue without bundler if not available
|
|
24
|
+
end
|
|
25
|
+
require 'bundlebun'
|
|
26
|
+
|
|
27
|
+
Bundlebun.call(ARGV)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bundlebun
|
|
4
|
+
# EnvPath exists to help prepend the bun binary path to the system PATH,
|
|
5
|
+
# in order to make it easier for other gems and utilities to "see" the
|
|
6
|
+
# existing bun executable without the need to monkey-patch tools that already
|
|
7
|
+
# support Bun.
|
|
8
|
+
# This approach only works when the bundlebun gem is already loaded, which
|
|
9
|
+
# is not always the case, unfortunately.
|
|
10
|
+
class EnvPath
|
|
11
|
+
class << self
|
|
12
|
+
# Returns the current system PATH.
|
|
13
|
+
#
|
|
14
|
+
# @return [String] The system PATH
|
|
15
|
+
def path
|
|
16
|
+
ENV['PATH']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Sets the system PATH to a new value (_not_ prepends the value).
|
|
20
|
+
#
|
|
21
|
+
# @param new_path [String] The new system PATH
|
|
22
|
+
def path=(new_path)
|
|
23
|
+
ENV['PATH'] = new_path
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Prepends a new path to the system PATH.
|
|
27
|
+
# Makes sure to use different separators for different platforms.
|
|
28
|
+
#
|
|
29
|
+
# @param new_path [String] The new path to prepend
|
|
30
|
+
# @return [String] The new system PATH
|
|
31
|
+
def prepend(new_path)
|
|
32
|
+
return if new_path.nil? || new_path.empty?
|
|
33
|
+
|
|
34
|
+
already_present = if Bundlebun::Platform.windows?
|
|
35
|
+
path.downcase.start_with?(new_path.downcase)
|
|
36
|
+
else
|
|
37
|
+
path.start_with?(new_path)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
self.path = "#{new_path}#{separator}#{path}" unless already_present
|
|
41
|
+
path
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The `PATH` separator for the current platform (`:` or `;`)
|
|
45
|
+
#
|
|
46
|
+
# @return [String] The separator character
|
|
47
|
+
def separator
|
|
48
|
+
return @separator if defined?(@separator)
|
|
49
|
+
|
|
50
|
+
@separator = Bundlebun::Platform.windows? ? ';' : ':'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bundlebun
|
|
4
|
+
module Integrations
|
|
5
|
+
# A Bundlebun integration for [cssbundling-rails](https://github.com/rails/cssbundling-rails).
|
|
6
|
+
#
|
|
7
|
+
# It's hard to override those methods on the fly, and a Rails initializer in the
|
|
8
|
+
# target project also does not seem to work, so we have to create a dummy task
|
|
9
|
+
# in the actual Rails project, and patch the helper module Tasks from there.
|
|
10
|
+
#
|
|
11
|
+
# When installed, makes it run a bundled Bun runtime for packing tasks.
|
|
12
|
+
#
|
|
13
|
+
# @see https://github.com/rails/cssbundling-rails
|
|
14
|
+
# @see https://github.com/rails/cssbundling-rails/blob/main/lib/tasks/cssbundling/build.rake
|
|
15
|
+
module Cssbundling
|
|
16
|
+
# Patches the existing module.
|
|
17
|
+
#
|
|
18
|
+
# Call this after everything is loaded and required.
|
|
19
|
+
# For a Rails application, a good place is... _not_ an initializer,
|
|
20
|
+
# but some code that can be run in a Rake task. Like a custom Rake task
|
|
21
|
+
# in `lib/tasks`.
|
|
22
|
+
#
|
|
23
|
+
# See the documentation for more info on installation Rake tasks.
|
|
24
|
+
#
|
|
25
|
+
# @example
|
|
26
|
+
# Bundlebun::Integrations::Cssbundling.bun!
|
|
27
|
+
def self.bun!
|
|
28
|
+
return unless defined?(::Cssbundling::Tasks)
|
|
29
|
+
|
|
30
|
+
::Cssbundling::Tasks.prepend(self::Tasks)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# A monkeypatch for tasks that are defined in the original
|
|
34
|
+
# Rake task
|
|
35
|
+
#
|
|
36
|
+
# @see https://github.com/rails/cssbundling-rails/blob/main/lib/tasks/cssbundling/build.rake
|
|
37
|
+
module Tasks
|
|
38
|
+
extend self
|
|
39
|
+
|
|
40
|
+
def install_command
|
|
41
|
+
"#{Bundlebun::Runner.binstub_or_binary_path} install"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def build_command
|
|
45
|
+
"#{Bundlebun::Runner.binstub_or_binary_path} run --bun build:css"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bundlebun
|
|
4
|
+
module Integrations
|
|
5
|
+
# An integration for [execjs](https://github.com/rails/execjs).
|
|
6
|
+
#
|
|
7
|
+
# Runtimes in ExecJS are declared like this: https://github.com/rails/execjs/blob/master/lib/execjs/runtimes.rb
|
|
8
|
+
# We will redefine the Bun one, changing its command.
|
|
9
|
+
#
|
|
10
|
+
# Then, we will automatically set the bundlebun-ed Bun as the default runtime.
|
|
11
|
+
#
|
|
12
|
+
# @see https://github.com/rails/execjs
|
|
13
|
+
module ExecJS
|
|
14
|
+
# Patches the existing module to use bundlebun-ed Bun in place of an
|
|
15
|
+
# already existing, spported Bun runtime: we replace it with a bundled version.
|
|
16
|
+
#
|
|
17
|
+
# Additionally, sets it as a default ExecJS runtime.
|
|
18
|
+
#
|
|
19
|
+
# Call this after everything is loaded and required.
|
|
20
|
+
# For a Rails application, a good place is an initializer.
|
|
21
|
+
#
|
|
22
|
+
# See the documentation for more info on installation Rake tasks.
|
|
23
|
+
#
|
|
24
|
+
# @example
|
|
25
|
+
# Bundlebun::Integrations::ExecJS.bun!
|
|
26
|
+
def self.bun!
|
|
27
|
+
return unless defined?(::ExecJS::Runtimes)
|
|
28
|
+
|
|
29
|
+
# Remove the existing Bun constant if it exists
|
|
30
|
+
::ExecJS::Runtimes.send(:remove_const, :Bun) if ::ExecJS::Runtimes.const_defined?(:Bun)
|
|
31
|
+
|
|
32
|
+
# Define new Bun runtime with our custom command
|
|
33
|
+
bun_runtime = ::ExecJS::Runtimes.const_set(:Bun,
|
|
34
|
+
::ExecJS::ExternalRuntime.new(
|
|
35
|
+
name: "Bun.sh",
|
|
36
|
+
command: [Bundlebun::Runner.binstub_or_binary_path],
|
|
37
|
+
runner_path: ::ExecJS.root + "/support/bun_runner.js",
|
|
38
|
+
encoding: "UTF-8"
|
|
39
|
+
))
|
|
40
|
+
|
|
41
|
+
# Set the runtime
|
|
42
|
+
::ExecJS.runtime = bun_runtime
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bundlebun
|
|
4
|
+
module Integrations
|
|
5
|
+
# A Bundlebun integration for [jsbundling-rails](https://github.com/rails/jsbundling-rails).
|
|
6
|
+
#
|
|
7
|
+
# It's hard to override those methods on the fly, and a Rails initializer in the
|
|
8
|
+
# target project also does not seem to work, so we have to create a dummy task
|
|
9
|
+
# in the actual Rails project, and patch the helper module Tasks from there.
|
|
10
|
+
#
|
|
11
|
+
# When installed, makes it run a bundled Bun runtime for packing tasks.
|
|
12
|
+
#
|
|
13
|
+
# @see https://github.com/rails/jsbundling-rails
|
|
14
|
+
# @see https://github.com/rails/jsbundling-rails/blob/main/lib/tasks/jsbundling/build.rake
|
|
15
|
+
module Jsbundling
|
|
16
|
+
# Patches the existing module.
|
|
17
|
+
#
|
|
18
|
+
# Call this after everything is loaded and required.
|
|
19
|
+
# For a Rails application, a good place is... not an initializer,
|
|
20
|
+
# but some code that can be run in a Rake task. Like a custom Rake task
|
|
21
|
+
# in `lib/tasks`.
|
|
22
|
+
#
|
|
23
|
+
# See the documentation for more info on installation Rake tasks.
|
|
24
|
+
#
|
|
25
|
+
# @example
|
|
26
|
+
# Bundlebun::Integrations::Jsbundling.bun!
|
|
27
|
+
def self.bun!
|
|
28
|
+
return unless defined?(::Jsbundling::Tasks)
|
|
29
|
+
|
|
30
|
+
::Jsbundling::Tasks.prepend(self::Tasks)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# A monkeypatch for tasks that are defined in the original
|
|
34
|
+
# Rake task
|
|
35
|
+
#
|
|
36
|
+
# @see https://github.com/rails/jsbundling-rails/blob/main/lib/tasks/jsbundling/build.rake
|
|
37
|
+
module Tasks
|
|
38
|
+
extend self
|
|
39
|
+
|
|
40
|
+
def install_command
|
|
41
|
+
"#{Bundlebun::Runner.binstub_or_binary_path} install"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def build_command
|
|
45
|
+
"#{Bundlebun::Runner.binstub_or_binary_path} run --bun build"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|