bundlebun 0.5.0.1.3.13-aarch64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,305 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'json'
5
+
6
+ namespace :bun do
7
+ desc 'Install bundlebun: install binstub and detect frameworks'
8
+ task 'install' do
9
+ puts <<~MESSAGE
10
+ We are now going to install bundlebun. We'll try to detect the frameworks already in use and install integrations for them.
11
+
12
+ 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.
13
+
14
+ Bun.
15
+
16
+ MESSAGE
17
+
18
+ Rake::Task['bun:install:bin'].invoke
19
+
20
+ if defined?(Cssbundling) || defined?(Jsbundling)
21
+ puts "Rails' cssbundling/jsbundling detected.\n\n"
22
+ Rake::Task['bun:install:bundling-rails'].invoke
23
+ end
24
+
25
+ if defined?(ViteRuby)
26
+ puts "vite-ruby detected.\n\n"
27
+ Rake::Task['bun:install:vite'].invoke
28
+ end
29
+
30
+ if File.exist?('package.json')
31
+ puts "package.json detected.\n\n"
32
+ Rake::Task['bun:install:package'].invoke
33
+ end
34
+
35
+ if Dir.glob('Procfile*').any?
36
+ puts "Procfile detected.\n\n"
37
+ Rake::Task['bun:install:procfile'].invoke
38
+ end
39
+ end
40
+
41
+ desc 'Install bundlebun: create `bin/bun` binstub'
42
+ task 'install:bin' do
43
+ puts "Installing bin/bun...\n\n"
44
+
45
+ source = File.expand_path('../../exe/bundlebun', __dir__)
46
+ target_dir = 'bin'
47
+ target = File.join(target_dir, 'bun')
48
+ content = File.read(source)
49
+
50
+ if File.exist?(target)
51
+ puts "#{target} already exists."
52
+ else
53
+ FileUtils.mkdir_p(target_dir)
54
+ File.write(target, content, mode: "w")
55
+ FileUtils.chmod(0o755, target)
56
+
57
+ puts "Installed binstub at #{target}."
58
+ end
59
+
60
+ # We're using Bundler technique to generate the .cmd wrappers on
61
+ # Windows (as Windows cannot run files with shebangs, of course).
62
+ # There is no public API for generating binstubs (I wish), so that's a copy and paste.
63
+ # @see https://github.com/rubygems/rubygems/blob/186a4f24789e6e7fd967b290ce93ed5886ef22d8/bundler/lib/bundler/installer.rb#L137
64
+ if Gem.win_platform?
65
+ cmd_target = "#{target}.cmd"
66
+ if File.exist?(cmd_target)
67
+ puts "#{cmd_target} already exists."
68
+ else
69
+ prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
70
+ File.write(cmd_target, prefix + content, mode: "wb:UTF-8")
71
+ puts "Installed Windows binstub at #{cmd_target}"
72
+ end
73
+ end
74
+
75
+ puts <<~MESSAGE
76
+ Try running it directly. Or, replace existing mentions of `bun` with `bin/bun` in your `package.json`, `Procfile` or binstubs and other files.
77
+
78
+ Bun.
79
+
80
+ MESSAGE
81
+ end
82
+
83
+ desc 'Install bundlebun: cssbundling-rails, jsbundling-rails integration'
84
+ task 'install:bundling-rails' => :install do
85
+ puts "Installing cssbundling/jsbundling Rails integration...\n\n"
86
+
87
+ assets_rake = File.expand_path('../templates/bundling-rails/bundlebun.rake', __dir__)
88
+ target_dir = 'lib/tasks'
89
+ target = File.join(target_dir, 'bundlebun.rake')
90
+
91
+ if File.exist?(target)
92
+ puts "#{target} already exists."
93
+ else
94
+ FileUtils.mkdir_p(target_dir)
95
+ FileUtils.cp(assets_rake, target)
96
+ puts "Installed an initializer with overrides for cssbundling-rails and jsbundling-rails at #{target}"
97
+ end
98
+
99
+ puts <<~MESSAGE
100
+ 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.
101
+
102
+ Example:
103
+
104
+ bundle add cssbundling-rails
105
+ bin/rails css:install:[tailwind|bootstrap|bulma|postcss|sass]
106
+ bin/rails css:build
107
+
108
+ bundle add jsbundling-rails
109
+ bin/rails javascript:install:bun
110
+
111
+ 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.
112
+
113
+ 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.
114
+
115
+ Bun.
116
+
117
+ MESSAGE
118
+ end
119
+
120
+ desc 'Install bundlebun: vite-ruby integration'
121
+ task 'install:vite' => :install do
122
+ puts "Installing vite-ruby integration...\n\n"
123
+
124
+ binstub = File.expand_path('../templates/vite-ruby/bun-vite', __dir__)
125
+ target_dir = 'bin'
126
+ target = File.join(target_dir, 'bun-vite')
127
+ content = File.read(binstub)
128
+
129
+ config = File.expand_path('../templates/vite-ruby/vite.json', __dir__)
130
+ config_target_dir = 'config'
131
+ config_target = File.join(config_target_dir, 'vite.json')
132
+
133
+ if File.exist?(target)
134
+ puts "#{target} already exists."
135
+ else
136
+ FileUtils.mkdir_p(target_dir)
137
+ File.write(target, content, mode: "w")
138
+ FileUtils.chmod(0o755, target)
139
+ puts "Installed a vite-ruby + bundlebun binstub at #{target}"
140
+ end
141
+
142
+ # See above for notes on `.cmd`-file generation.
143
+ if Gem.win_platform?
144
+ cmd_target = "#{target}.cmd"
145
+ if File.exist?(cmd_target)
146
+ puts "#{cmd_target} already exists."
147
+ else
148
+ prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
149
+ File.write(cmd_target, prefix + content, mode: "wb:UTF-8")
150
+ puts "Installed Windows binstub at #{cmd_target}"
151
+ end
152
+ end
153
+
154
+ if File.exist?(config_target)
155
+ puts "#{config_target} already exists."
156
+
157
+ begin
158
+ json = JSON.parse(File.read(config_target))
159
+ # Injecting our binstub
160
+ json['all'] ||= {}
161
+ json['all']['viteBinPath'] = 'bin/bun-vite'
162
+
163
+ File.write(config_target, JSON.pretty_generate(json))
164
+ rescue
165
+ puts "Failed to parse #{config_target}, no changes made."
166
+ end
167
+ else
168
+ FileUtils.mkdir_p(config_target_dir)
169
+ FileUtils.cp(config, config_target)
170
+ puts "Installed sample vite-ruby + bundlebun config at #{config_target}"
171
+ end
172
+
173
+ puts <<~MESSAGE
174
+ We've installed a binstub for running vite-ruby with bundlebun enabled at #{target}.
175
+ 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.
176
+
177
+ Be sure to replace `bun` with `bin/bun` in any existing build-related files such as `Procfile` or `Procfile.dev`, `package.json` and others.
178
+
179
+ Bun.
180
+
181
+ MESSAGE
182
+ end
183
+
184
+ desc 'Migrate package.json scripts to use bin/bun'
185
+ task 'install:package' do
186
+ package_json_path = 'package.json'
187
+
188
+ unless File.exist?(package_json_path)
189
+ puts "No package.json found in the current directory."
190
+ next
191
+ end
192
+
193
+ begin
194
+ package = JSON.parse(File.read(package_json_path))
195
+ rescue JSON::ParserError
196
+ puts "Failed to parse package.json."
197
+ next
198
+ end
199
+
200
+ scripts = package['scripts']
201
+ if scripts.nil? || scripts.empty?
202
+ puts "No scripts found in package.json."
203
+ next
204
+ end
205
+
206
+ # Order in alternation matters: more specific patterns first
207
+ pattern = /\b(bunx|npx|pnpm exec|yarn exec|npm run|yarn run|pnpm run|bun)\b/
208
+ binstub = Bundlebun::Runner.binstub_path
209
+ replacements = {
210
+ 'bunx' => "#{binstub} x",
211
+ 'npx' => "#{binstub} x",
212
+ 'pnpm exec' => "#{binstub} x",
213
+ 'yarn exec' => "#{binstub} x",
214
+ 'npm run' => "#{binstub} run",
215
+ 'yarn run' => "#{binstub} run",
216
+ 'pnpm run' => "#{binstub} run",
217
+ 'bun' => binstub
218
+ }
219
+
220
+ changes = []
221
+ scripts.each do |name, value|
222
+ next unless value.is_a?(String)
223
+ next if value.include?(Bundlebun::Runner::BINSTUB_PATH)
224
+
225
+ new_value = value.gsub(pattern) { |match| replacements[match] }
226
+ changes << {name: name, old: value, new: new_value} if new_value != value
227
+ end
228
+
229
+ if changes.empty?
230
+ puts "All scripts in package.json already use bin/bun. No changes needed."
231
+ next
232
+ end
233
+
234
+ puts "The following changes will be made to package.json scripts:\n\n"
235
+ changes.each do |change|
236
+ puts " #{change[:name]}:"
237
+ puts " - #{change[:old]}"
238
+ puts " + #{change[:new]}"
239
+ puts
240
+ end
241
+
242
+ print "Apply these changes? [Y/n] "
243
+ answer = $stdin.gets&.strip&.downcase
244
+
245
+ if answer.nil? || answer.empty? || answer == 'y' || answer == 'yes'
246
+ changes.each do |change|
247
+ package['scripts'][change[:name]] = change[:new]
248
+ end
249
+
250
+ File.write(package_json_path, JSON.pretty_generate(package) + "\n")
251
+ puts "\nUpdated package.json successfully."
252
+ else
253
+ puts "\nNo changes made."
254
+ end
255
+ end
256
+
257
+ desc 'Migrate Procfile commands to use bin/bun'
258
+ task 'install:procfile' do
259
+ procfiles = Dir.glob('Procfile*')
260
+
261
+ if procfiles.empty?
262
+ puts "No Procfile found in the current directory."
263
+ next
264
+ end
265
+
266
+ pattern = /\b(bunx|npx|pnpm exec|yarn exec|npm run|yarn run|pnpm run|bun)\b/
267
+ binstub = Bundlebun::Runner.binstub_path
268
+ replacements = {
269
+ 'bunx' => "#{binstub} x",
270
+ 'npx' => "#{binstub} x",
271
+ 'pnpm exec' => "#{binstub} x",
272
+ 'yarn exec' => "#{binstub} x",
273
+ 'npm run' => "#{binstub} run",
274
+ 'yarn run' => "#{binstub} run",
275
+ 'pnpm run' => "#{binstub} run",
276
+ 'bun' => binstub
277
+ }
278
+
279
+ procfiles.each do |procfile|
280
+ content = File.read(procfile)
281
+ next if content.include?(Bundlebun::Runner::BINSTUB_PATH)
282
+
283
+ new_content = content.gsub(pattern) { |match| replacements[match] }
284
+ next if new_content == content
285
+
286
+ puts "Changes for #{procfile}:\n\n"
287
+ content.lines.zip(new_content.lines).each do |old_line, new_line|
288
+ if old_line != new_line
289
+ puts " - #{old_line}"
290
+ puts " + #{new_line}"
291
+ end
292
+ end
293
+
294
+ print "Apply these changes? [Y/n] "
295
+ answer = $stdin.gets&.strip&.downcase
296
+
297
+ if answer.nil? || answer.empty? || answer == 'y' || answer == 'yes'
298
+ File.write(procfile, new_content)
299
+ puts "Updated #{procfile} successfully.\n\n"
300
+ else
301
+ puts "No changes made to #{procfile}.\n\n"
302
+ end
303
+ end
304
+ end
305
+ end
@@ -0,0 +1,10 @@
1
+ # An initializer of sorts for bundlebun's 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,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
+ }
@@ -0,0 +1,8 @@
1
+ module Bundlebun
2
+ class EnvPath
3
+ def self.path: () -> String?
4
+ def self.path=: (String new_path) -> String
5
+ def self.prepend: (String new_path) -> String?
6
+ def self.separator: () -> String
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module Bundlebun
2
+ module Integrations
3
+ module Cssbundling
4
+ def self.bun!: () -> void
5
+
6
+ module Tasks
7
+ def install_command: () -> String
8
+ def build_command: () -> String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module Bundlebun
2
+ module Integrations
3
+ module ExecJS
4
+ def self.bun!: () -> void
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Bundlebun
2
+ module Integrations
3
+ module Jsbundling
4
+ def self.bun!: () -> void
5
+
6
+ module Tasks
7
+ def install_command: () -> String
8
+ def build_command: () -> String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Bundlebun
2
+ module Integrations
3
+ module ViteRuby
4
+ def self.bun!: () -> void
5
+
6
+ module RunnerExtensions
7
+ def vite_executable: (*untyped exec_args) -> Array[String]
8
+ def bun_binstub_path: () -> String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Bundlebun
2
+ module Integrations
3
+ def self.bun!: () -> Array[Module]
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Bundlebun
2
+ class Platform
3
+ def self.windows?: () -> bool
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+ module Bundlebun
2
+ class Runner
3
+ BINSTUB_PATH: String
4
+ RELATIVE_DIRECTORY: String
5
+
6
+ # Replaces the current Ruby process with Bun. Never returns.
7
+ def self.exec: (String | Array[String] arguments) -> bot
8
+
9
+ # Replaces the current Ruby process with Bun. Alias for .exec. Never returns.
10
+ def self.call: (String | Array[String] arguments) -> bot
11
+
12
+ # Runs Bun as a subprocess and returns control to Ruby.
13
+ def self.system: (String | Array[String] arguments) -> bool?
14
+
15
+ def self.binstub_path: () -> String
16
+ def self.full_binstub_path: () -> String
17
+ def self.relative_directory: () -> String
18
+ def self.full_directory: () -> String
19
+ def self.binary_path: () -> String
20
+ def self.binary_path_exist?: () -> bool
21
+ def self.binstub_or_binary_path: () -> String
22
+ def self.binstub_exist?: () -> bool
23
+
24
+ def initialize: (String | Array[String] arguments) -> void
25
+
26
+ # Replaces the current Ruby process with Bun. Never returns.
27
+ def exec: () -> bot
28
+
29
+ # Replaces the current Ruby process with Bun. Alias for #exec. Never returns.
30
+ def call: () -> bot
31
+
32
+ # Runs Bun as a subprocess and returns control to Ruby.
33
+ def system: () -> bool?
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Bundlebun
2
+ VERSION: String
3
+ end
data/sig/bundlebun.rbs ADDED
@@ -0,0 +1,18 @@
1
+ module Bundlebun
2
+ VERSION: String
3
+
4
+ # Replaces the current Ruby process with Bun.
5
+ # This is the default way to run Bun. Never returns.
6
+ def self.call: (String | Array[String] arguments) -> bot
7
+
8
+ # Replaces the current Ruby process with Bun. Same as .call.
9
+ def self.exec: (String | Array[String] arguments) -> bot
10
+
11
+ # Runs Bun as a subprocess and returns control to Ruby.
12
+ # Returns true if Bun exited successfully, false if it failed, nil if execution failed.
13
+ def self.system: (String | Array[String] arguments) -> bool?
14
+
15
+ def self.prepend_to_path: () -> String?
16
+ def self.load_tasks: () -> void
17
+ def self.load_integrations: () -> Array[Module]
18
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundlebun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0.1.3.13
5
+ platform: aarch64-linux-gnu
6
+ authors:
7
+ - Yaroslav Markin
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: zeitwerk
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.5'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.5'
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ description: 'bundlebun bundles Bun, a fast JavaScript runtime, package manager, and
41
+ builder, with your Ruby and Rails applications. No need to use Docker, devcontainers,
42
+ `curl | sh`, or `brew`.
43
+
44
+ '
45
+ email:
46
+ - yaroslav@markin.net
47
+ executables:
48
+ - bundlebun
49
+ extensions: []
50
+ extra_rdoc_files:
51
+ - README.md
52
+ files:
53
+ - CHANGELOG.md
54
+ - LICENSE.txt
55
+ - README.md
56
+ - exe/bundlebun
57
+ - lib/bundlebun.rb
58
+ - lib/bundlebun/env_path.rb
59
+ - lib/bundlebun/integrations.rb
60
+ - lib/bundlebun/integrations/cssbundling.rb
61
+ - lib/bundlebun/integrations/execjs.rb
62
+ - lib/bundlebun/integrations/jsbundling.rb
63
+ - lib/bundlebun/integrations/vite_ruby.rb
64
+ - lib/bundlebun/platform.rb
65
+ - lib/bundlebun/runner.rb
66
+ - lib/bundlebun/vendor/bun/LICENSE.md
67
+ - lib/bundlebun/vendor/bun/bun
68
+ - lib/bundlebun/version.rb
69
+ - lib/tasks/bun.rake
70
+ - lib/tasks/install.rake
71
+ - lib/templates/bundling-rails/bundlebun.rake
72
+ - lib/templates/vite-ruby/bun-vite
73
+ - lib/templates/vite-ruby/vite.json
74
+ - sig/bundlebun.rbs
75
+ - sig/bundlebun/env_path.rbs
76
+ - sig/bundlebun/integrations.rbs
77
+ - sig/bundlebun/integrations/cssbundling.rbs
78
+ - sig/bundlebun/integrations/execjs.rbs
79
+ - sig/bundlebun/integrations/jsbundling.rbs
80
+ - sig/bundlebun/integrations/vite_ruby.rbs
81
+ - sig/bundlebun/platform.rbs
82
+ - sig/bundlebun/runner.rbs
83
+ - sig/bundlebun/version.rbs
84
+ homepage: https://github.com/yaroslav/bundlebun
85
+ licenses:
86
+ - MIT
87
+ metadata:
88
+ homepage_uri: https://github.com/yaroslav/bundlebun
89
+ source_code_uri: https://github.com/yaroslav/bundlebun
90
+ changelog_uri: https://github.com/yaroslav/bundlebun/blob/main/CHANGELOG.md
91
+ bug_tracker_uri: https://github.com/yaroslav/bundlebun/issues
92
+ documentation_uri: https://rubydoc.info/gems/bundlebun
93
+ rbs_source: sig
94
+ post_install_message: Bun.
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 3.0.0
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.6.9
110
+ specification_version: 4
111
+ summary: bundlebun bundles the Bun JavaScript runtime, package manager and build tool,
112
+ for use with Ruby and Rails
113
+ test_files: []