bundlebun 0.1.0.1.1.38-x86_64-darwin → 0.1.1.1.1.39-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +87 -48
- data/lib/bundlebun/integrations/cssbundling.rb +13 -5
- data/lib/bundlebun/integrations/execjs.rb +7 -2
- data/lib/bundlebun/integrations/jsbundling.rb +12 -4
- data/lib/bundlebun/integrations/vite_ruby.rb +14 -5
- data/lib/bundlebun/integrations.rb +3 -5
- data/lib/bundlebun/runner.rb +45 -23
- data/lib/bundlebun/vendor/bun/bun +0 -0
- data/lib/bundlebun/version.rb +8 -1
- data/lib/bundlebun.rb +18 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e80942d3fc318b9109db27cbecb1f83469d759f1bdd174ff1eafdfbae4f8aa9
|
4
|
+
data.tar.gz: b92540466bba1d8b69019d728a9f2841c0ee6355fe6094b2baaa603f4229fb02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cf387c7e6ab84bd488eedcfdc4536f3a46d8798135018bcfd55ebfc3f5a02ed12b06138fd5481a07ec668525405c9aa9631b35ea226187390ad011bc6d66536
|
7
|
+
data.tar.gz: 7a6f4c60bd67c03ea92c94fe393071a18e476809c8bc5cf62e8cf8ab55af8e9fa5d06af63600c164e7d4edd5e05c6f28c05c680fd69823723eae69234fd1f4cf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,39 +2,50 @@
|
|
2
2
|
|
3
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
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/bundlebun.svg)](https://badge.fury.io/rb/bundlebun)
|
6
|
+
[![Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/gems/bundlebun)
|
7
|
+
|
8
|
+
<div align="center">
|
9
|
+
<img src="https://raw.githubusercontent.com/yaroslav/bundlebun/refs/heads/main/assets/mr-bundlebun-512.png" width="256" height="256" alt="Mr. Bundlebun">
|
10
|
+
</div>
|
11
|
+
|
5
12
|
## Quickstart
|
6
13
|
|
7
|
-
|
14
|
+
Starting with your Ruby or Rails project, no Bun or anything like that required:
|
8
15
|
|
9
16
|
```sh
|
10
17
|
bundle add bundlebun
|
11
18
|
rake bun:install
|
12
19
|
```
|
13
20
|
|
14
|
-
and then
|
21
|
+
and then:
|
15
22
|
|
16
23
|
```sh
|
17
|
-
bin/bun ...
|
24
|
+
> bin/bun ...
|
25
|
+
Bun is a fast JavaScript runtime, package manager, bundler, and test runner. (1.1.38+bf2f153f5)
|
26
|
+
|
27
|
+
Usage: bun <command> [...flags] [...args]
|
28
|
+
...
|
18
29
|
```
|
19
30
|
|
20
31
|
## Rationale
|
21
32
|
|
22
|
-
**Modern frontend setup is needlessly complex** and may involve a lot of
|
33
|
+
**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).
|
23
34
|
|
24
|
-
- One way forward is to dockerize development environments, creating unnecessary headaches for the development team—both frontend and backend engineers
|
25
|
-
- Another is to declare front-ops bankruptcy and pursue the "no-build" route.
|
35
|
+
- 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).
|
36
|
+
- Another approach is to declare front-ops bankruptcy and pursue the "no-build" route.
|
26
37
|
|
27
|
-
**What if we
|
38
|
+
**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.
|
28
39
|
|
29
|
-
|
40
|
+
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.
|
30
41
|
|
31
|
-
|
42
|
+
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.
|
32
43
|
|
33
|
-
**
|
44
|
+
**Enter bundlebun**. With a fast JavaScript runtime and a package manager included, you can even skip the build tool and use Bun itself.
|
34
45
|
|
35
46
|
## Install
|
36
47
|
|
37
|
-
bundlebun gem releases include a binary distribution of Bun for each supported Bun platform (macOS, Linux, Windows) and
|
48
|
+
bundlebun gem releases include a binary distribution of Bun for each supported Bun platform (macOS, Linux, Windows) and architecture.
|
38
49
|
|
39
50
|
First, add it to your `Gemfile`:
|
40
51
|
|
@@ -42,33 +53,50 @@ First, add it to your `Gemfile`:
|
|
42
53
|
gem "bundlebun"
|
43
54
|
```
|
44
55
|
|
45
|
-
and
|
56
|
+
and:
|
46
57
|
|
47
58
|
```sh
|
48
59
|
bundle install
|
49
60
|
```
|
50
61
|
|
51
|
-
or just
|
62
|
+
(or just):
|
52
63
|
|
53
64
|
```sh
|
54
65
|
bundle add bundlebun
|
55
66
|
```
|
56
67
|
|
57
|
-
|
68
|
+
If you're seeing a message like `Could not find gems matching 'bundlebun' valid for all resolution platforms
|
69
|
+
(aarch64-linux, aarch64-linux-gnu <...> )`, this may be [a known issue with Bundler/`Gemfile.lock`](https://www.google.com/search?client=firefox-b-d&q=Could+not+find+gems+matching+all+resolution+platforms) which you can fix. Open `Gemfile.lock` in your text editor, find a section called `PLATFORMS`, and alter a list of platforms you need to support. This can be a good default for most if you're targeting Linux and macOS (for Windows, also leave entries with `x64_mingw`):
|
70
|
+
|
71
|
+
```
|
72
|
+
(rest of the file here)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
aarch64-linux
|
76
|
+
arm64-darwin
|
77
|
+
x86_64-darwin
|
78
|
+
x86_64-linux
|
79
|
+
|
80
|
+
(rest of the file here)
|
81
|
+
```
|
82
|
+
|
83
|
+
... and try `bundle install` again.
|
84
|
+
|
85
|
+
Next, run:
|
58
86
|
|
59
87
|
```sh
|
60
88
|
rake bun:install
|
61
89
|
```
|
62
90
|
|
63
|
-
The task will install a binstub (`bin/bun`) that you can use to run Bun commands
|
91
|
+
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
92
|
|
65
93
|
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
94
|
|
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
|
95
|
+
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 continue with integrations.
|
68
96
|
|
69
97
|
### Integrations
|
70
98
|
|
71
|
-
|
99
|
+
`rake bun:install` will detect already-loaded gems and run the corresponding installation tasks.
|
72
100
|
|
73
101
|
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
102
|
|
@@ -76,58 +104,69 @@ Alternatively, you can ensure an integration is loaded and the necessary modules
|
|
76
104
|
|
77
105
|
[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
106
|
|
79
|
-
Be sure to check both gems
|
107
|
+
Be sure to check both gems for documentation on 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
108
|
|
81
|
-
|
109
|
+
To quote their READMEs, try this for cssbundling:
|
110
|
+
|
111
|
+
```sh
|
112
|
+
bundle add cssbundling-rails
|
113
|
+
bin/rails css:install:[tailwind|bootstrap|bulma|postcss|sass]
|
114
|
+
bin/rails css:build
|
115
|
+
```
|
116
|
+
|
117
|
+
and this jsbundling:
|
118
|
+
|
119
|
+
```sh
|
120
|
+
bundle add jsbundling-rails
|
121
|
+
bin/rails javascript:install:bun
|
122
|
+
```
|
123
|
+
|
124
|
+
To install the bundlebun integration, run
|
82
125
|
|
83
126
|
```sh
|
84
127
|
rake bun:install:rails
|
85
128
|
```
|
86
129
|
|
87
|
-
|
130
|
+
The task makes sure a `bin/bun` binstub exists and installs an initializer/task of sorts to ensure both build-related gems use our bundled version of Bun.
|
88
131
|
|
89
|
-
Alternatively, you can call
|
132
|
+
Alternatively, you can call the following in one of your project's rakefiles:
|
90
133
|
|
91
134
|
```ruby
|
92
135
|
Bundlebun::Integrations::Cssbundling.bun!
|
93
136
|
Bundlebun::Integrations::Jsbundling.bun!
|
94
137
|
```
|
95
138
|
|
96
|
-
in one of your project's rakefiles.
|
97
|
-
|
98
139
|
#### vite-ruby and vite-rails
|
99
140
|
|
100
141
|
[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
142
|
|
102
|
-
The bundlebun integration would be installed automatically, or you can run
|
143
|
+
The bundlebun integration would be installed automatically, or you can run:
|
103
144
|
|
104
145
|
```sh
|
105
146
|
rake bun:install:vite
|
106
147
|
```
|
107
148
|
|
108
|
-
That will
|
149
|
+
That will make sure you have a `bin/bun` binstub.
|
109
150
|
|
110
151
|
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
152
|
|
112
|
-
Finally, we'll put an initializer that forces vite-ruby to use bundlebun. Alternatively, you can call
|
153
|
+
Finally, we'll put an initializer that forces vite-ruby to use bundlebun. Alternatively, you can call this yourself:
|
113
154
|
|
114
155
|
```ruby
|
115
156
|
Bundlebun::Integrations::ViteRuby.bun!
|
116
157
|
```
|
117
158
|
|
118
|
-
yourself.
|
119
|
-
|
120
159
|
#### ExecJS
|
121
160
|
|
122
|
-
[ExecJS](https://github.com/rails/execjs) runs JavaScript code straight from Ruby.
|
161
|
+
[ExecJS](https://github.com/rails/execjs) runs JavaScript code straight from Ruby. To do so, it supports a bunch of runtimes it can launch—and get a result. The Bun runtime already exists for ExecJS; we just need to ensure it uses the bundled one.
|
123
162
|
|
124
|
-
The bundlebun integration
|
163
|
+
The bundlebun integration can be installed automatically, or you can run:
|
125
164
|
|
126
165
|
```sh
|
127
166
|
rake bun:install:execjs
|
128
167
|
```
|
129
168
|
|
130
|
-
|
169
|
+
This will create an initializer to redefine the Bun runtime for ExecJS and force its usage to be default. Alternatively, you can call:
|
131
170
|
|
132
171
|
```ruby
|
133
172
|
Bundlebun::Integrations::ExecJS.bun!
|
@@ -137,15 +176,15 @@ Bundlebun::Integrations::ExecJS.bun!
|
|
137
176
|
|
138
177
|
bundlebun is designed to be used with Bundler: installed in specific projects, and launched via `bin/bun` or integrations.
|
139
178
|
|
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`.
|
179
|
+
If you install the gem globally, you _won't see the `bun` executable_ as a wrapper for a Ruby-bundled Bun runtime; instead, it would be called `bundlebun`.
|
141
180
|
|
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.
|
181
|
+
This naming discrepency is to avoid possible conflicts in your `$PATH` if you have an independent Bun runtime installed: if the directory with Ruby gem-generated binstubs is in your `$PATH` before the directory with your Bun runtime, running `bun` will launch the bundlebun's version, causing a lot of confusion. And that is why bundlebun is _not_ greedy with the `bun` executable name. 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
182
|
|
144
183
|
## Usage
|
145
184
|
|
146
185
|
### Binstub
|
147
186
|
|
148
|
-
The easiest way to interact with bundled Bun is via the binstub at `bin/bun
|
187
|
+
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
188
|
|
150
189
|
```sh
|
151
190
|
> bin/bun
|
@@ -158,7 +197,7 @@ Usage: bun <command> [...flags] [...args]
|
|
158
197
|
|
159
198
|
### Return codes
|
160
199
|
|
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.
|
200
|
+
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
201
|
|
163
202
|
### Rake
|
164
203
|
|
@@ -176,14 +215,16 @@ bun outdated v1.1.38 (bf2f153f)
|
|
176
215
|
|
177
216
|
### Ruby
|
178
217
|
|
218
|
+
**Check bundlebun API: https://rubydoc.info/gems/bundlebun**.
|
219
|
+
|
179
220
|
The easiest way to call Bun from Ruby would be `Bundlebun.call`:
|
180
221
|
|
181
222
|
```ruby
|
182
|
-
Bundlebun.call("outdated")
|
183
|
-
Bundlebun.call(["add", "postcss"])
|
223
|
+
Bundlebun.call("outdated") # => `bun outdated`
|
224
|
+
Bundlebun.call(["add", "postcss"]) # => `bun add postcss`
|
184
225
|
```
|
185
226
|
|
186
|
-
Check out the
|
227
|
+
Check out the [API documentation](https://rubydoc.info/gems/bundlebun) on `Bundlebun::Runner` for helper methods. Some of the most useful ones:
|
187
228
|
|
188
229
|
- `Bundlebun::Runner.binary_path`: returns the full path to the bundled Bun library.
|
189
230
|
- `Bundlebun::Runner.binary_path_exist?`: checks if that binary even exists.
|
@@ -192,13 +233,9 @@ Check out the RDoc documentation for `Bundlebun::Runner` for helper methods. Som
|
|
192
233
|
|
193
234
|
## Versioning
|
194
235
|
|
195
|
-
bundlebun uses the `#{bundlebun.version}.#{bun.version}` versioning scheme.
|
236
|
+
bundlebun uses the `#{bundlebun.version}.#{bun.version}` versioning scheme. 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`.
|
196
237
|
|
197
|
-
|
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.
|
238
|
+
bundlebun is designed to automatically push new gem versions when there is a new Bun release. That said, you can lock the exact version number in your `Gemfile`, or leave the version unspecified and update it as you wish.
|
202
239
|
|
203
240
|
## Uninstall
|
204
241
|
|
@@ -208,7 +245,7 @@ To uninstall, remove the gem:
|
|
208
245
|
bundle remove bundlebun
|
209
246
|
```
|
210
247
|
|
211
|
-
Or remove it from your `Gemfile
|
248
|
+
Or remove it from your `Gemfile` and run bundler.
|
212
249
|
|
213
250
|
Next, remove the integrations you have in place:
|
214
251
|
|
@@ -224,13 +261,15 @@ Next, remove the integrations you have in place:
|
|
224
261
|
|
225
262
|
bundlebun gem downloads contain binary distributions of Bun available directly from https://github.com/oven-sh/bun/releases.
|
226
263
|
|
227
|
-
[Bun](https://bun.sh) was created Jarred Sumner [@jarred-sumner](https://github.com/jarred-sumner)
|
264
|
+
[Bun](https://bun.sh) was created by Jarred Sumner [@jarred-sumner](https://github.com/jarred-sumner) & co. and is distributed under MIT. Check their [LICENSE](https://github.com/oven-sh/bun/blob/main/LICENSE.md).
|
228
265
|
|
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).
|
266
|
+
Big thanks to Jason Meller [@terracatta](https://github.com/terracatta) for his work on integrating Bun into the Ruby on 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
267
|
|
231
268
|
## Contributing
|
232
269
|
|
233
|
-
Make sure you have up-to-date Ruby. Run `
|
270
|
+
Make sure you have up-to-date Ruby. Run `bin/setup` to install the nesessary gems, install [lefthook](https://github.com/evilmartians/lefthook) and run `rake bundlebun:download` to fetch a local version of Bun for tests.
|
271
|
+
|
272
|
+
`rake rspec` to check if all tests pass.
|
234
273
|
|
235
274
|
Open an issue or a PR.
|
236
275
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Bundlebun
|
4
4
|
module Integrations
|
5
|
-
# A Bundlebun integration for cssbundling-rails
|
5
|
+
# A Bundlebun integration for [cssbundling-rails](https://github.com/rails/cssbundling-rails).
|
6
6
|
#
|
7
7
|
# It's hard to override those methods on the fly, and a Rails initializer in the
|
8
8
|
# target project also does not seem to work, so we have to create a dummy task
|
@@ -10,23 +10,31 @@ module Bundlebun
|
|
10
10
|
#
|
11
11
|
# When installed, makes it run a bundled Bun runtime for packing tasks.
|
12
12
|
#
|
13
|
-
#
|
13
|
+
# @see https://github.com/rails/cssbundling-rails
|
14
|
+
# @see https://github.com/rails/cssbundling-rails/blob/main/lib/tasks/cssbundling/build.rake
|
14
15
|
module Cssbundling
|
15
16
|
# Patches the existing module.
|
16
17
|
#
|
17
18
|
# Call this after everything is loaded and required.
|
18
|
-
# For a Rails application, a good place is...
|
19
|
+
# For a Rails application, a good place is... _not_ an initializer,
|
19
20
|
# but some code that can be run in a Rake task. Like a custom Rake task
|
20
|
-
# in
|
21
|
+
# in `lib/tasks`.
|
21
22
|
#
|
22
23
|
# See the documentation for more info on installation Rake tasks.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Bundlebun::Integrations::Cssbundling.bun!
|
23
27
|
def self.bun!
|
24
28
|
return unless defined?(::Cssbundling::Tasks)
|
25
29
|
|
26
30
|
::Cssbundling::Tasks.prepend(self::Tasks)
|
27
31
|
end
|
28
32
|
|
29
|
-
|
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
|
30
38
|
extend self
|
31
39
|
|
32
40
|
def install_command
|
@@ -2,22 +2,27 @@
|
|
2
2
|
|
3
3
|
module Bundlebun
|
4
4
|
module Integrations
|
5
|
-
# An integration for execjs
|
5
|
+
# An integration for [execjs](https://github.com/rails/execjs).
|
6
6
|
#
|
7
7
|
# Runtimes in ExecJS are declared like this: https://github.com/rails/execjs/blob/master/lib/execjs/runtimes.rb
|
8
8
|
# We will redefine the Bun one, changing its command.
|
9
9
|
#
|
10
10
|
# Then, we will automatically set the bundlebun-ed Bun as the default runtime.
|
11
|
+
#
|
12
|
+
# @see https://github.com/rails/execjs
|
11
13
|
module ExecJS
|
12
14
|
# Patches the existing module to use bundlebun-ed Bun in place of an
|
13
15
|
# already existing, spported Bun runtime: we replace it with a bundled version.
|
14
16
|
#
|
15
|
-
# Additionally, sets it
|
17
|
+
# Additionally, sets it as a default ExecJS runtime.
|
16
18
|
#
|
17
19
|
# Call this after everything is loaded and required.
|
18
20
|
# For a Rails application, a good place is an initializer.
|
19
21
|
#
|
20
22
|
# See the documentation for more info on installation Rake tasks.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# Bundlebun::Integrations::ExecJS.bun!
|
21
26
|
def self.bun!
|
22
27
|
return unless defined?(::ExecJS::Runtimes)
|
23
28
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Bundlebun
|
4
4
|
module Integrations
|
5
|
-
# A Bundlebun integration for jsbundling-rails
|
5
|
+
# A Bundlebun integration for [jsbundling-rails](https://github.com/rails/jsbundling-rails).
|
6
6
|
#
|
7
7
|
# It's hard to override those methods on the fly, and a Rails initializer in the
|
8
8
|
# target project also does not seem to work, so we have to create a dummy task
|
@@ -10,23 +10,31 @@ module Bundlebun
|
|
10
10
|
#
|
11
11
|
# When installed, makes it run a bundled Bun runtime for packing tasks.
|
12
12
|
#
|
13
|
-
#
|
13
|
+
# @see https://github.com/rails/jsbundling-rails
|
14
|
+
# @see https://github.com/rails/jsbundling-rails/blob/main/lib/tasks/jsbundling/build.rake
|
14
15
|
module Jsbundling
|
15
16
|
# Patches the existing module.
|
16
17
|
#
|
17
18
|
# Call this after everything is loaded and required.
|
18
19
|
# For a Rails application, a good place is... not an initializer,
|
19
20
|
# but some code that can be run in a Rake task. Like a custom Rake task
|
20
|
-
# in
|
21
|
+
# in `lib/tasks`.
|
21
22
|
#
|
22
23
|
# See the documentation for more info on installation Rake tasks.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Bundlebun::Integrations::Jsbundling.bun!
|
23
27
|
def self.bun!
|
24
28
|
return unless defined?(::Jsbundling::Tasks)
|
25
29
|
|
26
30
|
::Jsbundling::Tasks.prepend(self::Tasks)
|
27
31
|
end
|
28
32
|
|
29
|
-
|
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
|
30
38
|
extend self
|
31
39
|
|
32
40
|
def install_command
|
@@ -2,13 +2,16 @@
|
|
2
2
|
|
3
3
|
module Bundlebun
|
4
4
|
module Integrations
|
5
|
-
# An integration for vite-ruby
|
5
|
+
# An integration for [vite-ruby](https://github.com/ElMassimo/vite_ruby) and [vite-rails](https://vite-ruby.netlify.app).
|
6
6
|
#
|
7
|
-
# For that, we would need both to replace the vite binstub (as
|
7
|
+
# For that, we would need both to replace the vite binstub (as `bin/vite`
|
8
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
|
9
|
+
# and redefine the {RunnerExtensions} for ViteRuby by calling this patch from
|
10
10
|
# a Rails initializer.
|
11
|
-
# This way, a typical
|
11
|
+
# This way, a typical `bin/dev` would work, as well as integration tests.
|
12
|
+
#
|
13
|
+
# @see https://github.com/ElMassimo/vite_ruby
|
14
|
+
# @see https://vite-ruby.netlify.app
|
12
15
|
module ViteRuby
|
13
16
|
# Patches the existing module.
|
14
17
|
#
|
@@ -16,13 +19,19 @@ module Bundlebun
|
|
16
19
|
# For a Rails application, a good place is an initializer.
|
17
20
|
#
|
18
21
|
# See the documentation for more info on installation Rake tasks.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# Bundlebun::Integrations::ViteRuby.bun!
|
19
25
|
def self.bun!
|
20
26
|
return unless defined?(::ViteRuby::Runner)
|
21
27
|
|
22
28
|
::ViteRuby::Runner.prepend(self::RunnerExtensions)
|
23
29
|
end
|
24
30
|
|
25
|
-
|
31
|
+
# A monkey-patch for ViteRuby.
|
32
|
+
#
|
33
|
+
# @see https://github.com/ElMassimo/vite_ruby/blob/main/vite_ruby/lib/vite_ruby/runner.rb
|
34
|
+
module RunnerExtensions
|
26
35
|
# Internal: Resolves to an executable for Vite.
|
27
36
|
#
|
28
37
|
# We're overloading this to use with bundlebun.
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module Bundlebun
|
2
2
|
# Bundlebun includes several integrations for frontend-related gems and frameworks.
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# Usually you would need to run a provided Rake task (see the list at `rake -T bun`)
|
5
5
|
# to install any initializers or binstubs you might need.
|
6
|
-
# Then, the provided files will help you to
|
6
|
+
# Then, the provided files will help you to initialize (patch) the code.
|
7
7
|
#
|
8
8
|
# Typically, to call an integration / patch the loaded code, you would need to call
|
9
|
-
# the
|
10
|
-
#
|
11
|
-
# Bundlebun::Integrations::Foobar.bun!
|
9
|
+
# the `bun!` method, like `Bundlebun::Integrations::Foobar.bun!`.
|
12
10
|
#
|
13
11
|
# See the documentation to learn about the supported integrations.
|
14
12
|
module Integrations
|
data/lib/bundlebun/runner.rb
CHANGED
@@ -1,50 +1,66 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Bundlebun
|
4
|
-
# Runner is the class that bundlebun uses to run the bundled Bun executable.
|
4
|
+
# {Runner} is the class that bundlebun uses to run the bundled Bun executable.
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# @see Bundlebun
|
7
7
|
class Runner
|
8
|
-
BINSTUB_PATH = 'bin/bun'
|
9
|
-
RELATIVE_DIRECTORY = 'lib/bundlebun/vendor/bun'
|
8
|
+
BINSTUB_PATH = 'bin/bun'
|
9
|
+
RELATIVE_DIRECTORY = 'lib/bundlebun/vendor/bun'
|
10
10
|
|
11
11
|
class << self
|
12
|
-
# Runs the Bun runtime with parameters
|
12
|
+
# Runs the Bun runtime with parameters.
|
13
13
|
#
|
14
|
-
#
|
14
|
+
# A wrapper for {Bundlebun::Runner.new}, {Bundlebun::Runner.call}.
|
15
15
|
#
|
16
|
-
#
|
16
|
+
# @param arguments [String, Array<String>] Command arguments to pass to Bun
|
17
|
+
# @return [Integer] Exit status code (`127` if executable not found)
|
17
18
|
#
|
18
|
-
#
|
19
|
-
# Bundlebun.call(
|
19
|
+
# @example String as an argument
|
20
|
+
# Bundlebun.call('--version') # => `bun --version`
|
20
21
|
#
|
21
|
-
#
|
22
|
+
# @example Array of strings as an argument
|
23
|
+
# Bundlebun.call(['add', 'postcss']) # => `bun add postcss`
|
24
|
+
#
|
25
|
+
# @see Bundlebun::Runner.new
|
26
|
+
# @see Bundlebun::Runner#call
|
22
27
|
def call(...)
|
23
28
|
new(...).call
|
24
29
|
end
|
25
30
|
|
26
|
-
# A relative path to binstub bundlebun usually generates with installation Rake tasks.
|
31
|
+
# A relative path to binstub that bundlebun usually generates with installation Rake tasks.
|
32
|
+
#
|
33
|
+
# @return [String]
|
27
34
|
def binstub_path
|
28
35
|
BINSTUB_PATH
|
29
36
|
end
|
30
37
|
|
31
38
|
# A relative directory path to the bundled Bun executable from the root of the gem.
|
39
|
+
#
|
40
|
+
# @return [String]
|
32
41
|
def relative_directory
|
33
42
|
RELATIVE_DIRECTORY
|
34
43
|
end
|
35
44
|
|
36
45
|
# A full directory path to the bundled Bun executable from the root of the gem.
|
46
|
+
#
|
47
|
+
# @return [String]
|
37
48
|
def full_directory
|
38
49
|
File.expand_path("../../#{relative_directory}", __dir__)
|
39
50
|
end
|
40
51
|
|
41
|
-
# A full path to the bundled Bun binary we run
|
52
|
+
# A full path to the bundled Bun binary we run
|
53
|
+
# (includes `.exe` on Windows).
|
54
|
+
#
|
55
|
+
# @return [String]
|
42
56
|
def binary_path
|
43
57
|
executable = "bun#{RUBY_PLATFORM.match?(/mingw|mswin/) ? ".exe" : ""}"
|
44
58
|
File.join(full_directory, executable)
|
45
59
|
end
|
46
60
|
|
47
61
|
# Does the bundled Bun binary exist?
|
62
|
+
#
|
63
|
+
# @return [Boolean]
|
48
64
|
def binary_path_exist?
|
49
65
|
File.exist?(binary_path)
|
50
66
|
end
|
@@ -53,40 +69,46 @@ module Bundlebun
|
|
53
69
|
#
|
54
70
|
# If the binstub is installed (see binstub_path), use the binstub.
|
55
71
|
# If not, use the full binary path for the bundled executable (binary_path).
|
72
|
+
#
|
73
|
+
# @return [String]
|
56
74
|
def binstub_or_binary_path
|
57
75
|
binstub_exist? ? binstub_path : binary_path
|
58
76
|
end
|
59
77
|
|
60
78
|
# Does the binstub exist?
|
79
|
+
#
|
80
|
+
# @return [Boolean]
|
61
81
|
def binstub_exist?
|
62
82
|
File.exist?(binstub_path)
|
63
83
|
end
|
64
84
|
end
|
65
85
|
|
66
|
-
# Intialize the
|
86
|
+
# Intialize the {Runner} with arguments to run the Bun runtime later via #call.
|
67
87
|
#
|
68
|
-
#
|
88
|
+
# @param arguments [String, Array<String>] Command arguments to pass to Bun
|
69
89
|
#
|
70
|
-
#
|
90
|
+
# @example String as an argument
|
91
|
+
# Bundlebun::Runner.new('--version') # => `bun --version`
|
71
92
|
#
|
72
|
-
#
|
73
|
-
# Bundlebun::Runner.new(['
|
93
|
+
# @example Array of strings as an argument
|
94
|
+
# Bundlebun::Runner.new(['add', 'postcss']) # => `bun add postcss`
|
74
95
|
#
|
75
|
-
#
|
96
|
+
# @see Bundlebun::Runner#call
|
76
97
|
def initialize(arguments = '')
|
77
98
|
@arguments = arguments
|
78
99
|
end
|
79
100
|
|
80
101
|
# Runs the Bun executable with previously specified arguments.
|
81
102
|
#
|
82
|
-
#
|
103
|
+
# Check other methods of {Bundlebun::Runner} to see how we determine what to run exactly.
|
83
104
|
#
|
84
|
-
#
|
105
|
+
# @return [Integer] Exit status code (`127` if executable not found)
|
85
106
|
#
|
86
|
-
#
|
87
|
-
#
|
107
|
+
# @example
|
108
|
+
# b = Bundlebun::Runner.new('--version')
|
109
|
+
# b.call
|
88
110
|
#
|
89
|
-
#
|
111
|
+
# @see Bundlebun::Runner
|
90
112
|
def call
|
91
113
|
check_executable!
|
92
114
|
exec(command)
|
Binary file
|
data/lib/bundlebun/version.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Bundlebun
|
4
|
-
|
4
|
+
# bundlebun uses the `#{bundlebun.version}.#{bun.version}`
|
5
|
+
# versioning scheme.
|
6
|
+
# gem bundlebun version `0.1.0.1.1.38` is a distribution
|
7
|
+
# that includes a gem with its own code version `0.1.0` and
|
8
|
+
# a Bun runtime with version `1.1.38`.
|
9
|
+
#
|
10
|
+
# This constant always points to the "own" version of the gem.
|
11
|
+
VERSION = '0.1.1'
|
5
12
|
end
|
data/lib/bundlebun.rb
CHANGED
@@ -2,29 +2,36 @@
|
|
2
2
|
|
3
3
|
require 'zeitwerk'
|
4
4
|
|
5
|
-
# bundlebun bundles Bun
|
5
|
+
# bundlebun bundles [Bun](https://bun.sh), a fast JavaScript runtime, package manager
|
6
6
|
# and builder, with your Ruby and Rails applications.
|
7
|
-
# No Docker, devcontainers,
|
7
|
+
# No Docker, devcontainers, `curl | sh`, or `brew` needed.
|
8
8
|
#
|
9
9
|
# bundlebun includes binary distributions of Bun for each of the supported
|
10
10
|
# platforms (macOS, Linux, Windows) and architectures.
|
11
|
+
#
|
12
|
+
# @see Bundlebun::Runner
|
13
|
+
# @see Bundlebun::Integrations
|
11
14
|
module Bundlebun
|
12
15
|
class << self
|
13
|
-
# Runs the Bun runtime with parameters
|
16
|
+
# Runs the Bun runtime with parameters.
|
17
|
+
#
|
18
|
+
# A shortcut for {Bundlebun::Runner.call}.
|
14
19
|
#
|
15
|
-
#
|
20
|
+
# @param arguments [String, Array<String>] Command arguments to pass to Bun
|
21
|
+
# @return [Integer] Exit status code (`127` if executable not found)
|
16
22
|
#
|
17
|
-
#
|
23
|
+
# @example String as an argument
|
24
|
+
# Bundlebun.call('--version') # => `bun --version`
|
18
25
|
#
|
19
|
-
#
|
20
|
-
# Bundlebun.call(['add', 'postcss'])
|
26
|
+
# @example Array of strings as an argument
|
27
|
+
# Bundlebun.call(['add', 'postcss']) # => `bun add postcss`
|
21
28
|
#
|
22
|
-
#
|
29
|
+
# @see Bundlebun::Runner.call
|
23
30
|
def call(...)
|
24
31
|
Runner.call(...)
|
25
32
|
end
|
26
33
|
|
27
|
-
def loader #
|
34
|
+
def loader # @private
|
28
35
|
@loader ||= Zeitwerk::Loader.for_gem.tap do |loader|
|
29
36
|
loader.ignore("#{__dir__}/tasks")
|
30
37
|
loader.ignore("#{__dir__}/bundlebun/vendor")
|
@@ -36,11 +43,11 @@ module Bundlebun
|
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
39
|
-
def load_tasks #
|
46
|
+
def load_tasks # @private
|
40
47
|
Dir[File.expand_path('tasks/*.rake', __dir__)].each { |task| load task }
|
41
48
|
end
|
42
49
|
|
43
|
-
def bun = 'Bun'
|
50
|
+
def bun = 'Bun'
|
44
51
|
alias_method :bun?, :bun
|
45
52
|
alias_method :bun!, :bun
|
46
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bundlebun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1.1.1.39
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- Yaroslav Markin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -65,7 +65,7 @@ metadata:
|
|
65
65
|
source_code_uri: https://github.com/yaroslav/bundlebun
|
66
66
|
changelog_uri: https://github.com/yaroslav/bundlebun/blob/master/CHANGELOG.md
|
67
67
|
bug_tracker_uri: https://github.com/yaroslav/bundlebun/issues
|
68
|
-
documentation_uri: https://
|
68
|
+
documentation_uri: https://rubydoc.info/gems/bundlebun
|
69
69
|
post_install_message: Bun.
|
70
70
|
rdoc_options: []
|
71
71
|
require_paths:
|