railpack 0.1.9.1 → 1.1.0

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,80 @@
1
+ module Railpack
2
+ class Manager
3
+ BUNDLERS = {
4
+ 'bun' => BunBundler,
5
+ 'esbuild' => EsbuildBundler,
6
+ 'rollup' => RollupBundler
7
+ }
8
+
9
+ def initialize
10
+ @bundler = create_bundler
11
+ end
12
+
13
+ # Unified API - delegate to the selected bundler
14
+ def build!(args = [])
15
+ config = Railpack.config.for_environment(Rails.env)
16
+ Railpack.trigger_build_start(config)
17
+
18
+ begin
19
+ result = @bundler.build!(args)
20
+ Railpack.trigger_build_complete({ success: true, config: config })
21
+ result
22
+ rescue => error
23
+ Railpack.trigger_error(error)
24
+ Railpack.trigger_build_complete({ success: false, error: error, config: config })
25
+ raise
26
+ end
27
+ end
28
+
29
+ def watch(args = [])
30
+ @bundler.watch(args)
31
+ end
32
+
33
+ def install!(args = [])
34
+ @bundler.install!(args)
35
+ end
36
+
37
+ def add(*packages)
38
+ @bundler.add(*packages)
39
+ end
40
+
41
+ def remove(*packages)
42
+ @bundler.remove(*packages)
43
+ end
44
+
45
+ def exec(*args)
46
+ @bundler.exec(*args)
47
+ end
48
+
49
+ def version
50
+ @bundler.version
51
+ end
52
+
53
+ def installed?
54
+ @bundler.installed?
55
+ end
56
+
57
+ # Rails asset pipeline integration
58
+ def self.enhance_assets_precompile(*tasks)
59
+ if defined?(Rake::Task) && Rake::Task.task_defined?("assets:precompile")
60
+ Rake::Task["assets:precompile"].enhance(tasks)
61
+ end
62
+ end
63
+
64
+ # Alias for convenience
65
+ singleton_class.alias_method :enhance, :enhance_assets_precompile
66
+
67
+ private
68
+
69
+ def create_bundler
70
+ bundler_name = Railpack.config.bundler
71
+ bundler_class = BUNDLERS[bundler_name]
72
+
73
+ unless bundler_class
74
+ raise Error, "Unsupported bundler: #{bundler_name}. Available: #{BUNDLERS.keys.join(', ')}"
75
+ end
76
+
77
+ bundler_class.new(Railpack.config)
78
+ end
79
+ end
80
+ end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Railpack
4
- VERSION = "0.1.9.1"
2
+ VERSION = "1.1.0"
5
3
  end
data/lib/railpack.rb CHANGED
@@ -1,15 +1,66 @@
1
- # frozen_string_literal: true
2
-
1
+ # Railpack - Multi-bundler asset pipeline for Rails
3
2
  require_relative "railpack/version"
3
+ require_relative "railpack/bundler"
4
+ require_relative "railpack/bundlers/bun_bundler"
5
+ require_relative "railpack/bundlers/esbuild_bundler"
6
+ require_relative "railpack/bundlers/rollup_bundler"
7
+ require_relative "railpack/config"
8
+ require_relative "railpack/manager"
4
9
 
5
10
  module Railpack
6
11
  class Error < StandardError; end
7
- end
8
12
 
13
+ class << self
14
+ attr_accessor :logger
15
+
16
+ def config
17
+ @config ||= Config.new
18
+ end
19
+
20
+ def manager
21
+ @manager ||= Manager.new
22
+ end
23
+ end
24
+
25
+ # Hook system for events
26
+ def self.on_error(&block)
27
+ @error_hooks ||= []
28
+ @error_hooks << block
29
+ end
30
+
31
+ def self.on_build_start(&block)
32
+ @build_start_hooks ||= []
33
+ @build_start_hooks << block
34
+ end
35
+
36
+ def self.on_build_complete(&block)
37
+ @build_complete_hooks ||= []
38
+ @build_complete_hooks << block
39
+ end
40
+
41
+ # Trigger hooks
42
+ def self.trigger_error(error)
43
+ @error_hooks&.each { |hook| hook.call(error) }
44
+ end
45
+
46
+ def self.trigger_build_start(config)
47
+ @build_start_hooks&.each { |hook| hook.call(config) }
48
+ end
49
+
50
+ def self.trigger_build_complete(result)
51
+ @build_complete_hooks&.each { |hook| hook.call(result) }
52
+ end
53
+
54
+ # Delegate to manager
55
+ def self.method_missing(method, *args, &block)
56
+ if manager.respond_to?(method)
57
+ manager.send(method, *args, &block)
58
+ else
59
+ super
60
+ end
61
+ end
9
62
 
