bundlebun 0.1.2.1.1.41-arm64-darwin → 0.2.0.1.2.1-arm64-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 +11 -0
- data/README.md +29 -31
- data/exe/bundlebun +1 -2
- data/lib/bundlebun/env_path.rb +51 -0
- data/lib/bundlebun/integrations.rb +15 -0
- data/lib/bundlebun/platform.rb +19 -0
- data/lib/bundlebun/runner.rb +21 -6
- data/lib/bundlebun/vendor/bun/bun +0 -0
- data/lib/bundlebun/version.rb +1 -1
- data/lib/bundlebun.rb +18 -2
- data/lib/tasks/install.rake +64 -65
- data/lib/templates/{rails → bundling-rails}/bundlebun.rake +1 -1
- data/lib/templates/vite-ruby/bun-vite +13 -0
- data/lib/templates/vite-ruby/vite.json +16 -0
- metadata +22 -9
- data/lib/templates/execjs/bundlebun-execjs.rb +0 -9
- data/lib/templates/vite-ruby/bundlebun-vite.rb +0 -9
- data/lib/templates/vite-ruby/vite +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02134a6c5f6ae2cca914220e2496e271f957894a76dcf6e5f1ebf68c30750102
|
4
|
+
data.tar.gz: 6b0b7bbdd36b45840f0127858486d5481b310a968e15ca9e3ff898245881f9b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efcf93277918dc2a442099b96000d51cd3033513db71936ff4a84a38108ff01dd38c0ba1be2c117c755038d0862058598cc3736ba0979f7fe3fe134fe30477ff
|
7
|
+
data.tar.gz: 5e1b4c0ad07b1e87e6315734f2ff57965624338e6a7581bdfda4389c82cef5f00174cf5f4af87e6528d5954f2de73d3b3bb0378760e5fff39f4257253a86db59
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## [0.2.0] - 2025-01-30
|
2
|
+
|
3
|
+
- 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.
|
4
|
+
- 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.
|
5
|
+
- 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.
|
6
|
+
- 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.
|
7
|
+
- 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.
|
8
|
+
- 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.
|
9
|
+
- The ExecJS test is now a proper integration test, like the other integration tests.
|
10
|
+
- bundlebun is now properly tested on Windows (Windows Server 2025 on GitHub Actions).
|
11
|
+
|
1
12
|
## [0.1.2] - 2024-12-21
|
2
13
|
|
3
14
|
- Integration specs now test bundlebun + Bun against vite-ruby and cssbundling-rails + jsbundling-rails with positive real-world scenarios
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
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
|
-
[![
|
5
|
+
[![GitHub Release](https://img.shields.io/github/v/release/yaroslav/bundlebun)](https://github.com/yaroslav/bundlebun/releases)
|
6
6
|
[![Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/gems/bundlebun)
|
7
7
|
|
8
8
|
<div align="center">
|
@@ -45,11 +45,13 @@ So, how about we just pack it into a Ruby gem as a binary and allow developers t
|
|
45
45
|
|
46
46
|
## Install
|
47
47
|
|
48
|
-
bundlebun gem releases include a binary distribution of Bun for each supported Bun platform (macOS, Linux, Windows) and architecture.
|
48
|
+
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.
|
49
49
|
|
50
|
-
First, add it to your `Gemfile
|
50
|
+
First, add it to your `Gemfile`. Make sure to add it _after_ your existing frontend- and build-related librares:
|
51
51
|
|
52
52
|
```ruby
|
53
|
+
# ...
|
54
|
+
|
53
55
|
gem "bundlebun"
|
54
56
|
```
|
55
57
|
|
@@ -92,11 +94,18 @@ The task will install a binstub (`bin/bun`) that you can use to run Bun commands
|
|
92
94
|
|
93
95
|
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.
|
94
96
|
|
97
|
+
_Windows tip:_ If you're on Windows, the `bin\bun.cmd` file will be created. If you've joined an existing project where only the Unix-like binstub exists at that location, just run `rake bun:install` again.
|
98
|
+
|
95
99
|
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.
|
96
100
|
|
101
|
+
**By default, on load, bundlebun:**
|
102
|
+
|
103
|
+
- adds the path to the bundled `bun` executable to the start of your application's `PATH`. That simplifies the integration in cases where we don't really need to monkey-patch a lot of code, and we just need to make sure it "sees" our `bun` executable as available.
|
104
|
+
- tries to detect and load all possible integrations.
|
105
|
+
|
97
106
|
### Integrations
|
98
107
|
|
99
|
-
`
|
108
|
+
Usually, if you've placed `gem 'bundlebun'` after your frontend-related gems in the `Gemfile`, and did `rake bun:install`, the integrations should all be working out of the box.
|
100
109
|
|
101
110
|
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.
|
102
111
|
|
@@ -121,36 +130,27 @@ bundle add jsbundling-rails
|
|
121
130
|
bin/rails javascript:install:bun
|
122
131
|
```
|
123
132
|
|
124
|
-
To
|
133
|
+
To make sure the bundlebun integration is installed (although the default `rake bun:install` should detect everything just fine), run
|
125
134
|
|
126
135
|
```sh
|
127
|
-
rake bun:install:rails
|
136
|
+
rake bun:install:bundling-rails
|
128
137
|
```
|
129
138
|
|
130
|
-
The task makes sure a `bin/bun` binstub exists and installs an
|
131
|
-
|
132
|
-
Alternatively, you can call the following in one of your project's rakefiles:
|
133
|
-
|
134
|
-
```ruby
|
135
|
-
Bundlebun::Integrations::Cssbundling.bun!
|
136
|
-
Bundlebun::Integrations::Jsbundling.bun!
|
137
|
-
```
|
139
|
+
The task makes sure a `bin/bun` binstub exists and installs an Rake task hack of sorts to ensure both build-related gems use our bundled version of Bun.
|
138
140
|
|
139
141
|
#### vite-ruby and vite-rails
|
140
142
|
|
141
143
|
[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.
|
142
144
|
|
143
|
-
The bundlebun integration would be installed automatically
|
145
|
+
The bundlebun integration would be installed automatically with `rake bun:install`, or you can run:
|
144
146
|
|
145
147
|
```sh
|
146
148
|
rake bun:install:vite
|
147
149
|
```
|
148
150
|
|
149
|
-
That will make sure you have a `bin/bun` binstub.
|
150
|
-
|
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`.
|
151
|
+
That will make sure you have a `bin/bun` binstub. Next, we'll install a custom `bin/bun-vite` binstub to use in build scripts. The installer Rake task will create a new `vite.json` file if it does not exist yet, or force the existing one 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`.
|
152
152
|
|
153
|
-
|
153
|
+
Make sure you have `gem bundlebun` mentioned _after_ all the vite-related gems in your `Gemfile`. If you want to keep integrations to a minimum, and only enable them manually, use the following to manually turn on the bundlebun monkey-patching for vite-ruby:
|
154
154
|
|
155
155
|
```ruby
|
156
156
|
Bundlebun::Integrations::ViteRuby.bun!
|
@@ -158,15 +158,11 @@ Bundlebun::Integrations::ViteRuby.bun!
|
|
158
158
|
|
159
159
|
#### ExecJS
|
160
160
|
|
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.
|
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 support already exists for ExecJS; we just need to ensure it uses the bundled one.
|
162
162
|
|
163
|
-
The bundlebun integration
|
163
|
+
The bundlebun integration will work automatically if bundlebun is loaded after ExecJS in the `Gemfile`.
|
164
164
|
|
165
|
-
|
166
|
-
rake bun:install:execjs
|
167
|
-
```
|
168
|
-
|
169
|
-
This will create an initializer to redefine the Bun runtime for ExecJS and force its usage to be default. Alternatively, you can call:
|
165
|
+
Alternatively, you can load the monkey-patch manually:
|
170
166
|
|
171
167
|
```ruby
|
172
168
|
Bundlebun::Integrations::ExecJS.bun!
|
@@ -199,6 +195,10 @@ Usage: bun <command> [...flags] [...args]
|
|
199
195
|
|
200
196
|
Note that with this (or any other option to run Bun), bundlebun will return the error code `127` if the executable is not found.
|
201
197
|
|
198
|
+
### `PATH`
|
199
|
+
|
200
|
+
The bundlebun gem adds the directory with a binary Bun distribution to your `PATH`: prepends it there, to be exact. That helps existing tools that can detect the presence of `bun` executable to find it and work with no further setup or monkey-patching.
|
201
|
+
|
202
202
|
### Rake
|
203
203
|
|
204
204
|
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.
|
@@ -229,7 +229,7 @@ Check out the [API documentation](https://rubydoc.info/gems/bundlebun) on `Bundl
|
|
229
229
|
- `Bundlebun::Runner.binary_path`: returns the full path to the bundled Bun library.
|
230
230
|
- `Bundlebun::Runner.binary_path_exist?`: checks if that binary even exists.
|
231
231
|
- `Bundlebun::Runner.binstub_exist?`: checks if the binstub exists.
|
232
|
-
- `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.
|
232
|
+
- `Bundlebun::Runner.binstub_or_binary_path`: returns the optimal way to run bundled Bun: a full path to binstub or a full path to the binary.
|
233
233
|
|
234
234
|
## Versioning
|
235
235
|
|
@@ -247,13 +247,11 @@ bundle remove bundlebun
|
|
247
247
|
|
248
248
|
Or remove it from your `Gemfile` and run bundler.
|
249
249
|
|
250
|
-
Next, remove the integrations you have in place:
|
250
|
+
Next, remove the integrations you might have in place:
|
251
251
|
|
252
252
|
- `bin/bun`
|
253
|
-
- Delete `bin/vite` if exists
|
253
|
+
- Delete `bin/bun-vite` if exists
|
254
254
|
- Delete `tasks/bundlebun.rake` if exists
|
255
|
-
- Delete `config/initializers/bundlebun-vite.rb` if exists
|
256
|
-
- Delete `config/initializers/bundlebun-execjs.rb` if exists
|
257
255
|
- Search for `bin/bun` mentions in your code and configs
|
258
256
|
- Search for `Bundlebun` mentions in your code.
|
259
257
|
|
data/exe/bundlebun
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
2
|
|
4
3
|
# Install the gem first, then create a binstub.
|
5
4
|
#
|
@@ -16,7 +15,7 @@
|
|
16
15
|
#
|
17
16
|
# bin/bun ...
|
18
17
|
#
|
19
|
-
# If you're
|
18
|
+
# If you're looking at this file in your `bin/` directory and you're
|
20
19
|
# no longer using bundlebun, it should be safe to delete.
|
21
20
|
begin
|
22
21
|
require 'bundler/setup'
|
@@ -0,0 +1,51 @@
|
|
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
|
+
path_to_check = Bundlebun::Platform.windows? ? path.downcase : path
|
35
|
+
check_path = Bundlebun::Platform.windows? ? new_path.downcase : new_path
|
36
|
+
|
37
|
+
self.path = "#{new_path}#{separator}#{path}" unless path_to_check.start_with?(check_path)
|
38
|
+
path
|
39
|
+
end
|
40
|
+
|
41
|
+
# The `PATH` separator for the current platform (`:` or `;`)
|
42
|
+
#
|
43
|
+
# @return [String] The separator character
|
44
|
+
def separator
|
45
|
+
return @separator if defined?(@separator)
|
46
|
+
|
47
|
+
@separator = Bundlebun::Platform.windows? ? ';' : ':'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -10,5 +10,20 @@ module Bundlebun
|
|
10
10
|
#
|
11
11
|
# See the documentation to learn about the supported integrations.
|
12
12
|
module Integrations
|
13
|
+
# Loads and initializes all available integrations. See specific classes
|
14
|
+
# for implementation.
|
15
|
+
#
|
16
|
+
# @return [Array<Module>] List of initialized integrations
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# Bundlebun::Integrations.bun! # => [Bundlebun::Integrations::Cssbundling, ...]
|
20
|
+
def self.bun!
|
21
|
+
integration_modules = constants.map { |const| const_get(const) }
|
22
|
+
.select { |const| const.is_a?(Module) }
|
23
|
+
|
24
|
+
integration_modules.select do |mod|
|
25
|
+
mod.respond_to?(:bun!) && mod.bun!
|
26
|
+
end
|
27
|
+
end
|
13
28
|
end
|
14
29
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bundlebun
|
4
|
+
# Platform contains a set of helpers to deal with platform detection.
|
5
|
+
# Mostly, to see if we are running on Windows.
|
6
|
+
class Platform
|
7
|
+
class << self
|
8
|
+
# Are we running on Windows?
|
9
|
+
#
|
10
|
+
# @return [Boolean]
|
11
|
+
def windows?
|
12
|
+
return @windows if defined?(@windows)
|
13
|
+
|
14
|
+
@windows = defined?(RbConfig) && defined?(RbConfig::CONFIG) &&
|
15
|
+
RbConfig::CONFIG['host_os'].match?(/mswin|mingw|cygwin/)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/bundlebun/runner.rb
CHANGED
@@ -30,9 +30,20 @@ module Bundlebun
|
|
30
30
|
|
31
31
|
# A relative path to binstub that bundlebun usually generates with installation Rake tasks.
|
32
32
|
#
|
33
|
+
# For Windows, the binstub path will return the `bun.cmd` wrapper.
|
34
|
+
#
|
33
35
|
# @return [String]
|
34
36
|
def binstub_path
|
35
|
-
BINSTUB_PATH
|
37
|
+
Bundlebun::Platform.windows? ? "#{BINSTUB_PATH}.cmd" : BINSTUB_PATH
|
38
|
+
end
|
39
|
+
|
40
|
+
# A full path to binstub that bundlebun usually generates with installation Rake tasks.
|
41
|
+
#
|
42
|
+
# For Windows, that will use the `bun.cmd` wrapper.
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
def full_binstub_path
|
46
|
+
File.expand_path(binstub_path)
|
36
47
|
end
|
37
48
|
|
38
49
|
# A relative directory path to the bundled Bun executable from the root of the gem.
|
@@ -46,7 +57,9 @@ module Bundlebun
|
|
46
57
|
#
|
47
58
|
# @return [String]
|
48
59
|
def full_directory
|
49
|
-
|
60
|
+
return @full_directory if defined?(@full_directory)
|
61
|
+
|
62
|
+
@full_directory = File.expand_path("../../#{relative_directory}", __dir__)
|
50
63
|
end
|
51
64
|
|
52
65
|
# A full path to the bundled Bun binary we run
|
@@ -54,8 +67,10 @@ module Bundlebun
|
|
54
67
|
#
|
55
68
|
# @return [String]
|
56
69
|
def binary_path
|
57
|
-
|
58
|
-
|
70
|
+
return @binary_path if defined?(@binary_path)
|
71
|
+
|
72
|
+
executable = "bun#{Bundlebun::Platform.windows? ? ".exe" : ""}"
|
73
|
+
@binary_path = File.join(full_directory, executable)
|
59
74
|
end
|
60
75
|
|
61
76
|
# Does the bundled Bun binary exist?
|
@@ -67,12 +82,12 @@ module Bundlebun
|
|
67
82
|
|
68
83
|
# Returns the preferred way to run Bun when bundlebun is installed.
|
69
84
|
#
|
70
|
-
# If the binstub is installed (see binstub_path), use the binstub.
|
85
|
+
# If the binstub is installed (see binstub_path), use the full path to binstub.
|
71
86
|
# If not, use the full binary path for the bundled executable (binary_path).
|
72
87
|
#
|
73
88
|
# @return [String]
|
74
89
|
def binstub_or_binary_path
|
75
|
-
binstub_exist? ?
|
90
|
+
binstub_exist? ? full_binstub_path : binary_path
|
76
91
|
end
|
77
92
|
|
78
93
|
# Does the binstub exist?
|
Binary file
|
data/lib/bundlebun/version.rb
CHANGED
data/lib/bundlebun.rb
CHANGED
@@ -43,10 +43,25 @@ module Bundlebun
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
# Prepend the path to the bundled Bun executable to `PATH`.
|
47
|
+
#
|
48
|
+
# @see Bundlebun::Runner.full_directory
|
49
|
+
def prepend_to_path
|
50
|
+
EnvPath.prepend(Runner.full_directory)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Load included Rake tasks (like `bun:install`).
|
54
|
+
def load_tasks
|
47
55
|
Dir[File.expand_path('tasks/*.rake', __dir__)].each { |task| load task }
|
48
56
|
end
|
49
57
|
|
58
|
+
# Detect and load all integrations (monkey-patches).
|
59
|
+
#
|
60
|
+
# @see Bundlebun::Integrations
|
61
|
+
def load_integrations
|
62
|
+
Integrations.bun!
|
63
|
+
end
|
64
|
+
|
50
65
|
def bun = 'Bun'
|
51
66
|
alias_method :bun?, :bun
|
52
67
|
alias_method :bun!, :bun
|
@@ -54,5 +69,6 @@ module Bundlebun
|
|
54
69
|
end
|
55
70
|
|
56
71
|
Bundlebun.loader
|
57
|
-
|
72
|
+
Bundlebun.prepend_to_path
|
58
73
|
Bundlebun.load_tasks if defined?(Rake)
|
74
|
+
Bundlebun.load_integrations
|
data/lib/tasks/install.rake
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
|
+
require 'json'
|
4
5
|
|
5
6
|
namespace :bun do
|
6
7
|
desc 'Install bundlebun: install binstub and detect frameworks'
|
@@ -16,20 +17,15 @@ namespace :bun do
|
|
16
17
|
|
17
18
|
Rake::Task['bun:install:bin'].invoke
|
18
19
|
|
19
|
-
if defined?(
|
20
|
-
puts "Rails detected.\n\n"
|
21
|
-
Rake::Task['bun:install:rails'].invoke
|
20
|
+
if defined?(Cssbundling) || defined?(Jsbundling)
|
21
|
+
puts "Rails' cssbundling/jsbundling detected.\n\n"
|
22
|
+
Rake::Task['bun:install:bundling-rails'].invoke
|
22
23
|
end
|
23
24
|
|
24
25
|
if defined?(ViteRuby)
|
25
26
|
puts "vite-ruby detected.\n\n"
|
26
27
|
Rake::Task['bun:install:vite'].invoke
|
27
28
|
end
|
28
|
-
|
29
|
-
if defined?(ExecJS)
|
30
|
-
puts "ExecJS detected.\n\n"
|
31
|
-
Rake::Task['bun:install:execjs'].invoke
|
32
|
-
end
|
33
29
|
end
|
34
30
|
|
35
31
|
desc 'Install bundlebun: create `bin/bun` binstub'
|
@@ -39,17 +35,33 @@ namespace :bun do
|
|
39
35
|
source = File.expand_path('../../exe/bundlebun', __dir__)
|
40
36
|
target_dir = 'bin'
|
41
37
|
target = File.join(target_dir, 'bun')
|
38
|
+
content = File.read(source)
|
42
39
|
|
43
40
|
if File.exist?(target)
|
44
41
|
puts "#{target} already exists."
|
45
42
|
else
|
46
43
|
FileUtils.mkdir_p(target_dir)
|
47
|
-
|
44
|
+
File.write(target, content, mode: "w")
|
48
45
|
FileUtils.chmod(0o755, target)
|
49
46
|
|
50
47
|
puts "Installed binstub at #{target}."
|
51
48
|
end
|
52
49
|
|
50
|
+
# We're using Bundler technique to generate the .cmd wrappers on
|
51
|
+
# Windows (as Windows cannot run files with shebangs, of course).
|
52
|
+
# There is no public API for generating binstubs (I wish), so that's a copy and paste.
|
53
|
+
# @see https://github.com/rubygems/rubygems/blob/186a4f24789e6e7fd967b290ce93ed5886ef22d8/bundler/lib/bundler/installer.rb#L137
|
54
|
+
if Gem.win_platform?
|
55
|
+
cmd_target = "#{target}.cmd"
|
56
|
+
if File.exist?(cmd_target)
|
57
|
+
puts "#{cmd_target} already exists."
|
58
|
+
else
|
59
|
+
prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
|
60
|
+
File.write(cmd_target, prefix + content, mode: "wb:UTF-8")
|
61
|
+
puts "Installed Windows binstub at #{cmd_target}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
53
65
|
puts <<~MESSAGE
|
54
66
|
Try running it directly. Or, replace existing mentions of `bun` with `bin/bun` in your `package.json`, `Procfile` or binstubs and other files.
|
55
67
|
|
@@ -58,18 +70,20 @@ namespace :bun do
|
|
58
70
|
MESSAGE
|
59
71
|
end
|
60
72
|
|
61
|
-
desc 'Install bundlebun:
|
62
|
-
task 'install:rails' => :install do
|
63
|
-
puts "Installing Rails integration...\n\n"
|
73
|
+
desc 'Install bundlebun: cssbundling-rails, jsbundling-rails integration'
|
74
|
+
task 'install:bundling-rails' => :install do
|
75
|
+
puts "Installing cssbundling/jsbundling Rails integration...\n\n"
|
64
76
|
|
65
|
-
assets_rake = File.expand_path('../templates/rails/bundlebun.rake', __dir__)
|
77
|
+
assets_rake = File.expand_path('../templates/bundling-rails/bundlebun.rake', __dir__)
|
66
78
|
target_dir = 'lib/tasks'
|
67
79
|
target = File.join(target_dir, 'bundlebun.rake')
|
68
80
|
|
69
|
-
if
|
70
|
-
puts "Installed an initializer with overrides for cssbundling-rails and jsbundling-rails at #{target}"
|
71
|
-
else
|
81
|
+
if File.exist?(target)
|
72
82
|
puts "#{target} already exists."
|
83
|
+
else
|
84
|
+
FileUtils.mkdir_p(target_dir)
|
85
|
+
FileUtils.cp(assets_rake, target)
|
86
|
+
puts "Installed an initializer with overrides for cssbundling-rails and jsbundling-rails at #{target}"
|
73
87
|
end
|
74
88
|
|
75
89
|
puts <<~MESSAGE
|
@@ -97,75 +111,60 @@ namespace :bun do
|
|
97
111
|
task 'install:vite' => :install do
|
98
112
|
puts "Installing vite-ruby integration...\n\n"
|
99
113
|
|
100
|
-
binstub = File.expand_path('../templates/vite-ruby/vite', __dir__)
|
114
|
+
binstub = File.expand_path('../templates/vite-ruby/bun-vite', __dir__)
|
101
115
|
target_dir = 'bin'
|
102
|
-
|
103
|
-
|
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')
|
116
|
+
target = File.join(target_dir, 'bun-vite')
|
117
|
+
content = File.read(binstub)
|
107
118
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
puts "Copying #{target} to #{backup} for backup"
|
112
|
-
FileUtils.mv(target, backup)
|
119
|
+
config = File.expand_path('../templates/vite-ruby/vite.json', __dir__)
|
120
|
+
config_target_dir = 'config'
|
121
|
+
config_target = File.join(config_target_dir, 'vite.json')
|
113
122
|
|
114
|
-
|
115
|
-
|
116
|
-
puts "Installed a vite-ruby + bundlebun binstub at #{target}"
|
123
|
+
if File.exist?(target)
|
124
|
+
puts "#{target} already exists."
|
117
125
|
else
|
118
126
|
FileUtils.mkdir_p(target_dir)
|
119
|
-
|
127
|
+
File.write(target, content, mode: "w")
|
120
128
|
FileUtils.chmod(0o755, target)
|
121
129
|
puts "Installed a vite-ruby + bundlebun binstub at #{target}"
|
122
130
|
end
|
123
131
|
|
124
|
-
|
125
|
-
|
126
|
-
|
132
|
+
# See above for notes on `.cmd`-file generation.
|
133
|
+
if Gem.win_platform?
|
134
|
+
cmd_target = "#{target}.cmd"
|
135
|
+
if File.exist?(cmd_target)
|
136
|
+
puts "#{cmd_target} already exists."
|
127
137
|
else
|
128
|
-
|
129
|
-
|
138
|
+
prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
|
139
|
+
File.write(cmd_target, prefix + content, mode: "wb:UTF-8")
|
140
|
+
puts "Installed Windows binstub at #{cmd_target}"
|
130
141
|
end
|
131
|
-
else
|
132
|
-
puts "Directory #{initializers_dir} does not seem to exist; not installing a Rails initializer."
|
133
142
|
end
|
134
143
|
|
135
|
-
|
136
|
-
|
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.
|
144
|
+
if File.exist?(config_target)
|
145
|
+
puts "#{config_target} already exists."
|
141
146
|
|
142
|
-
|
147
|
+
begin
|
148
|
+
json = JSON.parse(File.read(config_target))
|
149
|
+
# Injecting our binstub
|
150
|
+
json['all'] ||= {}
|
151
|
+
json['all']['viteBinPath'] = 'bin/bun-vite'
|
143
152
|
|
144
|
-
|
145
|
-
|
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}."
|
153
|
+
File.write(config_target, JSON.pretty_generate(json))
|
154
|
+
rescue
|
155
|
+
puts "Failed to parse #{config_target}, no changes made."
|
161
156
|
end
|
162
157
|
else
|
163
|
-
|
158
|
+
FileUtils.mkdir_p(config_target_dir)
|
159
|
+
FileUtils.cp(config, config_target)
|
160
|
+
puts "Installed sample vite-ruby + bundlebun config at #{config_target}"
|
164
161
|
end
|
165
162
|
|
166
163
|
puts <<~MESSAGE
|
167
|
-
We've installed a
|
168
|
-
|
164
|
+
We've installed a binstub for running vite-ruby with bundlebun enabled at #{target}.
|
165
|
+
Use this binstub to force bundlebun with Vite as a JavaScript runtime. Additionally, we've installed (or updated!) a vite-ruby configuration file at #{config_target} to use that binstub.
|
166
|
+
|
167
|
+
Be sure to replace `bun` with `bin/bun` in any existing build-related files such as `Procfile` or `Procfile.dev`, `package.json` and others.
|
169
168
|
|
170
169
|
Bun.
|
171
170
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This file runs the Vite executable under Bun.
|
4
|
+
|
5
|
+
ENV['RAILS_ENV'] ||= ENV['RACK_ENV']
|
6
|
+
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'vite_ruby'
|
9
|
+
require 'bundlebun'
|
10
|
+
|
11
|
+
Bundlebun::Integrations::ViteRuby.bun!
|
12
|
+
|
13
|
+
Bundlebun.call(['x', '--bun', 'vite', *ARGV])
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"all": {
|
3
|
+
"watchAdditionalPaths": [],
|
4
|
+
"viteBinPath": "bin/bun-vite"
|
5
|
+
},
|
6
|
+
"development": {
|
7
|
+
"autoBuild": true,
|
8
|
+
"publicOutputDir": "vite-dev",
|
9
|
+
"port": 3036
|
10
|
+
},
|
11
|
+
"test": {
|
12
|
+
"autoBuild": true,
|
13
|
+
"publicOutputDir": "vite-test",
|
14
|
+
"port": 3037
|
15
|
+
}
|
16
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bundlebun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.2.1
|
4
|
+
version: 0.2.0.1.2.1
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- Yaroslav Markin
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-30 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: zeitwerk
|
@@ -24,6 +23,20 @@ dependencies:
|
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: json
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
27
40
|
description: 'bundlebun bundles Bun, a fast JavaScript runtime, package manager, and
|
28
41
|
builder, with your Ruby and Rails applications. No need to use Docker, devcontainers,
|
29
42
|
`curl | sh`, or `brew`.
|
@@ -42,21 +55,22 @@ files:
|
|
42
55
|
- README.md
|
43
56
|
- exe/bundlebun
|
44
57
|
- lib/bundlebun.rb
|
58
|
+
- lib/bundlebun/env_path.rb
|
45
59
|
- lib/bundlebun/integrations.rb
|
46
60
|
- lib/bundlebun/integrations/cssbundling.rb
|
47
61
|
- lib/bundlebun/integrations/execjs.rb
|
48
62
|
- lib/bundlebun/integrations/jsbundling.rb
|
49
63
|
- lib/bundlebun/integrations/vite_ruby.rb
|
64
|
+
- lib/bundlebun/platform.rb
|
50
65
|
- lib/bundlebun/runner.rb
|
51
66
|
- lib/bundlebun/vendor/bun/LICENSE.md
|
52
67
|
- lib/bundlebun/vendor/bun/bun
|
53
68
|
- lib/bundlebun/version.rb
|
54
69
|
- lib/tasks/bun.rake
|
55
70
|
- lib/tasks/install.rake
|
56
|
-
- lib/templates/
|
57
|
-
- lib/templates/
|
58
|
-
- lib/templates/vite-ruby/
|
59
|
-
- lib/templates/vite-ruby/vite
|
71
|
+
- lib/templates/bundling-rails/bundlebun.rake
|
72
|
+
- lib/templates/vite-ruby/bun-vite
|
73
|
+
- lib/templates/vite-ruby/vite.json
|
60
74
|
homepage: https://github.com/yaroslav/bundlebun
|
61
75
|
licenses:
|
62
76
|
- MIT
|
@@ -81,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
85
|
-
signing_key:
|
98
|
+
rubygems_version: 3.6.2
|
86
99
|
specification_version: 4
|
87
100
|
summary: bundlebun bundles the Bun JavaScript runtime, package manager and build tool,
|
88
101
|
for use with Ruby and Rails
|
@@ -1,9 +0,0 @@
|
|
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!
|
@@ -1,9 +0,0 @@
|
|
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!
|
@@ -1,25 +0,0 @@
|
|
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
|