bundlebun 0.1.0.1.1.38-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +98 -0
- data/README.md +241 -0
- data/exe/bundlebun +28 -0
- data/lib/bundlebun/integrations/cssbundling.rb +42 -0
- data/lib/bundlebun/integrations/execjs.rb +41 -0
- data/lib/bundlebun/integrations/jsbundling.rb +42 -0
- data/lib/bundlebun/integrations/vite_ruby.rb +49 -0
- data/lib/bundlebun/integrations.rb +16 -0
- data/lib/bundlebun/runner.rb +110 -0
- data/lib/bundlebun/vendor/bun/LICENSE.md +73 -0
- data/lib/bundlebun/vendor/bun/bun.exe +0 -0
- data/lib/bundlebun/version.rb +5 -0
- data/lib/bundlebun.rb +51 -0
- data/lib/tasks/bun.rake +21 -0
- data/lib/tasks/install.rake +174 -0
- data/lib/templates/execjs/bundlebun-execjs.rb +9 -0
- data/lib/templates/rails/bundlebun.rake +10 -0
- data/lib/templates/vite-ruby/bundlebun-vite.rb +9 -0
- data/lib/templates/vite-ruby/vite +25 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 658d1e09a376e7d6b2d94db58182c3dba921f2d4a3cecef60e43934dfc2dfe86
|
4
|
+
data.tar.gz: bbba581871392a38c26a0b8ab372d677f8636f512db7dae9a632ee2a0319117c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f9249088e9cc5ca370abaa0938e608f78686951ffa7bac755872cd646efdfc0335bbdcab8d20ac9a63a4fe40e5d61ea74fe10a6d9f5ca0e3905ca2ed456c09a8
|
7
|
+
data.tar.gz: aa0fb56c2e36f3b67ecd9800cc099d7989247dc6646e7f9642074c601fa3da9853e73cf2b934cc6adff8a5db602a8c9f8ffd331a1eabb18eb17a931ba2ad4175
|
data/CHANGELOG.md
ADDED
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,241 @@
|
|
1
|
+
# bundlebun
|
2
|
+
|
3
|
+
**bundlebun bundles [Bun](https://bun.sh), a fast JavaScript runtime, package manager, and builder, with your Ruby and Rails applications**. No need to use Docker, devcontainers, `curl ... | sh`, or `brew`.
|
4
|
+
|
5
|
+
## Quickstart
|
6
|
+
|
7
|
+
Within your Ruby or Rails project:
|
8
|
+
|
9
|
+
```sh
|
10
|
+
bundle add bundlebun
|
11
|
+
rake bun:install
|
12
|
+
```
|
13
|
+
|
14
|
+
and then
|
15
|
+
|
16
|
+
```sh
|
17
|
+
bin/bun ...
|
18
|
+
```
|
19
|
+
|
20
|
+
## Rationale
|
21
|
+
|
22
|
+
**Modern frontend setup is needlessly complex** and may involve a lot of setup and 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).
|
23
|
+
|
24
|
+
- 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.
|
25
|
+
- Another is to declare front-ops bankruptcy and pursue the "no-build" route.
|
26
|
+
|
27
|
+
**What if we can simplify?** **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.
|
28
|
+
|
29
|
+
But Bun still requires [some installation](https://bun.sh/docs/installation), and we need to ensure everyone in the team uses the same version.
|
30
|
+
|
31
|
+
How about we just pack it into a Ruby gem as a binary and allow developers to stay updated—every time a new Bun version is out—or freeze their desired version within their Ruby project. There are no setups, large READMEs with instructions, and no enforcing the Docker workflow.
|
32
|
+
|
33
|
+
**Meet bundlebun**. With fast JavaScript runtime and a package manager included you can even skip on the build tool and use Bun itself.
|
34
|
+
|
35
|
+
## Install
|
36
|
+
|
37
|
+
bundlebun gem releases include a binary distribution of Bun for each supported Bun platform (macOS, Linux, Windows) and architectures.
|
38
|
+
|
39
|
+
First, add it to your `Gemfile`:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
gem "bundlebun"
|
43
|
+
```
|
44
|
+
|
45
|
+
and
|
46
|
+
|
47
|
+
```sh
|
48
|
+
bundle install
|
49
|
+
```
|
50
|
+
|
51
|
+
or just
|
52
|
+
|
53
|
+
```sh
|
54
|
+
bundle add bundlebun
|
55
|
+
```
|
56
|
+
|
57
|
+
Next, run
|
58
|
+
|
59
|
+
```sh
|
60
|
+
rake bun:install
|
61
|
+
```
|
62
|
+
|
63
|
+
The task will install a binstub (`bin/bun`) that you can use to run Bun commands: try running `bin/bun` or `bin/bun --version`.
|
64
|
+
|
65
|
+
You should use `bin/bun` in your scripts, including your local runners like `Procfile.dev` or `Procfile`, and `package.json`—if you had a call to `node` or `bun` in the `scripts` section there.
|
66
|
+
|
67
|
+
Next, the Rake task will try to detect the integrations we need to install based on the classes and modules Rake can see in your project. We'll follow with integrations:
|
68
|
+
|
69
|
+
### Integrations
|
70
|
+
|
71
|
+
Running `rake bun:install` tries to detect already-loaded gems and run the corresponding installation tasks.
|
72
|
+
|
73
|
+
Alternatively, you can ensure an integration is loaded and the necessary modules are patched by calling methods that look like `Bundlebun::Integration::IntegrationName.bun!`: more on that below.
|
74
|
+
|
75
|
+
#### Ruby on Rails: cssbundling and jsbundling
|
76
|
+
|
77
|
+
[cssbundling](https://github.com/rails/cssbundling-rails) and [jsbundling](https://github.com/rails/jsbundling-rails) are Rails gems that support the traditional CSS and JS building pipeline for Ruby on Rails.
|
78
|
+
|
79
|
+
Be sure to check both gems on documentation for bootstrapping your frontend build pipeline, as bundlebun supports them instead of duplicating approaches. cssbundling, for instance, includes an excellent sample build configuration for Bun.
|
80
|
+
|
81
|
+
The bundlebun integration would be installed automatically, or you can run
|
82
|
+
|
83
|
+
```sh
|
84
|
+
rake bun:install:rails
|
85
|
+
```
|
86
|
+
|
87
|
+
manually. The task ensures a `bin/bun` binstub and installs an initializer/task of sorts to ensure both build-related gems use our bundled version of Bun.
|
88
|
+
|
89
|
+
Alternatively, you can call
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
Bundlebun::Integrations::Cssbundling.bun!
|
93
|
+
Bundlebun::Integrations::Jsbundling.bun!
|
94
|
+
```
|
95
|
+
|
96
|
+
in one of your project's rakefiles.
|
97
|
+
|
98
|
+
#### vite-ruby and vite-rails
|
99
|
+
|
100
|
+
[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.
|
101
|
+
|
102
|
+
The bundlebun integration would be installed automatically, or you can run
|
103
|
+
|
104
|
+
```sh
|
105
|
+
rake bun:install:vite
|
106
|
+
```
|
107
|
+
|
108
|
+
That will ensure that you have a `bin/bun` binstub.
|
109
|
+
|
110
|
+
Next, we'll install a custom `bin/vite` binstub (otherwise, ruby-vite won't be able to sense bundlebun presence); the original file, if present, would be backed up to `bin/vite-backup`.
|
111
|
+
|
112
|
+
Finally, we'll put an initializer that forces vite-ruby to use bundlebun. Alternatively, you can call
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
Bundlebun::Integrations::ViteRuby.bun!
|
116
|
+
```
|
117
|
+
|
118
|
+
yourself.
|
119
|
+
|
120
|
+
#### ExecJS
|
121
|
+
|
122
|
+
[ExecJS](https://github.com/rails/execjs) runs JavaScript code straight from Ruby. For that, it supports a bunch of runtimes it could launch—and get a result. The Bun runtime already exists for ExecJS, and we just need to ensure it uses the bundled one.
|
123
|
+
|
124
|
+
The bundlebun integration would be installed automatically, or you can run
|
125
|
+
|
126
|
+
```sh
|
127
|
+
rake bun:install:execjs
|
128
|
+
```
|
129
|
+
|
130
|
+
That would create an initializer that would redefine the Bun runtime for ExecJS and force its usage to be the default. Alternatively, you can call
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
Bundlebun::Integrations::ExecJS.bun!
|
134
|
+
```
|
135
|
+
|
136
|
+
### Notes on `gem install`
|
137
|
+
|
138
|
+
bundlebun is designed to be used with Bundler: installed in specific projects, and launched via `bin/bun` or integrations.
|
139
|
+
|
140
|
+
If you install the gem globally, you _won't see the `bun` executable_ as a wrapper for a bundled Bun runtime; instead, it would be called `bundlebun`. This is done to avoid possible conflicts in your `$PATH` with a "real" Bun runtime you might have installed: if Ruby gem-generated binstubs are in that path before your Bun runtime, you won't easily run it. And that is bundlebun is not greedy with the `bun` executable name.
|
141
|
+
|
142
|
+
If you wish to run Bun runtime globally using this gem, a simple symlink or a wrapper script will do, but the gem won't act destructively.
|
143
|
+
|
144
|
+
## Usage
|
145
|
+
|
146
|
+
### Binstub
|
147
|
+
|
148
|
+
The easiest way to interact with bundled Bun is via the binstub at `bin/bun`. It will launch the bundled version of Bun with the arguments provided:
|
149
|
+
|
150
|
+
```sh
|
151
|
+
> bin/bun
|
152
|
+
Bun is a fast JavaScript runtime, package manager, bundler, and test runner. (1.1.38+bf2f153f5)
|
153
|
+
|
154
|
+
Usage: bun <command> [...flags] [...args]
|
155
|
+
|
156
|
+
...
|
157
|
+
```
|
158
|
+
|
159
|
+
### Return codes
|
160
|
+
|
161
|
+
Note that with this or any other option to run Bun, bundlebun will return the error code `127` if the executable is not found.
|
162
|
+
|
163
|
+
### Rake
|
164
|
+
|
165
|
+
Alternatively, you can use a Rake task. The syntax is far from perfect, but that's a limitation of Rake. You need to add quotes around the parameters and put them into square brackets. If you cannot install the binstub, though, might be your option.
|
166
|
+
|
167
|
+
```
|
168
|
+
rake bun[command] # Run bundled Bun with parameters
|
169
|
+
```
|
170
|
+
|
171
|
+
```sh
|
172
|
+
> rake "bun[outdated]"
|
173
|
+
bun outdated v1.1.38 (bf2f153f)
|
174
|
+
...
|
175
|
+
```
|
176
|
+
|
177
|
+
### Ruby
|
178
|
+
|
179
|
+
The easiest way to call Bun from Ruby would be `Bundlebun.call`:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
Bundlebun.call("outdated")
|
183
|
+
Bundlebun.call(["add", "postcss"])
|
184
|
+
```
|
185
|
+
|
186
|
+
Check out the RDoc documentation for `Bundlebun::Runner` for helper methods. Some of the most useful ones:
|
187
|
+
|
188
|
+
- `Bundlebun::Runner.binary_path`: returns the full path to the bundled Bun library.
|
189
|
+
- `Bundlebun::Runner.binary_path_exist?`: checks if that binary even exists.
|
190
|
+
- `Bundlebun::Runner.binstub_exist?`: checks if the binstub exists.
|
191
|
+
- `Bundlebun::Runner.binstub_or_binary_path`: returns the optimal way to run bundled Bun: a path to binstub or a full path to the binary.
|
192
|
+
|
193
|
+
## Versioning
|
194
|
+
|
195
|
+
bundlebun uses the `#{bundlebun.version}.#{bun.version}` versioning scheme.
|
196
|
+
|
197
|
+
Meaning: gem bundlebun version `0.1.0.1.1.38` is a distribution that includes a gem with its own code version `0.1.0` and a Bun runtime with version `1.1.38`.
|
198
|
+
|
199
|
+
bundlebun is supposed to automatically push new gem versions when there is a new Bun release.
|
200
|
+
|
201
|
+
You can lock the exact version number in your `Gemfile`, or leave the version unspecified and update it as you wish.
|
202
|
+
|
203
|
+
## Uninstall
|
204
|
+
|
205
|
+
To uninstall, remove the gem:
|
206
|
+
|
207
|
+
```sh
|
208
|
+
bundle remove bundlebun
|
209
|
+
```
|
210
|
+
|
211
|
+
Or remove it from your `Gemfile`.
|
212
|
+
|
213
|
+
Next, remove the integrations you have in place:
|
214
|
+
|
215
|
+
- `bin/bun`
|
216
|
+
- Delete `bin/vite` if exists or restore it from `bin/vite-backup`
|
217
|
+
- Delete `tasks/bundlebun.rake` if exists
|
218
|
+
- Delete `config/initializers/bundlebun-vite.rb` if exists
|
219
|
+
- Delete `config/initializers/bundlebun-execjs.rb` if exists
|
220
|
+
- Search for `bin/bun` mentions in your code and configs
|
221
|
+
- Search for `Bundlebun` mentions in your code.
|
222
|
+
|
223
|
+
## Acknowledgements
|
224
|
+
|
225
|
+
bundlebun gem downloads contain binary distributions of Bun available directly from https://github.com/oven-sh/bun/releases.
|
226
|
+
|
227
|
+
[Bun](https://bun.sh) was created Jarred Sumner [@jarred-sumner](https://github.com/jarred-sumner) and co. and is distributed under MIT. Check their [LICENSE](https://github.com/oven-sh/bun/blob/main/LICENSE.md).
|
228
|
+
|
229
|
+
Big thanks to Jason Meller [@terracatta](https://github.com/terracatta) for his work on integrating Bun into the Rails ecosystem: jsbundling-rails support, cssbundling-rails support with a proper build configuration, turbo-rails and stimulus-rails support, ExecJS support. See this [Pull Request](https://github.com/rails/rails/pull/49241).
|
230
|
+
|
231
|
+
## Contributing
|
232
|
+
|
233
|
+
Make sure you have up-to-date Ruby. Run `bundle install`. Run `rake bundlebun:download` to fetch a local version of Bun for tests. `rake rspec` to check if all tests pass.
|
234
|
+
|
235
|
+
Open an issue or a PR.
|
236
|
+
|
237
|
+
## License
|
238
|
+
|
239
|
+
The gem is available as open source under the terms of the MIT License.
|
240
|
+
|
241
|
+
See [LICENSE.txt](LICENSE.txt).
|
data/exe/bundlebun
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Install the gem first, then create a binstub.
|
5
|
+
#
|
6
|
+
# Add to your Gemfile:
|
7
|
+
#
|
8
|
+
# gem 'bundlebun'
|
9
|
+
#
|
10
|
+
# Then:
|
11
|
+
#
|
12
|
+
# bundle install
|
13
|
+
# rake bun:install
|
14
|
+
#
|
15
|
+
# And then:
|
16
|
+
#
|
17
|
+
# bin/bun ...
|
18
|
+
#
|
19
|
+
# If you're seeing this in your `bin/` directory and you're
|
20
|
+
# no longer using bundlebun, it should be safe to delete.
|
21
|
+
begin
|
22
|
+
require 'bundler/setup'
|
23
|
+
rescue LoadError
|
24
|
+
# Continue without bundler if not available
|
25
|
+
end
|
26
|
+
require 'bundlebun'
|
27
|
+
|
28
|
+
Bundlebun::Runner.call(ARGV)
|
@@ -0,0 +1,42 @@
|
|
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/blob/main/lib/tasks/cssbundling/build.rake
|
14
|
+
module Cssbundling
|
15
|
+
# Patches the existing module.
|
16
|
+
#
|
17
|
+
# Call this after everything is loaded and required.
|
18
|
+
# For a Rails application, a good place is... not an initializer,
|
19
|
+
# but some code that can be run in a Rake task. Like a custom Rake task
|
20
|
+
# in <tt>lib/tasks</tt>.
|
21
|
+
#
|
22
|
+
# See the documentation for more info on installation Rake tasks.
|
23
|
+
def self.bun!
|
24
|
+
return unless defined?(::Cssbundling::Tasks)
|
25
|
+
|
26
|
+
::Cssbundling::Tasks.prepend(self::Tasks)
|
27
|
+
end
|
28
|
+
|
29
|
+
module Tasks # :nodoc:
|
30
|
+
extend self
|
31
|
+
|
32
|
+
def install_command
|
33
|
+
"#{Bundlebun::Runner.binstub_or_binary_path} install"
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_command
|
37
|
+
"#{Bundlebun::Runner.binstub_or_binary_path} run --bun build:css"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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
|
+
module ExecJS
|
12
|
+
# Patches the existing module to use bundlebun-ed Bun in place of an
|
13
|
+
# already existing, spported Bun runtime: we replace it with a bundled version.
|
14
|
+
#
|
15
|
+
# Additionally, sets it asa default ExecJS runtime.
|
16
|
+
#
|
17
|
+
# Call this after everything is loaded and required.
|
18
|
+
# For a Rails application, a good place is an initializer.
|
19
|
+
#
|
20
|
+
# See the documentation for more info on installation Rake tasks.
|
21
|
+
def self.bun!
|
22
|
+
return unless defined?(::ExecJS::Runtimes)
|
23
|
+
|
24
|
+
# Remove the existing Bun constant if it exists
|
25
|
+
::ExecJS::Runtimes.send(:remove_const, :Bun) if ::ExecJS::Runtimes.const_defined?(:Bun)
|
26
|
+
|
27
|
+
# Define new Bun runtime with our custom command
|
28
|
+
bun_runtime = ::ExecJS::Runtimes.const_set(:Bun,
|
29
|
+
::ExecJS::ExternalRuntime.new(
|
30
|
+
name: "Bun.sh",
|
31
|
+
command: [Bundlebun::Runner.binstub_or_binary_path],
|
32
|
+
runner_path: ::ExecJS.root + "/support/bun_runner.js",
|
33
|
+
encoding: "UTF-8"
|
34
|
+
))
|
35
|
+
|
36
|
+
# Set the runtime
|
37
|
+
::ExecJS.runtime = bun_runtime
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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/blob/main/lib/tasks/jsbundling/build.rake
|
14
|
+
module Jsbundling
|
15
|
+
# Patches the existing module.
|
16
|
+
#
|
17
|
+
# Call this after everything is loaded and required.
|
18
|
+
# For a Rails application, a good place is... not an initializer,
|
19
|
+
# but some code that can be run in a Rake task. Like a custom Rake task
|
20
|
+
# in <tt>lib/tasks</tt>.
|
21
|
+
#
|
22
|
+
# See the documentation for more info on installation Rake tasks.
|
23
|
+
def self.bun!
|
24
|
+
return unless defined?(::Jsbundling::Tasks)
|
25
|
+
|
26
|
+
::Jsbundling::Tasks.prepend(self::Tasks)
|
27
|
+
end
|
28
|
+
|
29
|
+
module Tasks # :nodoc:
|
30
|
+
extend self
|
31
|
+
|
32
|
+
def install_command
|
33
|
+
"#{Bundlebun::Runner.binstub_or_binary_path} install"
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_command
|
37
|
+
"#{Bundlebun::Runner.binstub_or_binary_path} run --bun build"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bundlebun
|
4
|
+
module Integrations
|
5
|
+
# An integration for vite-ruby[https://github.com/ElMassimo/vite_ruby] and vite-rails[https://vite-ruby.netlify.app/].
|
6
|
+
#
|
7
|
+
# For that, we would need both to replace the vite binstub (as <tt>bin/vite</tt>
|
8
|
+
# exists by itself and does not really initialize this gem if it is installed),
|
9
|
+
# and redefine the RunnerExtensions for ViteRuby by calling this patch from
|
10
|
+
# a Rails initializer.
|
11
|
+
# This way, a typical <tt>bin/dev</tt> would work, as well as integration tests.
|
12
|
+
module ViteRuby
|
13
|
+
# Patches the existing module.
|
14
|
+
#
|
15
|
+
# Call this after everything is loaded and required.
|
16
|
+
# For a Rails application, a good place is an initializer.
|
17
|
+
#
|
18
|
+
# See the documentation for more info on installation Rake tasks.
|
19
|
+
def self.bun!
|
20
|
+
return unless defined?(::ViteRuby::Runner)
|
21
|
+
|
22
|
+
::ViteRuby::Runner.prepend(self::RunnerExtensions)
|
23
|
+
end
|
24
|
+
|
25
|
+
module RunnerExtensions # :nodoc:
|
26
|
+
# Internal: Resolves to an executable for Vite.
|
27
|
+
#
|
28
|
+
# We're overloading this to use with bundlebun.
|
29
|
+
def vite_executable(*exec_args)
|
30
|
+
# Should still allow a custom bin path/binstub
|
31
|
+
bin_path = config.vite_bin_path
|
32
|
+
return [bin_path] if bin_path && File.exist?(bin_path)
|
33
|
+
|
34
|
+
# Would be cleaner is to check `if config.package_manager == 'bun'`,
|
35
|
+
# but seems redundant since we're already bundling Bun,
|
36
|
+
# and putting `bun` as a package manager in their vite.json is just
|
37
|
+
# another step for the developer to do.
|
38
|
+
[bun_binstub_path, 'x --bun', *exec_args, 'vite']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Use our binstub if it is installed in the project,
|
42
|
+
# otherwise just use the binary included with the gem.
|
43
|
+
def bun_binstub_path
|
44
|
+
Bundlebun::Runner.binstub_or_binary_path
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Bundlebun
|
2
|
+
# Bundlebun includes several integrations for frontend-related gems and frameworks.
|
3
|
+
#
|
4
|
+
# Usuall, you would need to run a provided Rake task (see the list at <tt>rake -T bun</tt>)
|
5
|
+
# to install any initializers or binstubs you might need.
|
6
|
+
# Then, the provided files will help you to initialise (patch) the code.
|
7
|
+
#
|
8
|
+
# Typically, to call an integration / patch the loaded code, you would need to call
|
9
|
+
# the <tt>bun!</tt> method, like:
|
10
|
+
#
|
11
|
+
# Bundlebun::Integrations::Foobar.bun!
|
12
|
+
#
|
13
|
+
# See the documentation to learn about the supported integrations.
|
14
|
+
module Integrations
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bundlebun
|
4
|
+
# Runner is the class that bundlebun uses to run the bundled Bun executable.
|
5
|
+
#
|
6
|
+
# See Bundlebun.
|
7
|
+
class Runner
|
8
|
+
BINSTUB_PATH = 'bin/bun' # :nodoc:
|
9
|
+
RELATIVE_DIRECTORY = 'lib/bundlebun/vendor/bun' # :nodoc:
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# Runs the Bun runtime with parameters (can be String or Array of strings).
|
13
|
+
#
|
14
|
+
# See Bundlebun::Runner.new, Bundlebun::Runner.call.
|
15
|
+
#
|
16
|
+
# Example:
|
17
|
+
#
|
18
|
+
# Bundlebun.call('--version')
|
19
|
+
# Bundlebun.call(['add', 'postcss'])
|
20
|
+
#
|
21
|
+
# Returns error status <tt>127</tt> if the executable does not exist.
|
22
|
+
def call(...)
|
23
|
+
new(...).call
|
24
|
+
end
|
25
|
+
|
26
|
+
# A relative path to binstub bundlebun usually generates with installation Rake tasks.
|
27
|
+
def binstub_path
|
28
|
+
BINSTUB_PATH
|
29
|
+
end
|
30
|
+
|
31
|
+
# A relative directory path to the bundled Bun executable from the root of the gem.
|
32
|
+
def relative_directory
|
33
|
+
RELATIVE_DIRECTORY
|
34
|
+
end
|
35
|
+
|
36
|
+
# A full directory path to the bundled Bun executable from the root of the gem.
|
37
|
+
def full_directory
|
38
|
+
File.expand_path("../../#{relative_directory}", __dir__)
|
39
|
+
end
|
40
|
+
|
41
|
+
# A full path to the bundled Bun binary we run.
|
42
|
+
def binary_path
|
43
|
+
executable = "bun#{RUBY_PLATFORM.match?(/mingw|mswin/) ? ".exe" : ""}"
|
44
|
+
File.join(full_directory, executable)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Does the bundled Bun binary exist?
|
48
|
+
def binary_path_exist?
|
49
|
+
File.exist?(binary_path)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns the preferred way to run Bun when bundlebun is installed.
|
53
|
+
#
|
54
|
+
# If the binstub is installed (see binstub_path), use the binstub.
|
55
|
+
# If not, use the full binary path for the bundled executable (binary_path).
|
56
|
+
def binstub_or_binary_path
|
57
|
+
binstub_exist? ? binstub_path : binary_path
|
58
|
+
end
|
59
|
+
|
60
|
+
# Does the binstub exist?
|
61
|
+
def binstub_exist?
|
62
|
+
File.exist?(binstub_path)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Intialize the runner with arguments to run the Bun runtime later via call.
|
67
|
+
#
|
68
|
+
# Arguments can be a String or an Array of strings.
|
69
|
+
#
|
70
|
+
# Example:
|
71
|
+
#
|
72
|
+
# Bundlebun::Runner.new('--version')
|
73
|
+
# Bundlebun::Runner.new(['install', 'postcss'])
|
74
|
+
#
|
75
|
+
# Returns error status <tt>127</tt> if the executable does not exist.
|
76
|
+
def initialize(arguments = '')
|
77
|
+
@arguments = arguments
|
78
|
+
end
|
79
|
+
|
80
|
+
# Runs the Bun executable with previously specified arguments.
|
81
|
+
#
|
82
|
+
# Returns error status <tt>127</tt> if the executable does not exist.
|
83
|
+
#
|
84
|
+
# Example:
|
85
|
+
#
|
86
|
+
# r = Bundlebun::Runner.new('--version')
|
87
|
+
# r.call!
|
88
|
+
#
|
89
|
+
# Check other methods of Bundlebun::Runner to see how we determine what to run exactly.
|
90
|
+
def call
|
91
|
+
check_executable!
|
92
|
+
exec(command)
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
attr_reader :arguments
|
98
|
+
|
99
|
+
def check_executable!
|
100
|
+
return if self.class.binary_path_exist?
|
101
|
+
|
102
|
+
Kernel.warn "Unable to run Bun: executable not found at #{self.class.binary_path}"
|
103
|
+
Kernel.exit 127
|
104
|
+
end
|
105
|
+
|
106
|
+
def command
|
107
|
+
[self.class.binary_path, *arguments].join(' ').strip
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
Bun itself is MIT-licensed.
|
2
|
+
|
3
|
+
## JavaScriptCore
|
4
|
+
|
5
|
+
Bun statically links JavaScriptCore (and WebKit) which is LGPL-2 licensed. WebCore files from WebKit are also licensed under LGPL2. Per LGPL2:
|
6
|
+
|
7
|
+
> (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.
|
8
|
+
|
9
|
+
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:
|
10
|
+
|
11
|
+
- `git submodule update --init --recursive`
|
12
|
+
- `make jsc`
|
13
|
+
- `zig build`
|
14
|
+
|
15
|
+
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.
|
16
|
+
|
17
|
+
## Linked libraries
|
18
|
+
|
19
|
+
Bun statically links these libraries:
|
20
|
+
|
21
|
+
| Library | License |
|
22
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
|
23
|
+
| [`boringssl`](https://boringssl.googlesource.com/boringssl/) | [several licenses](https://boringssl.googlesource.com/boringssl/+/refs/heads/master/LICENSE) |
|
24
|
+
| [`brotli`](https://github.com/google/brotli) | MIT |
|
25
|
+
| [`libarchive`](https://github.com/libarchive/libarchive) | [several licenses](https://github.com/libarchive/libarchive/blob/master/COPYING) |
|
26
|
+
| [`lol-html`](https://github.com/cloudflare/lol-html/tree/master/c-api) | BSD 3-Clause |
|
27
|
+
| [`mimalloc`](https://github.com/microsoft/mimalloc) | MIT |
|
28
|
+
| [`picohttp`](https://github.com/h2o/picohttpparser) | dual-licensed under the Perl License or the MIT License |
|
29
|
+
| [`zstd`](https://github.com/facebook/zstd) | dual-licensed under the BSD License or GPLv2 license |
|
30
|
+
| [`simdutf`](https://github.com/simdutf/simdutf) | Apache 2.0 |
|
31
|
+
| [`tinycc`](https://github.com/tinycc/tinycc) | LGPL v2.1 |
|
32
|
+
| [`uSockets`](https://github.com/uNetworking/uSockets) | Apache 2.0 |
|
33
|
+
| [`zlib-cloudflare`](https://github.com/cloudflare/zlib) | zlib |
|
34
|
+
| [`c-ares`](https://github.com/c-ares/c-ares) | MIT licensed |
|
35
|
+
| [`libicu`](https://github.com/unicode-org/icu) 72 | [license here](https://github.com/unicode-org/icu/blob/main/icu4c/LICENSE) |
|
36
|
+
| [`libbase64`](https://github.com/aklomp/base64/blob/master/LICENSE) | BSD 2-Clause |
|
37
|
+
| [`libuv`](https://github.com/libuv/libuv) (on Windows) | MIT |
|
38
|
+
| [`libdeflate`](https://github.com/ebiggers/libdeflate) | MIT |
|
39
|
+
| A fork of [`uWebsockets`](https://github.com/jarred-sumner/uwebsockets) | Apache 2.0 licensed |
|
40
|
+
| Parts of [Tigerbeetle's IO code](https://github.com/tigerbeetle/tigerbeetle/blob/532c8b70b9142c17e07737ab6d3da68d7500cbca/src/io/windows.zig#L1) | Apache 2.0 licensed |
|
41
|
+
|
42
|
+
## Polyfills
|
43
|
+
|
44
|
+
For compatibility reasons, the following packages are embedded into Bun's binary and injected if imported.
|
45
|
+
|
46
|
+
| Package | License |
|
47
|
+
| ------------------------------------------------------------------------ | ------- |
|
48
|
+
| [`assert`](https://npmjs.com/package/assert) | MIT |
|
49
|
+
| [`browserify-zlib`](https://npmjs.com/package/browserify-zlib) | MIT |
|
50
|
+
| [`buffer`](https://npmjs.com/package/buffer) | MIT |
|
51
|
+
| [`constants-browserify`](https://npmjs.com/package/constants-browserify) | MIT |
|
52
|
+
| [`crypto-browserify`](https://npmjs.com/package/crypto-browserify) | MIT |
|
53
|
+
| [`domain-browser`](https://npmjs.com/package/domain-browser) | MIT |
|
54
|
+
| [`events`](https://npmjs.com/package/events) | MIT |
|
55
|
+
| [`https-browserify`](https://npmjs.com/package/https-browserify) | MIT |
|
56
|
+
| [`os-browserify`](https://npmjs.com/package/os-browserify) | MIT |
|
57
|
+
| [`path-browserify`](https://npmjs.com/package/path-browserify) | MIT |
|
58
|
+
| [`process`](https://npmjs.com/package/process) | MIT |
|
59
|
+
| [`punycode`](https://npmjs.com/package/punycode) | MIT |
|
60
|
+
| [`querystring-es3`](https://npmjs.com/package/querystring-es3) | MIT |
|
61
|
+
| [`stream-browserify`](https://npmjs.com/package/stream-browserify) | MIT |
|
62
|
+
| [`stream-http`](https://npmjs.com/package/stream-http) | MIT |
|
63
|
+
| [`string_decoder`](https://npmjs.com/package/string_decoder) | MIT |
|
64
|
+
| [`timers-browserify`](https://npmjs.com/package/timers-browserify) | MIT |
|
65
|
+
| [`tty-browserify`](https://npmjs.com/package/tty-browserify) | MIT |
|
66
|
+
| [`url`](https://npmjs.com/package/url) | MIT |
|
67
|
+
| [`util`](https://npmjs.com/package/util) | MIT |
|
68
|
+
| [`vm-browserify`](https://npmjs.com/package/vm-browserify) | MIT |
|
69
|
+
|
70
|
+
## Additional credits
|
71
|
+
|
72
|
+
- 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.
|
73
|
+
- Credit to [@kipply](https://github.com/kipply) for the name "Bun"!
|
Binary file
|
data/lib/bundlebun.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zeitwerk'
|
4
|
+
|
5
|
+
# bundlebun bundles Bun[https://bun.sh], a fast JavaScript runtime, package manager
|
6
|
+
# and builder, with your Ruby and Rails applications.
|
7
|
+
# No Docker, devcontainers, <tt>curl | sh</tt>, or <tt>brew</tt> needed.
|
8
|
+
#
|
9
|
+
# bundlebun includes binary distributions of Bun for each of the supported
|
10
|
+
# platforms (macOS, Linux, Windows) and architectures.
|
11
|
+
module Bundlebun
|
12
|
+
class << self
|
13
|
+
# Runs the Bun runtime with parameters (can be String or Array of strings).
|
14
|
+
#
|
15
|
+
# A shortcut for Bundlebun::Runner.call.
|
16
|
+
#
|
17
|
+
# Example:
|
18
|
+
#
|
19
|
+
# Bundlebun.call('--version')
|
20
|
+
# Bundlebun.call(['add', 'postcss'])
|
21
|
+
#
|
22
|
+
# Returns error status <tt>127</tt> if the executable does not exist.
|
23
|
+
def call(...)
|
24
|
+
Runner.call(...)
|
25
|
+
end
|
26
|
+
|
27
|
+
def loader # :nodoc:
|
28
|
+
@loader ||= Zeitwerk::Loader.for_gem.tap do |loader|
|
29
|
+
loader.ignore("#{__dir__}/tasks")
|
30
|
+
loader.ignore("#{__dir__}/bundlebun/vendor")
|
31
|
+
loader.ignore("#{__dir__}/templates")
|
32
|
+
|
33
|
+
loader.inflector.inflect('execjs' => 'ExecJS')
|
34
|
+
|
35
|
+
loader.setup
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_tasks # :nodoc:
|
40
|
+
Dir[File.expand_path('tasks/*.rake', __dir__)].each { |task| load task }
|
41
|
+
end
|
42
|
+
|
43
|
+
def bun = 'Bun' # :nodoc:
|
44
|
+
alias_method :bun?, :bun
|
45
|
+
alias_method :bun!, :bun
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Bundlebun.loader
|
50
|
+
|
51
|
+
Bundlebun.load_tasks if defined?(Rake)
|
data/lib/tasks/bun.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
# Rake command/parameter handling is limited, so we
|
6
|
+
# need to use the <tt>[]</tt>-syntax.
|
7
|
+
#
|
8
|
+
# Even when using <tt>--</tt> with something like
|
9
|
+
# <tt>rake bun -- -e 'console.log(1)'</tt>, Rack thinks that
|
10
|
+
# <tt>console.log...</tt> is a task it needs to run, warns about an
|
11
|
+
# error (although still executes known tasks).
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
#
|
15
|
+
# rake "bun[-e 'console.log(2+2)']"
|
16
|
+
#
|
17
|
+
desc 'Run bundled Bun with parameters. Example: rake "bun[build]"'
|
18
|
+
task :bun, [:command] do |_t, args|
|
19
|
+
command = args[:command] || ''
|
20
|
+
Bundlebun::Runner.call(command)
|
21
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
namespace :bun do
|
6
|
+
desc 'Install bundlebun: install binstub and detect frameworks'
|
7
|
+
task 'install' do
|
8
|
+
puts <<~MESSAGE
|
9
|
+
We are now going to install bundlebun. We'll try to detect the frameworks already in use and install integrations for them.
|
10
|
+
|
11
|
+
Don't forget to run `rake -T bun` to learn more about additional installation tasks for integration with Ruby and JavaScript frameworks, or check the documentation.
|
12
|
+
|
13
|
+
Bun.
|
14
|
+
|
15
|
+
MESSAGE
|
16
|
+
|
17
|
+
Rake::Task['bun:install:bin'].invoke
|
18
|
+
|
19
|
+
if defined?(Rails)
|
20
|
+
puts "Rails detected.\n\n"
|
21
|
+
Rake::Task['bun:install:rails'].invoke
|
22
|
+
end
|
23
|
+
|
24
|
+
if defined?(ViteRuby)
|
25
|
+
puts "vite-ruby detected.\n\n"
|
26
|
+
Rake::Task['bun:install:vite'].invoke
|
27
|
+
end
|
28
|
+
|
29
|
+
if defined?(ExecJS)
|
30
|
+
puts "ExecJS detected.\n\n"
|
31
|
+
Rake::Task['bun:install:execjs'].invoke
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Install bundlebun: create `bin/bun` binstub'
|
36
|
+
task 'install:bin' do
|
37
|
+
puts "Installing bin/bun...\n\n"
|
38
|
+
|
39
|
+
source = File.expand_path('../../exe/bundlebun', __dir__)
|
40
|
+
target_dir = 'bin'
|
41
|
+
target = File.join(target_dir, 'bun')
|
42
|
+
|
43
|
+
if File.exist?(target)
|
44
|
+
puts "#{target} already exists."
|
45
|
+
else
|
46
|
+
FileUtils.mkdir_p(target_dir)
|
47
|
+
FileUtils.cp(source, target)
|
48
|
+
FileUtils.chmod(0o755, target)
|
49
|
+
|
50
|
+
puts "Installed binstub at #{target}."
|
51
|
+
end
|
52
|
+
|
53
|
+
puts <<~MESSAGE
|
54
|
+
Try running it directly. Or, replace existing mentions of `bun` with `bin/bun` in your `package.json`, `Procfile` or binstubs and other files.
|
55
|
+
|
56
|
+
Bun.
|
57
|
+
|
58
|
+
MESSAGE
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'Install bundlebun: Rails, cssbundling-rails, jsbundling-rails integration'
|
62
|
+
task 'install:rails' => :install do
|
63
|
+
puts "Installing Rails integration...\n\n"
|
64
|
+
|
65
|
+
assets_rake = File.expand_path('../templates/rails/bundlebun.rake', __dir__)
|
66
|
+
target_dir = 'lib/tasks'
|
67
|
+
target = File.join(target_dir, 'bundlebun.rake')
|
68
|
+
|
69
|
+
if FileUtils.mkdir_p(target_dir) && FileUtils.cp(assets_rake, target)
|
70
|
+
puts "Installed an initializer with overrides for cssbundling-rails and jsbundling-rails at #{target}"
|
71
|
+
else
|
72
|
+
puts "#{target} already exists."
|
73
|
+
end
|
74
|
+
|
75
|
+
puts <<~MESSAGE
|
76
|
+
Install cssbundling-rails [https://github.com/rails/cssbundling-rails] and jsbundling-rails [https://github.com/rails/jsbundling-rails] to get a simple assets pipeline with Rails, powered by Bun.
|
77
|
+
|
78
|
+
Example:
|
79
|
+
|
80
|
+
bundle add cssbundling-rails
|
81
|
+
bin/rails css:install:[tailwind|bootstrap|bulma|postcss|sass]
|
82
|
+
bin/rails css:build
|
83
|
+
|
84
|
+
bundle add jsbundling-rails
|
85
|
+
bin/rails javascript:install:bun
|
86
|
+
|
87
|
+
Those gems enable you to create new Rails templates using Bun, as well as to create a simple build configuration with Bun. Check their READMEs and documentation.
|
88
|
+
|
89
|
+
Be sure to replace `bun` with `bin/bun` in any existing and generated build-related files such as `Procfile` or `Procfile.dev`, `package.json` and others.
|
90
|
+
|
91
|
+
Bun.
|
92
|
+
|
93
|
+
MESSAGE
|
94
|
+
end
|
95
|
+
|
96
|
+
desc 'Install bundlebun: vite-ruby integration'
|
97
|
+
task 'install:vite' => :install do
|
98
|
+
puts "Installing vite-ruby integration...\n\n"
|
99
|
+
|
100
|
+
binstub = File.expand_path('../templates/vite-ruby/vite', __dir__)
|
101
|
+
target_dir = 'bin'
|
102
|
+
initializers_dir = 'config/initializers'
|
103
|
+
target = File.join(target_dir, 'vite')
|
104
|
+
backup = File.join(target_dir, 'vite-backup')
|
105
|
+
initializer = File.expand_path('../templates/vite-ruby/bundlebun-vite.rb', __dir__)
|
106
|
+
initializer_target = File.join(initializers_dir, 'bundlebun-vite.rb')
|
107
|
+
|
108
|
+
if File.exist?(target) && File.read(target).include?('bundlebun')
|
109
|
+
puts "#{target} already exists."
|
110
|
+
elsif File.exist?(target)
|
111
|
+
puts "Copying #{target} to #{backup} for backup"
|
112
|
+
FileUtils.mv(target, backup)
|
113
|
+
|
114
|
+
FileUtils.cp(binstub, target)
|
115
|
+
FileUtils.chmod(0o755, target)
|
116
|
+
puts "Installed a vite-ruby + bundlebun binstub at #{target}"
|
117
|
+
else
|
118
|
+
FileUtils.mkdir_p(target_dir)
|
119
|
+
FileUtils.cp(binstub, target)
|
120
|
+
FileUtils.chmod(0o755, target)
|
121
|
+
puts "Installed a vite-ruby + bundlebun binstub at #{target}"
|
122
|
+
end
|
123
|
+
|
124
|
+
if File.directory?(initializers_dir)
|
125
|
+
if File.exist?(initializer_target)
|
126
|
+
puts "#{initializer_target} already exists."
|
127
|
+
else
|
128
|
+
FileUtils.cp(initializer, initializer_target)
|
129
|
+
puts "Installed a Rails initializer for vite-ruby at #{initializer_target}."
|
130
|
+
end
|
131
|
+
else
|
132
|
+
puts "Directory #{initializers_dir} does not seem to exist; not installing a Rails initializer."
|
133
|
+
end
|
134
|
+
|
135
|
+
puts <<~MESSAGE
|
136
|
+
We've installed a binstub for running vite-ruby with bundlebun enabled at #{target}.
|
137
|
+
vite-ruby should now use this patched binstub to use `bin/bun` with bundlebun as a JavaScript runtime. Additionally, we've tried to install a Rails initializer at
|
138
|
+
#{initializer_target} to help vite-ruby work with bundlebun.
|
139
|
+
|
140
|
+
Be sure to replace `bun` with `bin/bun` in any existing and generated build-related files such as `Procfile` or `Procfile.dev`, `package.json` and others.
|
141
|
+
|
142
|
+
Bun.
|
143
|
+
|
144
|
+
MESSAGE
|
145
|
+
end
|
146
|
+
|
147
|
+
desc 'Install bundlebun: ExecJS integration'
|
148
|
+
task 'install:execjs' => :install do
|
149
|
+
puts "Installing ExecJS integration...\n\n"
|
150
|
+
|
151
|
+
initializers_dir = 'config/initializers'
|
152
|
+
initializer = File.expand_path('../templates/execjs/bundlebun-execjs.rb', __dir__)
|
153
|
+
initializer_target = File.join(initializers_dir, 'bundlebun-execjs.rb')
|
154
|
+
|
155
|
+
if File.directory?(initializers_dir)
|
156
|
+
if File.exist?(initializer_target)
|
157
|
+
puts "#{initializer_target} already exists."
|
158
|
+
else
|
159
|
+
FileUtils.cp(initializer, initializer_target)
|
160
|
+
puts "Installed a Rails initializer for ExecJS at #{initializer_target}."
|
161
|
+
end
|
162
|
+
else
|
163
|
+
puts "Directory #{initializers_dir} does not seem to exist; not installing a Rails initializer."
|
164
|
+
end
|
165
|
+
|
166
|
+
puts <<~MESSAGE
|
167
|
+
We've installed a Rails initializer that re-defines the Bun runtime for ExecJS and
|
168
|
+
sets Bun as a default runtime.
|
169
|
+
|
170
|
+
Bun.
|
171
|
+
|
172
|
+
MESSAGE
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# An initializer for bundlebun's ExecJS integration.
|
2
|
+
#
|
3
|
+
# This introduces ExecJS to the bundlebun'ed version of Bun,
|
4
|
+
# allows it to run Bun from our binstub, and also sets that
|
5
|
+
# version of Bun as a default runtime.
|
6
|
+
#
|
7
|
+
# Safe to delete if you no longer use bundlebun or
|
8
|
+
# not interested in running Bun anymore.
|
9
|
+
Bundlebun::Integrations::ExecJS.bun!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# An initializer of sorts for bundlebun's ExecJS integration.
|
2
|
+
# Can't go to `initializers`, does not trigger that way.
|
3
|
+
#
|
4
|
+
# This forces cssbundling and jsbundling to use a bundlebun'ed
|
5
|
+
# version of Bun for building assets.
|
6
|
+
#
|
7
|
+
# Safe to delete if you no longer use bundlebun or
|
8
|
+
# not interested in running Bun anymore.
|
9
|
+
Bundlebun::Integrations::Cssbundling.bun!
|
10
|
+
Bundlebun::Integrations::Jsbundling.bun!
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# An initializer vite-ruby integration.
|
2
|
+
# We need both this initializer and a custom binstub at `bin/vite`.
|
3
|
+
#
|
4
|
+
# This forces vite-ruby to run bundlebun'ed version of Bun as a
|
5
|
+
# JavaScript runtime.
|
6
|
+
#
|
7
|
+
# Safe to delete if you no longer use bundlebun or
|
8
|
+
# not interested in running Bun anymore.
|
9
|
+
Bundlebun::Integrations::ViteRuby.bun!
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# This is a replacement for the bin/vite binstub for integration
|
5
|
+
# with bundlebun.
|
6
|
+
# We need to patch the binstub, otherwise there is no way to force
|
7
|
+
# ruby-vite that is being run via `bin/vite` to use bundlebun.
|
8
|
+
#
|
9
|
+
# The code below is the code for the original vite-ruby binstub, with
|
10
|
+
# the bundlebun initializer run injected.
|
11
|
+
#
|
12
|
+
# If you had an original `vite` binstub at this place, it should
|
13
|
+
# be at `vite-backup`.
|
14
|
+
|
15
|
+
ENV['RAILS_ENV'] ||= ENV['RACK_ENV']
|
16
|
+
|
17
|
+
require 'bundler/setup'
|
18
|
+
require 'vite_ruby'
|
19
|
+
require 'bundlebun'
|
20
|
+
|
21
|
+
cli = ViteRuby::CLI
|
22
|
+
cli.require_framework_libraries
|
23
|
+
Bundlebun::Integrations::ViteRuby.bun!
|
24
|
+
|
25
|
+
Dry::CLI.new(cli).call
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bundlebun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.1.1.38
|
5
|
+
platform: x64-mingw-ucrt
|
6
|
+
authors:
|
7
|
+
- Yaroslav Markin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zeitwerk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: 'bundlebun bundles Bun, a fast JavaScript runtime, package manager, and
|
28
|
+
builder, with your Ruby and Rails applications. No need to use Docker, devcontainers,
|
29
|
+
`curl | sh`, or `brew`.
|
30
|
+
|
31
|
+
'
|
32
|
+
email:
|
33
|
+
- yaroslav@markin.net
|
34
|
+
executables:
|
35
|
+
- bundlebun
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files:
|
38
|
+
- README.md
|
39
|
+
files:
|
40
|
+
- CHANGELOG.md
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- exe/bundlebun
|
44
|
+
- lib/bundlebun.rb
|
45
|
+
- lib/bundlebun/integrations.rb
|
46
|
+
- lib/bundlebun/integrations/cssbundling.rb
|
47
|
+
- lib/bundlebun/integrations/execjs.rb
|
48
|
+
- lib/bundlebun/integrations/jsbundling.rb
|
49
|
+
- lib/bundlebun/integrations/vite_ruby.rb
|
50
|
+
- lib/bundlebun/runner.rb
|
51
|
+
- lib/bundlebun/vendor/bun/LICENSE.md
|
52
|
+
- lib/bundlebun/vendor/bun/bun.exe
|
53
|
+
- lib/bundlebun/version.rb
|
54
|
+
- lib/tasks/bun.rake
|
55
|
+
- lib/tasks/install.rake
|
56
|
+
- lib/templates/execjs/bundlebun-execjs.rb
|
57
|
+
- lib/templates/rails/bundlebun.rake
|
58
|
+
- lib/templates/vite-ruby/bundlebun-vite.rb
|
59
|
+
- lib/templates/vite-ruby/vite
|
60
|
+
homepage: https://github.com/yaroslav/bundlebun
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
homepage_uri: https://github.com/yaroslav/bundlebun
|
65
|
+
source_code_uri: https://github.com/yaroslav/bundlebun
|
66
|
+
changelog_uri: https://github.com/yaroslav/bundlebun/blob/master/CHANGELOG.md
|
67
|
+
bug_tracker_uri: https://github.com/yaroslav/bundlebun/issues
|
68
|
+
documentation_uri: https://github.com/yaroslav/bundlebun/blob/main/README.md
|
69
|
+
post_install_message: Bun.
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.0.0
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.5.22
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: bundlebun bundles the Bun JavaScript runtime, package manager and build tool,
|
88
|
+
for use with Ruby and Rails
|
89
|
+
test_files: []
|