10
- require_relative "railpack/instance"
11
- require_relative "railpack/configuration"
12
- require_relative "railpack/bun_manager"
13
- require_relative "railpack/webpack_manager"
14
- require_relative "railpack/esbuild_manager"
15
- require_relative "railpack/rollup_manager"
63
+ def self.respond_to_missing?(method, include_private = false)
64
+ manager.respond_to?(method) || super
65
+ end
66
+ end
@@ -0,0 +1,70 @@
1
+ # Railpack convenience tasks for Rails
2
+ require "railpack"
3
+
4
+ # Rails asset pipeline integration - must be in rake file for Docker build
5
+ Railpack::Manager.enhance("build", "copy_assets")
6
+
7
+ namespace :railpack do
8
+ desc "Install Railpack dependencies"
9
+ task :install do
10
+ Railpack.install!
11
+ end
12
+
13
+ desc "Build JavaScript for production"
14
+ task :build do
15
+ Railpack.build!
16
+ end
17
+
18
+ desc "Watch and rebuild JavaScript"
19
+ task :watch do
20
+ Railpack.watch
21
+ end
22
+
23
+ desc "Clean built assets"
24
+ task :clean do
25
+ # TODO: Implement clean
26
+ end
27
+
28
+ desc "Add Railpack dependencies"
29
+ task :add, [ :packages ] do |t, args|
30
+ packages = args[:packages].split(" ")
31
+ Railpack.add(*packages)
32
+ end
33
+
34
+ desc "Remove Railpack dependencies"
35
+ task :remove, [ :packages ] do |t, args|
36
+ packages = args[:packages].split(" ")
37
+ Railpack.remove(*packages)
38
+ end
39
+
40
+ desc "Copy built assets to public/assets for Rails serving"
41
+ task :copy_assets do
42
+ builds_dir = Rails.root.join("app/assets/builds")
43
+ public_assets_dir = Rails.root.join("public/assets")
44
+
45
+ if builds_dir.exist?
46
+ FileUtils.mkdir_p(public_assets_dir)
47
+ Dir.glob("#{builds_dir}/*.{js,map}").each do |file|
48
+ FileUtils.cp(file, public_assets_dir)
49
+ end
50
+ puts "Copied #{Dir.glob("#{builds_dir}/*.{js,map}").size} assets to public/assets"
51
+ else
52
+ puts "No builds directory found"
53
+ end
54
+ end
55
+
56
+ desc "Show Railpack version"
57
+ task :version do
58
+ puts Railpack.version
59
+ end
60
+
61
+ desc "Check if Railpack bundler is installed"
62
+ task :installed do
63
+ puts Railpack.installed? ? "Yes" : "No"
64
+ end
65
+
66
+ desc "Show current bundler"
67
+ task :bundler do
68
+ puts "Current bundler: #{Railpack.config.bundler}"
69
+ end
70
+ end
data/sig/railpack.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Railpack
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/autorun'
4
+ require 'railpack'
5
+
6
+ class RailpackTest < Minitest::Test
7
+ def test_version
8
+ refute_nil ::Railpack::VERSION
9
+ end
10
+
11
+ def test_config
12
+ assert_instance_of Railpack::Config, Railpack.config
13
+ end
14
+
15
+ def test_manager
16
+ assert_instance_of Railpack::Manager, Railpack.manager
17
+ end
18
+
19
+ def test_bundler_support
20
+ assert_includes Railpack::Manager::BUNDLERS.keys, 'bun'
21
+ assert_includes Railpack::Manager::BUNDLERS.keys, 'esbuild'
22
+ assert_includes Railpack::Manager::BUNDLERS.keys, 'rollup'
23
+ assert_equal Railpack::BunBundler, Railpack::Manager::BUNDLERS['bun']
24
+ assert_equal Railpack::EsbuildBundler, Railpack::Manager::BUNDLERS['esbuild']
25
+ assert_equal Railpack::RollupBundler, Railpack::Manager::BUNDLERS['rollup']
26
+ end
27
+ end
metadata CHANGED
@@ -1,47 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 21tycoons LLC
8
- - Liroy Leshed
9
- autorequire:
10
8
  bindir: exe
