railpack 1.2.3 → 1.2.5

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: 269e75f35771ec905394623faa61366d3c7208ea4f21cb867c8a10dc733ff9cc
4
- data.tar.gz: 925c4070f7f2888cc7e260cab0ff3617d1ac0151dfc190c6b9ccd1d7a4baf9bf
3
+ metadata.gz: b13af1329c7192e2a8fd5c83eb0cc9ff07a0edec87b7311dedae0f26b4710975
4
+ data.tar.gz: 757f2eedf1421e59d9ae165f13a353918cdad3bad8cee83cdf0bc60078ede4d1
5
5
  SHA512:
6
- metadata.gz: fa4ef98d5320a341ef6fb6c0d103ef83aee393b2efd346c132299c842046f17b885f1ea5da84e549dc91fc0de5d83fac00a20c3155000f6f0b4cbb9da9b018a6
7
- data.tar.gz: bd4178182819778bbd1d7716a660030904099eee0af4c3f127d906afa1a0c4cd49590903ab7ca9690042c1addfa190943452a79e01395d828294f194d3794ef8
6
+ metadata.gz: f14bb9cb2f37592089c517a4c8dcd16185bf9fa6d5029344031c58e9f54baa1cea24a0542bb8059f96acc59d54d0aec00b3c783f787ba5188743553b63864777
7
+ data.tar.gz: 17748f4d280fbfebefec259db9525daf4609285886a98a0027cd29a53a1c5a8aa0ff3007e05ffed4c96802a048d58cceae3ec2d056ab50f9c953f7d3e276ad40
data/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.2.5] - 2026-01-26
4
+
5
+ - Add test_config_yaml_file_loading test for YAML config file loading
6
+ - Test that Railpack correctly reads config/railpack.yml from Rails.root
7
+ - Test bundler selection, environment overrides, and config merging
8
+ - All 19 tests passing with 72 assertions
9
+
10
+ ## [1.2.4] - 2026-01-26
11
+
12
+ - Add comprehensive test suite (19 tests, 72 assertions)
13
+ - Test config system including YAML file loading from Rails.root
14
+ - Test bundler implementations, manager features, event hooks
15
+ - Test error handling, asset manifest generation, bundle size calculation
16
+ - Test Rails integration and environment overrides
17
+ - Add default logger with Logger.new($stdout)
18
+ - Fix logger nil issues in manager
19
+
20
+ ## [1.2.3] - 2026-01-26
21
+
22
+ - Add install scaffold generator (`rails railpack:install`)
23
+ - Create default `config/railpack.yml` with sensible Rails defaults
24
+ - Add `rails railpack:install:force` for overwriting existing config
25
+ - Update README with install instructions
26
+ - Similar to jsbundling install experience
27
+
3
28
  ## [1.2.2] - 2026-01-26
4
29
 
5
30
  - Fix asset manifest generation for Propshaft compatibility
@@ -1,3 +1,3 @@
1
1
  module Railpack
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.5"
3
3
  end
data/lib/railpack.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # Railpack - Multi-bundler asset pipeline for Rails
2
+ require 'logger'
2
3
  require_relative "railpack/version"
3
4
  require_relative "railpack/bundler"
4
5
  require_relative "railpack/bundlers/bun_bundler"
@@ -12,7 +13,11 @@ module Railpack
12
13
  class Error < StandardError; end
13
14
 
14
15
  class << self
15
- attr_accessor :logger
16
+ attr_writer :logger
17
+
18
+ def logger
19
+ @logger ||= Logger.new($stdout)
20
+ end
16
21
 
17
22
  def config
18
23
  @config ||= Config.new
@@ -1,18 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'minitest/autorun'
4
+ require 'tempfile'
5
+ require 'fileutils'
6
+ require 'pathname'
7
+ require 'json'
4
8
  require 'railpack'
5
9
 
6
10
  class RailpackTest < Minitest::Test
11
+ def setup
12
+ # Create a temporary directory for testing
13
+ @temp_dir = Dir.mktmpdir
14
+ @original_rails_root = nil
15
+ if defined?(Rails) && Rails.respond_to?(:root)
16
+ @original_rails_root = Rails.singleton_class.instance_method(:root)
17
+ end
18
+ end
19
+
20
+ def teardown
21
+ FileUtils.remove_entry(@temp_dir) if @temp_dir && Dir.exist?(@temp_dir)
22
+ # Restore original Rails.root method if it was overridden
23
+ if @original_rails_root && defined?(Rails)
24
+ Rails.singleton_class.define_method(:root, @original_rails_root)
25
+ end
26
+ end
27
+
7
28
  def test_version
