railpack 0.1.9.1 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c397b4ece2e22bc1beea1057b869fea72414420cf13063037e3322724bec937d
4
- data.tar.gz: b09bd032d22a15f2f06c4a2cfb030307752246d8b9a0f6f820a9fe16ab55f756
3
+ metadata.gz: f2b316c03702c30f4d6885d7a6f83b7e04e807e654a3c14452a40549a1a0120a
4
+ data.tar.gz: 52ab40983d2ca98f5729bfe38401aabffdd1b48cd509ab342f0f7696a2deb43c
5
5
  SHA512:
6
- metadata.gz: 6d5c7a27ab052456e27ea1c7913563006af21156156df44f5a4fe370c8101d6aeb6a5a3ebb80ced5fd91726eac90a345a33e9c7d39edf4a48cff40e87f497be4
7
- data.tar.gz: c5a55843ce820c3d1103f67f763221502774625be4ce948ab681140b870344d18a43c52b9469f9ec0f9e1f693a28343e9d518b21c7db5929d0ab5eae69143b89
6
+ metadata.gz: 29fdc731da308f0c928fc1a88e1381c95ec2f14ca5a43b2da6b99396b2e2b7281063412285c28244c1256910d5c73157023295b074c4056a8e0a0d2e49ee40f0
7
+ data.tar.gz: e5d47f045a11a4db727fc03c2c276b5aff6f2879a3f203b171f6eec2849533c1a3a93642d22adf9bad5a78a6f4ad58da077a9afaba21c1b7aca3ede01db8eb45
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-01-26
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 21tycoons LLC
3
+ Copyright (c) 2026 21tycoons LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,31 +1,188 @@
1
1
  # Railpack 🎒
2
2
 
3
- Use webpack/esbuild/bun/rollup to manage JavaScript in your Rails app.
3
+ **Multi-bundler asset pipeline for Rails** - Choose your bundler, unified Rails integration.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **Multiple Bundlers**: Bun, esbuild, Rollup, Webpack support
8
+ - 🔧 **Unified API**: Same interface regardless of bundler
9
+ - 🎯 **Rails Integration**: Seamless asset pipeline integration
10
+ - ⚡ **Hot Module Replacement**: Development server with live reload
11
+ - 🎣 **Event Hooks**: Build lifecycle callbacks
12
+ - 📦 **Production Ready**: Optimized builds for all bundlers
4
13
 
5
14
  ## Installation
6
15
 
7
- Add this line to your application's Gemfile:
16
+ Add to your Gemfile:
8
17
 
9
18
  ```ruby
10
19
  gem 'railpack'
11
20
  ```
12
21
 