11
9
  cert_chain: []
12
- date: 2025-02-01 00:00:00.000000000 Z
13
- dependencies: []
14
- description:
10
+ date: 2026-01-26 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '5.0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '5.0'
26
+ description: Choose your JavaScript bundler - Bun, esbuild, Rollup, Webpack. Unified
27
+ Rails integration with hot module replacement and production builds.
15
28
  email:
16
- - liroy@tycooncrm.com
29
+ - hello@21tycoons.com
17
30
  executables: []
18
31
  extensions: []
19
32
  extra_rdoc_files: []
20
33
  files:
21
- - Gemfile
22
- - Gemfile.lock
34
+ - ".rubocop.yml"
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
23
37
  - LICENSE.txt
24
38
  - README.md
25
39
  - Rakefile
26
- - bin/console
27
- - bin/setup
28
- - bun.config.js
29
40
  - lib/railpack.rb
30
- - lib/railpack/bun_manager.rb
31
- - lib/railpack/configuration.rb
32
- - lib/railpack/esbuild_manager.rb
33
- - lib/railpack/instance.rb
34
- - lib/railpack/rollup_manager.rb
41
+ - lib/railpack/bundler.rb
42
+ - lib/railpack/bundlers/bun_bundler.rb
43
+ - lib/railpack/bundlers/esbuild_bundler.rb
44
+ - lib/railpack/config.rb
45
+ - lib/railpack/manager.rb
35
46
  - lib/railpack/version.rb
36
- - lib/railpack/webpack_manager.rb
37
- - rollup.config.js
38
- - webpack.config.js
47
+ - lib/tasks/railpack.rake
48
+ - sig/railpack.rbs
49
+ - test/railpack_test.rb
39
50
  homepage: https://github.com/21tycoons/railpack
40
51
  licenses:
41
52
  - MIT
42
53
  metadata:
54
+ allowed_push_host: https://rubygems.org
43
55
  homepage_uri: https://github.com/21tycoons/railpack
44
- post_install_message:
56
+ source_code_uri: https://github.com/21tycoons/railpack
45
57
  rdoc_options: []
46
58
  require_paths:
47
59
  - lib
@@ -49,15 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
61
  requirements:
50
62
  - - ">="
51
63
  - !ruby/object:Gem::Version
52
- version: 2.6.0
64
+ version: 3.1.0
53
65
  required_rubygems_version: !ruby/object:Gem::Requirement
54
66
  requirements:
55
67
  - - ">="
56
68
  - !ruby/object:Gem::Version
57
69
  version: '0'
58
70
  requirements: []
59
- rubygems_version: 3.5.9
60
- signing_key:
71
+ rubygems_version: 3.6.5
61
72
  specification_version: 4