8
29
  refute_nil ::Railpack::VERSION
30
+ assert_match(/\d+\.\d+\.\d+/, ::Railpack::VERSION)
9
31
  end
10
32
 
11
- def test_config
33
+ def test_config_instance
12
34
  assert_instance_of Railpack::Config, Railpack.config
13
35
  end
14
36
 
15
- def test_manager
37
+ def test_manager_instance
16
38
  assert_instance_of Railpack::Manager, Railpack.manager
17
39
  end
18
40
 
@@ -26,4 +48,230 @@ class RailpackTest < Minitest::Test
26
48
  assert_equal Railpack::RollupBundler, Railpack::Manager::BUNDLERS['rollup']
27
49
  assert_equal Railpack::WebpackBundler, Railpack::Manager::BUNDLERS['webpack']
28
50
  end
51
+
52
+ def test_config_loading_without_rails
53
+ # Test config loading without Rails.root
54
+ config = Railpack::Config.new
55
+ assert_equal 'bun', config.bundler
56
+ assert_equal './app/javascript/application.js', config.entrypoint
57
+ end
58
+
59
+ def test_config_yaml_file_loading
60
+ # Test that Railpack can load config from a YAML file
61
+ config_dir = File.join(@temp_dir, 'config')
62
+ FileUtils.mkdir_p(config_dir)
63
+ config_file = File.join(config_dir, 'railpack.yml')
64
+
65
+ File.write(config_file, <<~YAML)
66
+ default:
67
+ bundler: rollup
68
+ target: node
69
+ format: cjs
70
+ entrypoint: "./server.js"
71
+ outdir: "dist"
72
+ minify: false
73
+ development:
74
+ sourcemap: true
75
+ production:
76
+ minify: true
77
+ sourcemap: false
78
+ YAML
79
+
80
+ # Verify the file was created
81
+ assert File.exist?(config_file), "Config file should exist at #{config_file}"
82
+
83
+ # Mock Rails.root to point to our temp directory
84
+ mock_rails_root(@temp_dir)
85
+
86
+ # Create a fresh config instance to test file loading
87
+ config = Railpack::Config.new
88
+
89
+
90
+
91
+ # Test that the YAML file was loaded correctly
92
+ assert_equal 'rollup', config.bundler
93
+ assert_equal './server.js', config.entrypoint
94
+ assert_equal 'dist', config.outdir
95
+ assert_equal 'node', config.target
96
+ assert_equal 'cjs', config.format
97
+ assert_equal false, config.minify
98
+
99
+ # Test environment overrides
100
+ dev_config = config.for_environment('development')
101
+ prod_config = config.for_environment('production')
102
+
103
+ assert_equal true, dev_config['sourcemap']
104
+ assert_equal true, prod_config['minify']
105
+ assert_equal false, prod_config['sourcemap']
106
+ end
107
+
108
+ def test_config_environment_overrides
109
+ # Test environment override logic with default config
110
+ config = Railpack::Config.new
111
+ dev_config = config.for_environment('development')
112
+ prod_config = config.for_environment('production')
113
+
114
+ # Development should have sourcemap enabled by default
115
+ assert_equal true, dev_config['sourcemap']
116
+ # Production should have minify enabled by default
117
+ assert_equal true, prod_config['minify']
118
+ end
119
+
120
+ def test_config_build_flags
121
+ # Test build flags generation with default config
122
+ config = Railpack::Config.new
123
+ flags = config.build_flags
124
+
125
+ assert_includes flags, '--target=browser'
126
+ assert_includes flags, '--format=esm'
127
+ end
128
+
129
+ def test_config_build_args
130
+ # Test build args generation with default config
131
+ config = Railpack::Config.new
132
+ args = config.build_args
133
+
134
+ assert_includes args, './app/javascript/application.js'
135
+ assert_includes args, '--outdir=app/assets/builds'
136
+ assert_includes args, '--target=browser'
137
+ assert_includes args, '--format=esm'
138
+ end
139
+
140
+ def test_manager_bundle_size_calculation
141
+ # Create test output directory with fake assets
142
+ outdir = File.join(@temp_dir, 'builds')
143
+ FileUtils.mkdir_p(outdir)
144
+
145
+ # Create fake JS and CSS files
146
+ File.write(File.join(outdir, 'app.js'), 'console.log("test");')
147
+ File.write(File.join(outdir, 'app.css'), 'body { color: red; }')
148
+ File.write(File.join(outdir, 'app.js.map'), '{"version":3}')
149
+
150
+ config = { 'outdir' => outdir }
151
+ manager = Railpack::Manager.new
152
+
153
+ size = manager.send(:calculate_bundle_size, config)
154
+ assert size.is_a?(Float)
155
+ assert size > 0
156
+ end
157
+
158
+ def test_manager_asset_manifest_generation
159
+ outdir = File.join(@temp_dir, 'builds')
160
+ FileUtils.mkdir_p(outdir)
161
+
162
+ # Create fake built assets
163
+ File.write(File.join(outdir, 'application.js'), 'console.log("app");')
164
+ File.write(File.join(outdir, 'application.css'), 'body { color: blue; }')
165
+
166
+ config = { 'outdir' => outdir }
167
+ manager = Railpack::Manager.new
168
+
169
+ manager.send(:generate_asset_manifest, config)
170
+
171
+ manifest_path = File.join(outdir, '.manifest.json')
172
+ assert File.exist?(manifest_path)
173
+
174
+ manifest = JSON.parse(File.read(manifest_path))
175
+ assert manifest.key?('application.js')
176
+ assert manifest.key?('application.css')
177
+ assert manifest['application.js']['logical_path'] == 'application.js'
178
+ end
179
+
180
+ def test_bundler_base_class
181
+ bundler = Railpack::Bundler.new({})
182
+
183
+ assert_respond_to bundler, :build!
184
+ assert_respond_to bundler, :watch
185
+ assert_respond_to bundler, :install!
186
+ assert_respond_to bundler, :name
187
+ assert_respond_to bundler, :commands
188
+ end
189
+
190
+ def test_bun_bundler_commands
191
+ bundler = Railpack::BunBundler.new({})
192
+ commands = bundler.send(:commands)
193
+
194
+ assert_equal 'bun run build', commands[:build]
195
+ assert_equal 'bun run watch', commands[:watch]
196
+ assert_equal 'bun install', commands[:install]
197
+ end
198
+
199
+ def test_esbuild_bundler_commands
200
+ bundler = Railpack::EsbuildBundler.new({})
201
+ commands = bundler.send(:commands)
202
+
203
+ assert_equal 'esbuild', commands[:build]
204
+ assert_equal 'esbuild --watch', commands[:watch]
205
+ assert_equal 'npm install', commands[:install]
206
+ end
207
+
208
+ def test_rollup_bundler_commands
209
+ bundler = Railpack::RollupBundler.new({})
210
+ commands = bundler.send(:commands)
211
+
212
+ assert_equal 'rollup', commands[:build]
213
+ assert_equal 'rollup --watch', commands[:watch]
214
+ assert_equal 'npm install', commands[:install]
215
+ end
216
+
217
+ def test_webpack_bundler_commands
218
+ bundler = Railpack::WebpackBundler.new({})
219
+ commands = bundler.send(:commands)
220
+
221
+ assert_equal 'webpack', commands[:build]
222
+ assert_equal 'webpack --watch', commands[:watch]
223
+ assert_equal 'npm install', commands[:install]
224
+ end
225
+
226
+ def test_event_hooks
227
+ events = []
228
+ Railpack.on_build_start { |config| events << [:start, config] }
229
+ Railpack.on_build_complete { |result| events << [:complete, result] }
230
+
231
+ # Trigger build to test hooks
232
+ manager = Railpack::Manager.new
233
+ config = Railpack.config.for_environment
234
+
235
+ # Mock a simple build that doesn't actually execute
236
+ manager.instance_variable_set(:@bundler, Minitest::Mock.new)
237
+ manager.instance_variable_get(:@bundler).expect(:build!, true, [[]])
238
+
239
+ Railpack.trigger_build_start(config)
240
+ Railpack.trigger_build_complete({ success: true })
241
+
242
+ assert_equal 2, events.size
243
+ assert_equal [:start, config], events[0]
244
+ assert_equal [:complete, { success: true }], events[1]
245
+ end
246
+
247
+ def test_error_handling
248
+ error = nil
249
+ Railpack.on_error { |err| error = err }
250
+
251
+ begin
252
+ raise StandardError.new("Test error")
253
+ rescue => e
254
+ Railpack.trigger_error(e)
255
+ end
256
+
257
+ assert_equal "Test error", error.message
258
+ end
259
+
260
+ def test_logger_integration
261
+ # Test that logger methods exist
262
+ assert_respond_to Railpack, :logger
263
+ assert_respond_to Railpack, :logger=
264
+ end
265
+
266
+ private
267
+
268
+ def mock_rails_root(path)
269
+ rails_module = if defined?(Rails)
270
+ Rails
271
+ else
272
+ Object.const_set(:Rails, Module.new)
273
+ end
274
+
275
+ rails_module.define_singleton_method(:root) { Pathname.new(path) }
276
+ end
29
277
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - 21tycoons LLC