13
- And then execute:
22
+ ## Configuration
23
+
24
+ Create `config/railpack.yml`:
25
+
26
+ ```yaml
27
+ # Choose your bundler
28
+ bundler: bun # or 'rollup', 'webpack', 'esbuild'
29
+
30
+ # Global defaults
31
+ default:
32
+ target: browser
33
+ format: esm
34
+ minify: false
35
+ sourcemap: false
36
+ entrypoint: "./app/javascript/application.js"
37
+ outdir: "app/assets/builds"
38
+
39
+ # Bundler-specific config
40
+ bun:
41
+ target: browser
42
+ format: esm
43
+
44
+ # Environment overrides
45
+ development:
46
+ sourcemap: true
47
+
48
+ production:
49
+ minify: true
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ ### Basic Commands
55
+
56
+ ```bash
57
+ # Build for production
58
+ rails railpack:build
59
+
60
+ # Watch and rebuild during development
61
+ rails railpack:watch
62
+
63
+ # Install dependencies
64
+ rails railpack:install
65
+
66
+ # Check current bundler
67
+ rails railpack:bundler
68
+ ```
69
+
70
+ ### Programmatic API
71
+
72
+ ```ruby
73
+ # Build assets
74
+ Railpack.build!
75
+
76
+ # Watch for changes
77
+ Railpack.watch
78
+
79
+ # Install packages
80
+ Railpack.install!
81
+
82
+ # Add dependencies
83
+ Railpack.add('lodash', 'axios')
84
+ ```
85
+
86
+ ### Rails Integration
87
+
88
+ Railpack automatically integrates with Rails asset pipeline:
89
+
90
+ ```ruby
91
+ # config/initializers/railpack.rb
92
+ require 'railpack'
93
+
94
+ # Override config at runtime
95
+ Railpack.config.sourcemap = true
96
+
97
+ # Setup logging
98
+ Railpack.logger = Rails.logger
99
+
100
+ # Build event hooks
101
+ Railpack.on_build_complete do |result|
102
+ Rails.logger.info "Build completed: #{result[:success]}"
103
+ end
104
+ ```
105
+
106
+ ## Supported Bundlers
14
107
 
15
- $ bundle install
108
+ ### Bun (Default)
109
+ - **Fast builds** - Lightning-quick bundling
110
+ - **All-in-one** - Runtime, bundler, package manager
111
+ - **Great DX** - Excellent development experience
16
112
 
17
- Or install it yourself as:
113
+ ### Rollup
114
+ - **Tree shaking** - Optimal bundle sizes
115
+ - **Plugin ecosystem** - Extensive customization
116
+ - **ESM focus** - Modern module system
18
117
 
19
- $ gem install railpack
118
+ ### Webpack
119
+ - **Enterprise** - Battle-tested in production
120
+ - **Feature-rich** - Extensive plugin ecosystem
121
+ - **Legacy support** - Handles all module types
20
122
 
21
- ## Still in Development
123
+ ### esbuild
124
+ - **Speed demon** - 10-100x faster than alternatives
125
+ - **Simple API** - Minimal configuration
126
+ - **Modern features** - ESM, minification, sourcemaps
22
127
 
23
- NOT READY YET, FEEL FREE TO CONTRIBUTE. 👍
128
+ ## Switching Bundlers
129
+
130
+ Change the `bundler` setting in `config/railpack.yml`:
131
+
132
+ ```yaml
133
+ bundler: esbuild # Switch to esbuild for speed
134
+ ```
135
+
136
+ Or use esbuild:
137
+
138
+ ```yaml
139
+ bundler: esbuild
140
+
141
+ esbuild:
142
+ platform: browser
143
+ target: es2015
144
+ minify: true
145
+ ```
146
+
147
+ Railpack handles the rest - same API, different bundler under the hood.
148
+
149
+ ## Development
150
+
151
+ ### Adding a New Bundler
152
+
153
+ 1. Create bundler class:
154
+ ```ruby
155
+ # lib/railpack/bundlers/my_bundler.rb
156
+ class Railpack::MyBundler < Railpack::Bundler
157
+ def commands
158
+ { build: "my-build", watch: "my-watch" }
159
+ end
160
+
161
+ def build!(args = [])
162
+ execute!([commands[:build], *args])
163
+ end
164
+ end
165
+ ```
166
+
167
+ 2. Register in Manager:
168
+ ```ruby
169
+ BUNDLERS = {
170
+ 'bun' => BunBundler,
171
+ 'my' => MyBundler # Add here
172
+ }
173
+ ```
24
174
 
25
175
  ## Contributing
26
176
 
27
- Bug reports and pull requests are welcome on GitHub at https://github.com/21tycoons/railpack.
177
+ 1. Fork the repo
178
+ 2. Add your bundler implementation
179
+ 3. Update documentation
180
+ 4. Submit a PR
28
181
 
29
182
  ## License
30
183
 
31
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
184
+ MIT License - see LICENSE.txt
185
+
186
+ ## Credits
187
+
188
+ Built by 21tycoons LLC for the Rails community.
data/Rakefile CHANGED
@@ -9,4 +9,8 @@ Rake::TestTask.new(:test) do |t|
9
9
  t.test_files = FileList["test/**/*_test.rb"]
10
10
  end
11
11
 
12
- task default: :test
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,42 @@
1
+ module Railpack
2
+ class Bundler
3
+ attr_reader :config
4
+
5
+ def initialize(config)
6
+ @config = config
7
+ end
8
+
9
+ # Common interface all bundlers must implement
10
+ def build!(args = [])
11
+ raise NotImplementedError, "#{self.class.name} must implement #build!"
12
+ end
13
+
14
+ def watch(args = [])
15
+ raise NotImplementedError, "#{self.class.name} must implement #watch"
16
+ end
17
+
18
+ def install!(args = [])
19
+ raise NotImplementedError, "#{self.class.name} must implement #install!"
20
+ end
21
+
22
+ def name
23
+ self.class.name.split('::').last.sub('_bundler', '').downcase
24
+ end
25
+
26
+ def commands
27
+ raise NotImplementedError, "#{self.class.name} must implement #commands"
28
+ end
29
+
30
+ protected
31
+
32
+ def execute(command_array)
33
+ system(*command_array)
34
+ end
35
+
36
+ def execute!(command_array)
37
+ success = system(*command_array)
38
+ raise Error, "Command failed: #{command_array.join(' ')}" unless success
39
+ success
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ module Railpack
2
+ class BunBundler < Bundler
3
+ def commands
4
+ {
5
+ build: "bun run build",
6
+ watch: "bun run watch",
7
+ build_dev: "bun run build:development",
8
+ clean: "bun run clean",
9
+ install: "bun install",
10
+ add: "bun add",
11
+ remove: "bun remove",
12
+ exec: "bun",
13
+ version: "bun --version"
14
+ }
15
+ end
16
+
17
+ def build!(args = [])
18
+ execute!([commands[:build], *args])
19
+ end
20
+
21
+ def watch(args = [])
22
+ execute([commands[:watch], *args])
23
+ end
24
+
25
+ def install!(args = [])
26
+ execute!([commands[:install], *args])
27
+ end
28
+
29
+ def add(*packages)
30
+ execute([commands[:add], *packages])
31
+ end
32
+
33
+ def remove(*packages)
34
+ execute([commands[:remove], *packages])
35
+ end
36
+
37
+ def exec(*args)
38
+ execute([commands[:exec], *args])
39
+ end
40
+
41
+ def version
42
+ `#{commands[:version]}`.strip
43
+ end
44
+
45
+ def installed?
46
+ system("#{commands[:version]} > /dev/null 2>&1")
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ module Railpack
2
+ class EsbuildBundler < Bundler
3
+ def commands
4
+ {
5
+ build: "esbuild",
6
+ watch: "esbuild --watch",
7
+ build_dev: "esbuild",
8
+ clean: "rm -rf dist/",
9
+ install: "npm install",
10
+ add: "npm install",
11
+ remove: "npm uninstall",
12
+ exec: "node",
13
+ version: "esbuild --version"
14
+ }
15
+ end
16
+
17
+ def build!(args = [])
18
+ execute!([commands[:build], *args])
19
+ end
20
+
21
+ def watch(args = [])
22
+ execute([commands[:watch], *args])
23
+ end
24
+
25
+ def install!(args = [])
26
+ execute!([commands[:install], *args])
27
+ end
28
+
29
+ def add(*packages)
30
+ execute([commands[:add], *packages])
31
+ end
32
+
33
+ def remove(*packages)
34
+ execute([commands[:remove], *packages])
35
+ end
36
+
37
+ def exec(*args)
38
+ execute([commands[:exec], *args])
39
+ end
40
+
41
+ def version
42
+ `#{commands[:version]}`.strip
43
+ end
44
+
45
+ def installed?
46
+ system("#{commands[:version]} > /dev/null 2>&1")
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,155 @@
1
+ require "yaml"
2
+
3
+ module Railpack
4
+ class Config
5
+ class Error < StandardError; end
6
+
7
+ attr_reader :config
8
+
9
+ def initialize
10
+ @config = load_config
11
+ end
12
+
13
+ def current_env
14
+ if defined?(Rails) && Rails.respond_to?(:env)
15
+ Rails.env
16
+ else
17
+ :development
18
+ end
19
+ end
20
+
21
+ def for_environment(env = current_env)
22
+ base_config = @config["default"] || {}
23
+ bundler_config = bundler_config(env)
24
+ env_config = @config[env.to_s] || {}
25
+
26
+ # Merge: default <- bundler <- environment
27
+ deep_merge(deep_merge(base_config, bundler_config), env_config)
28
+ end
29
+
30
+ def bundler(env = current_env)
31
+ # Look directly in config to avoid circular dependency
32
+ env_config = @config[env.to_s] || {}
33
+ default_config = @config["default"] || {}
34
+ env_config['bundler'] || default_config['bundler'] || 'bun'
35
+ end
36
+
37
+ def bundler_config(env = current_env)
38
+ bundler_name = bundler(env)
39
+ @config[bundler_name] || {}
40
+ end
41
+
42
+ def method_missing(method, *args)
43
+ config_key = method.to_s
44
+ if method.end_with?('=')
45
+ # Setter - allow initializer to override config
46
+ key = config_key.chomp('=')
47
+ @config[current_env.to_s] ||= {}
48
+ @config[current_env.to_s][key] = args.first
49
+ else
50
+ # Getter - read from merged config
51
+ env = args.first || current_env
52
+ return for_environment(env)[config_key] if for_environment(env).key?(config_key)
53
+ super
54
+ end
55
+ end
56
+
57
+ def respond_to_missing?(method, include_private = false)
58
+ config_key = method.to_s.chomp('=')
59
+ env = current_env
60
+ for_environment(env).key?(config_key) || super
61
+ end
62
+
63
+ # Build command flags from config
64
+ def build_flags(env = current_env)
65
+ cfg = for_environment(env)
66
+ flags = []
67
+
68
+ flags << "--target=#{cfg['target']}" if cfg['target']
69
+ flags << "--format=#{cfg['format']}" if cfg['format']
70
+ flags << "--minify" if cfg['minify']
71
+ flags << "--sourcemap" if cfg['sourcemap']
72
+ flags << "--splitting" if cfg['splitting']
73
+
74
+ flags
75
+ end
76
+
77
+ # Build command arguments
78
+ def build_args(env = current_env)
79
+ cfg = for_environment(env)
80
+ args = []
81
+
82
+ # Support multiple entrypoints or single entrypoint
83
+ entrypoints = cfg['entrypoints']
84
+ if entrypoints.is_a?(Array) && entrypoints.any?
85
+ args.concat(entrypoints)
86
+ elsif cfg['entrypoint'].is_a?(String) && !cfg['entrypoint'].empty?
87
+ args << cfg['entrypoint']
88
+ end
89
+
90
+ args << "--outdir=#{cfg['outdir']}" if cfg['outdir']
91
+ args.concat(build_flags(env))
92
+
93
+ args
94
+ end
95
+
96
+ private
97
+
98
+ def config_path
99
+ if defined?(Rails) && Rails.respond_to?(:root)
100
+ Rails.root.join("config", "railpack.yml")
101
+ else
102
+ Pathname.new("config/railpack.yml")
103
+ end
104
+ end
105
+
106
+ def load_config
107
+ if config_path.exist?
108
+ YAML.safe_load(File.read(config_path), aliases: true)
109
+ else
110
+ default_config
111
+ end
112
+ rescue Psych::SyntaxError => e
113
+ raise Error, "Invalid YAML in #{config_path}: #{e.message}"
114
+ end
115
+
116
+ def default_config
117
+ {
118
+ "default" => {
119
+ "bundler" => "bun",
120
+ "target" => "browser",
121
+ "format" => "esm",
122
+ "minify" => false,
123
+ "sourcemap" => false,
124
+ "entrypoint" => "./app/javascript/application.js",
125
+ "outdir" => "app/assets/builds"
126
+ },
127
+ "bun" => {
128
+ "target" => "browser",
129
+ "format" => "esm"
130
+ },
131
+ "esbuild" => {
132
+ "target" => "browser",
133
+ "format" => "esm",
134
+ "platform" => "browser"
135
+ },
136
+ "development" => {
137
+ "sourcemap" => true
138
+ },
139
+ "production" => {
140
+ "minify" => true
141
+ }
142
+ }
143
+ end
144
+
145
+ def deep_merge(hash1, hash2)
146
+ hash1.merge(hash2) do |key, old_val, new_val|
147
+ if old_val.is_a?(Hash) && new_val.is_a?(Hash)
148
+ deep_merge(old_val, new_val)
149
+ else
150
+ new_val
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end