62
- summary: Use webpack/esbuild/bun/rollup to manage JavaScript in Rails
73
+ summary: Multi-bundler asset pipeline for Rails
63
74
  test_files: []
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in railpack.gemspec
6
- gemspec
7
-
8
- gem "rails"
9
-
10
- gem "rake", "~> 13.0"
11
-
12
- gem "minitest", "~> 5.0"
data/Gemfile.lock DELETED
@@ -1,197 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- railpack (0.1.5)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- actioncable (8.0.1)
10
- actionpack (= 8.0.1)
11
- activesupport (= 8.0.1)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- zeitwerk (~> 2.6)
15
- actionmailbox (8.0.1)
16
- actionpack (= 8.0.1)
17
- activejob (= 8.0.1)
18
- activerecord (= 8.0.1)
19
- activestorage (= 8.0.1)
20
- activesupport (= 8.0.1)
21
- mail (>= 2.8.0)
22
- actionmailer (8.0.1)
23
- actionpack (= 8.0.1)
24
- actionview (= 8.0.1)
25
- activejob (= 8.0.1)
26
- activesupport (= 8.0.1)
27
- mail (>= 2.8.0)
28
- rails-dom-testing (~> 2.2)
29
- actionpack (8.0.1)
30
- actionview (= 8.0.1)
31
- activesupport (= 8.0.1)
32
- nokogiri (>= 1.8.5)
33
- rack (>= 2.2.4)
34
- rack-session (>= 1.0.1)
35
- rack-test (>= 0.6.3)
36
- rails-dom-testing (~> 2.2)
37
- rails-html-sanitizer (~> 1.6)
38
- useragent (~> 0.16)
39
- actiontext (8.0.1)
40
- actionpack (= 8.0.1)
41
- activerecord (= 8.0.1)
42
- activestorage (= 8.0.1)
43
- activesupport (= 8.0.1)
44
- globalid (>= 0.6.0)
45
- nokogiri (>= 1.8.5)
46
- actionview (8.0.1)
47
- activesupport (= 8.0.1)
48
- builder (~> 3.1)
49
- erubi (~> 1.11)
50
- rails-dom-testing (~> 2.2)
51
- rails-html-sanitizer (~> 1.6)
52
- activejob (8.0.1)
53
- activesupport (= 8.0.1)
54
- globalid (>= 0.3.6)
55
- activemodel (8.0.1)
56
- activesupport (= 8.0.1)
57
- activerecord (8.0.1)
58
- activemodel (= 8.0.1)
59
- activesupport (= 8.0.1)
60
- timeout (>= 0.4.0)
61
- activestorage (8.0.1)
62
- actionpack (= 8.0.1)
63
- activejob (= 8.0.1)
64
- activerecord (= 8.0.1)
65
- activesupport (= 8.0.1)
66
- marcel (~> 1.0)
67
- activesupport (8.0.1)
68
- base64
69
- benchmark (>= 0.3)
70
- bigdecimal
71
- concurrent-ruby (~> 1.0, >= 1.3.1)
72
- connection_pool (>= 2.2.5)
73
- drb
74
- i18n (>= 1.6, < 2)
75
- logger (>= 1.4.2)
76
- minitest (>= 5.1)
77
- securerandom (>= 0.3)
78
- tzinfo (~> 2.0, >= 2.0.5)
79
- uri (>= 0.13.1)
80
- base64 (0.2.0)
81
- benchmark (0.4.0)
82
- bigdecimal (3.1.9)
83
- builder (3.3.0)
84
- concurrent-ruby (1.3.5)
85
- connection_pool (2.5.0)
86
- crass (1.0.6)
87
- date (3.4.1)
88
- drb (2.2.1)
89
- erubi (1.13.1)
90
- globalid (1.2.1)
91
- activesupport (>= 6.1)
92
- i18n (1.14.7)
93
- concurrent-ruby (~> 1.0)
94
- io-console (0.8.0)
95
- irb (1.15.1)
96
- pp (>= 0.6.0)
97
- rdoc (>= 4.0.0)
98
- reline (>= 0.4.2)
99
- logger (1.6.5)
100
- loofah (2.24.0)
101
- crass (~> 1.0.2)
102
- nokogiri (>= 1.12.0)
103
- mail (2.8.1)
104
- mini_mime (>= 0.1.1)
105
- net-imap
106
- net-pop
107
- net-smtp
108
- marcel (1.0.4)
109
- mini_mime (1.1.5)
110
- minitest (5.25.4)
111
- net-imap (0.5.5)
112
- date
113
- net-protocol
114
- net-pop (0.1.2)
115
- net-protocol
116
- net-protocol (0.2.2)
117
- timeout
118
- net-smtp (0.5.0)
119
- net-protocol
120
- nio4r (2.7.4)
121
- nokogiri (1.18.2-arm64-darwin)
122
- racc (~> 1.4)
123
- pp (0.6.2)
124
- prettyprint
125
- prettyprint (0.2.0)
126
- psych (5.2.3)
127
- date
128
- stringio
129
- racc (1.8.1)
130
- rack (3.1.8)
131
- rack-session (2.1.0)
132
- base64 (>= 0.1.0)
133
- rack (>= 3.0.0)
134
- rack-test (2.2.0)
135
- rack (>= 1.3)
136
- rackup (2.2.1)
137
- rack (>= 3)
138
- rails (8.0.1)
139
- actioncable (= 8.0.1)
140
- actionmailbox (= 8.0.1)
141
- actionmailer (= 8.0.1)
142
- actionpack (= 8.0.1)
143
- actiontext (= 8.0.1)
144
- actionview (= 8.0.1)
145
- activejob (= 8.0.1)
146
- activemodel (= 8.0.1)
147
- activerecord (= 8.0.1)
148
- activestorage (= 8.0.1)
149
- activesupport (= 8.0.1)
150
- bundler (>= 1.15.0)
151
- railties (= 8.0.1)
152
- rails-dom-testing (2.2.0)
153
- activesupport (>= 5.0.0)
154
- minitest
155
- nokogiri (>= 1.6)
156
- rails-html-sanitizer (1.6.2)
157
- loofah (~> 2.21)
158
- nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
159
- railties (8.0.1)
160
- actionpack (= 8.0.1)
161
- activesupport (= 8.0.1)
162
- irb (~> 1.13)
163
- rackup (>= 1.0.0)
164
- rake (>= 12.2)
165
- thor (~> 1.0, >= 1.2.2)
166
- zeitwerk (~> 2.6)
167
- rake (13.2.1)
168
- rdoc (6.11.0)
169
- psych (>= 4.0.0)
170
- reline (0.6.0)
171
- io-console (~> 0.5)
172
- securerandom (0.4.1)
173
- stringio (3.1.2)
174
- thor (1.3.2)
175
- timeout (0.4.3)
176
- tzinfo (2.0.6)
177
- concurrent-ruby (~> 1.0)
178
- uri (1.0.2)
179
- useragent (0.16.11)
180
- websocket-driver (0.7.7)
181
- base64
182
- websocket-extensions (>= 0.1.0)
183
- websocket-extensions (0.1.5)
184
- zeitwerk (2.7.1)
185
-
186
- PLATFORMS
187
- arm64-darwin-23
188
- ruby
189
-
190
- DEPENDENCIES
191
- minitest (~> 5.0)
192
- railpack!
193
- rails
194
- rake (~> 13.0)
195
-
196
- BUNDLED WITH
197
- 2.6.1
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "railpack"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/bun.config.js DELETED
@@ -1,37 +0,0 @@
1
- import path from 'path'
2
- import fs from 'fs'
3
-
4
- const config = {
5
- sourcemap: "external",
6
- entrypoints: ["app/javascript/application.js"],
7
- outdir: path.join(process.cwd(), "app/assets/builds"),
8
- }
9
-
10
- const build = async (config) => {
11
- const result = await Bun.build(config)
12
-
13
- if (!result.success) {
14
- if (process.argv.includes('--watch')) {
15
- console.error("Build failed")
16
- for (const message of result.logs) {
17
- console.error(message)
18
- }
19
- return;
20
- } else {
21
- throw new AggregateError(result.logs, "Build failed")
22
- }
23
- }
24
- }
25
-
26
- (async () => {
27
- await build(config)
28
-
29
- if (process.argv.includes('--watch')) {
30
- fs.watch(path.join(process.cwd(), "app/javascript"), { recursive: true }, (eventType, filename) => {
31
- console.log(`File changed: ${filename}. Rebuilding...`)
32
- build(config);
33
- });
34
- } else {
35
- process.exit(0);
36
- }
37
- })()
@@ -1,5 +0,0 @@
1
- class Railpack::BunManager
2
- def exists?
3
- true
4
- end
5
- end
@@ -1,7 +0,0 @@
1
- class Railpack::Configuration
2
- attr_reader :config
3
-
4
- def initialize(config = {})
5
- @config = config
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- class Railpack::EsbuildManager
2
- def exists?
3
- true
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Railpack::Instance
2
- def initialize(railpack)
3
- @railpack = railpack
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Railpack::RollupManager
2
- def exists?
3
- true
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Railpack::WebpackManager
2
- def exists?
3
- true
4
- end
5
- end
data/rollup.config.js DELETED
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- input: "src/index.js",
3
- output: {
4
- file: "app/javascript/application.js",
5
- format: "iife",
6
- inlineDynamicImports: true,
7
- sourcemap: false
8
- }
9
- }