Skip to content

Commit 2f11606

Browse files
authored
Remove PackerUtils.packer abstraction and use Shakapacker directly (#1801)
- Remove unnecessary packer method that was an abstraction layer - Replace all ReactOnRails::PackerUtils.packer calls with ::Shakapacker - Update all tests to mock ::Shakapacker directly instead of packer method - Fix configuration_spec.rb to use direct Shakapacker mocks - Update documentation to consistently use bundle exec rubocop - Simplifies codebase by removing abstraction that's no longer needed - All tests passing, functionality preserved This removes the abstraction layer that was originally created to support multiple webpack tools but is no longer necessary since we only support Shakapacker. The code is now cleaner and more direct.
1 parent 316d356 commit 2f11606

File tree

21 files changed

+335
-254
lines changed

21 files changed

+335
-254
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Changes since the last non-beta release.
3232
#### Bug Fixes
3333

3434
- **Doctor rake task**: Fixed LoadError in `rake react_on_rails:doctor` when using packaged gem. The task was trying to require excluded `rakelib/task_helpers` file. [PR 1795](https://github.com/shakacode/react_on_rails/pull/1795)
35+
- **Shakapacker version requirements**: Fixed inconsistent version requirements between basic pack generation (6.5.1+) and advanced auto-registration features (7.0.0+). Added backward compatibility for users on Shakapacker 6.5.1-6.9.x while providing clear upgrade guidance for advanced features. Added new constants `MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_REGISTRATION` and improved version checking performance with caching. [PR 1798](https://github.com/shakacode/react_on_rails/pull/1798)
36+
37+
#### Code Cleanup
38+
39+
- **PackerUtils abstraction removal**: Removed unnecessary `PackerUtils.packer` abstraction method and replaced all calls with direct `::Shakapacker` usage. This simplifies the codebase by eliminating an abstraction layer that was originally created to support multiple webpack tools but is no longer needed since we only support Shakapacker. All tests updated accordingly. [PR 1798](https://github.com/shakacode/react_on_rails/pull/1798) by [claude-code](https://claude.ai/code)
3540

3641
### [16.0.1-rc.0] - 2025-09-19
3742

docs/contributor-info/linters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If you haven't tried the autofix options for `eslint` and `rubocop`, you're seri
1010
2. **Rubocop:** Be sure to be in the correct directory where you have Ruby files, usually the top level of your Rails project.
1111

1212
```bash
13-
rubocop -a
13+
bundle exec rubocop -a
1414
```
1515

1616
3. **ESLint:** Be sure to be in the correct directory where you have JS files.

docs/guides/configuration.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ ReactOnRails.configure do |config|
195195
# `render_component` and `render_component_hash` view helper methods can
196196
# auto-load the bundle for the generated component, to avoid having to specify the
197197
# bundle manually for each view with the component.
198+
#
199+
# SHAKAPACKER VERSION REQUIREMENTS:
200+
# - Basic pack generation: Shakapacker 6.5.1+
201+
# - Advanced auto-registration with nested entries: Shakapacker 7.0.0+
202+
# - Async loading support: Shakapacker 8.2.0+
203+
#
204+
# Feature Compatibility Matrix:
205+
# | Shakapacker Version | Basic Pack Generation | Auto-Registration | Nested Entries | Async Loading |
206+
# |-------------------|----------------------|-------------------|----------------|---------------|
207+
# | 6.5.1 - 6.9.x | ✅ Yes | ❌ No | ❌ No | ❌ No |
208+
# | 7.0.0 - 8.1.x | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No |
209+
# | 8.2.0+ | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
210+
#
198211
################################################################################
199212
# components_subdirectory is the name of the subdirectory matched to detect and register components automatically
200213
# The default is nil. You can enable the feature by updating it in the next line.
@@ -205,6 +218,8 @@ ReactOnRails.configure do |config|
205218
# Default is false.
206219
# The default can be overridden as an option in calls to view helpers
207220
# `render_component` and `render_component_hash`. You may set to true to change the default to auto loading.
221+
# NOTE: Requires Shakapacker 6.5.1+ for basic functionality, 7.0.0+ for full auto-registration features.
222+
# See version requirements matrix above for complete feature compatibility.
208223
config.auto_load_bundle = false
209224

210225
# Default is false

lib/generators/react_on_rails/base_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def copy_base_files
4141
base_templates = %w[config/initializers/react_on_rails.rb]
4242
base_files.each { |file| copy_file("#{base_path}#{file}", file) }
4343
base_templates.each do |file|
44-
template("#{base_path}/#{file}.tt", file, { packer_type: ReactOnRails::PackerUtils.packer_type })
44+
template("#{base_path}/#{file}.tt", file)
4545
end
4646
end
4747

lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ ReactOnRails.configure do |config|
2424
# to automatically refresh your webpack assets on every test run.
2525
#
2626
# Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
27-
# and set the config/<%= config[:packer_type] %>.yml option for test to true.
28-
config.build_test_command = "RAILS_ENV=test bin/<%= config[:packer_type] %>"
27+
# and set the config/shakapacker.yml option for test to true.
28+
config.build_test_command = "RAILS_ENV=test bin/shakapacker"
2929

3030
################################################################################
3131
################################################################################

lib/react_on_rails/configuration.rb

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def validate_generated_component_packs_loading_strategy
180180
1. Use :sync or :defer loading strategy instead of :async
181181
2. Upgrade to Shakapacker v8.2.0 or above to enable async script loading
182182
MSG
183-
if PackerUtils.shakapacker_version_requirement_met?("8.2.0")
183+
if PackerUtils.supports_async_loading?
184184
self.generated_component_packs_loading_strategy ||= :async
185185
elsif generated_component_packs_loading_strategy.nil?
186186
Rails.logger.warn("**WARNING** #{msg}")
@@ -198,12 +198,19 @@ def check_autobundling_requirements
198198
raise_missing_components_subdirectory if auto_load_bundle && !components_subdirectory.present?
199199
return unless components_subdirectory.present?
200200

201-
ReactOnRails::PackerUtils.raise_shakapacker_not_installed unless ReactOnRails::PackerUtils.using_packer?
202-
ReactOnRails::PackerUtils.raise_shakapacker_version_incompatible_for_autobundling unless
203-
ReactOnRails::PackerUtils.shakapacker_version_requirement_met?(
204-
ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION
205-
)
206-
ReactOnRails::PackerUtils.raise_nested_entries_disabled unless ReactOnRails::PackerUtils.nested_entries?
201+
# Check basic pack generation support for auto_load_bundle
202+
ReactOnRails::PackerUtils.raise_shakapacker_version_incompatible_for_basic_pack_generation unless
203+
ReactOnRails::PackerUtils.supports_basic_pack_generation?
204+
205+
# Additional checks for advanced features requiring nested entries
206+
if ReactOnRails::PackerUtils.supports_autobundling?
207+
ReactOnRails::PackerUtils.raise_nested_entries_disabled unless ReactOnRails::PackerUtils.nested_entries?
208+
else
209+
# Warn users about missing advanced features but don't block basic functionality
210+
min_version = ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_REGISTRATION
211+
Rails.logger.warn("React on Rails: Basic pack generation enabled. " \
212+
"Upgrade to Shakapacker #{min_version}+ for advanced auto-registration features.")
213+
end
207214
end
208215

209216
def adjust_precompile_task
@@ -221,8 +228,8 @@ def adjust_precompile_task
221228
# We set it very big so that it is not used, and then clean just
222229
# removes files older than 1 hour.
223230
versions = 100_000
224-
puts "Invoking task #{ReactOnRails::PackerUtils.packer_type}:clean from React on Rails"
225-
Rake::Task["#{ReactOnRails::PackerUtils.packer_type}:clean"].invoke(versions)
231+
puts "Invoking task shakapacker:clean from React on Rails"
232+
Rake::Task["shakapacker:clean"].invoke(versions)
226233
}
227234

228235
if Rake::Task.task_defined?("assets:precompile")
@@ -237,23 +244,21 @@ def adjust_precompile_task
237244
end
238245

239246
def error_if_using_packer_and_generated_assets_dir_not_match_public_output_path
240-
return unless ReactOnRails::PackerUtils.using_packer?
241-
242247
return if generated_assets_dir.blank?
243248

244249
packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
245250

246251
if File.expand_path(generated_assets_dir) == packer_public_output_path.to_s
247252
Rails.logger.warn("You specified generated_assets_dir in `config/initializers/react_on_rails.rb` " \
248-
"with #{ReactOnRails::PackerUtils.packer_type}. " \
253+
"with shakapacker. " \
249254
"Remove this line from your configuration file.")
250255
else
251256
msg = <<~MSG
252-
Error configuring /config/initializers/react_on_rails.rb: You are using #{ReactOnRails::PackerUtils.packer_type}
253-
and your specified value for generated_assets_dir = #{generated_assets_dir}
254-
that does not match the value for public_output_path specified in
255-
#{ReactOnRails::PackerUtils.packer_type}.yml = #{packer_public_output_path}. You should remove the configuration
256-
value for "generated_assets_dir" from your config/initializers/react_on_rails.rb file.
257+
Configuration mismatch in config/initializers/react_on_rails.rb:
258+
259+
Your generated_assets_dir setting (#{generated_assets_dir}) does not match the value for public_output_path (#{packer_public_output_path}).
260+
261+
Remove the generated_assets_dir configuration and let Shakapacker manage the output path.
257262
MSG
258263
raise ReactOnRails::Error, msg
259264
end
@@ -272,36 +277,22 @@ def check_server_render_method_is_only_execjs
272277
end
273278

274279
def ensure_generated_assets_dir_present
275-
return if generated_assets_dir.present? || ReactOnRails::PackerUtils.using_packer?
280+
return if generated_assets_dir.present?
276281

277-
self.generated_assets_dir = DEFAULT_GENERATED_ASSETS_DIR
278-
Rails.logger.warn "ReactOnRails: Set generated_assets_dir to default: #{DEFAULT_GENERATED_ASSETS_DIR}"
282+
# When using Shakapacker, don't set a default generated_assets_dir since
283+
# Shakapacker manages its own public_output_path configuration
284+
# This prevents configuration mismatches between ReactOnRails and Shakapacker
285+
Rails.logger.warn "ReactOnRails: No generated_assets_dir specified, using Shakapacker public_output_path"
279286
end
280287

281288
def configure_generated_assets_dirs_deprecation
282289
return if generated_assets_dirs.blank?
283290

284-
if ReactOnRails::PackerUtils.using_packer?
285-
packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
286-
# rubocop:disable Layout/LineLength
287-
packer_name = ReactOnRails::PackerUtils.packer_type&.upcase_first
288-
289-
Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the generated_assets_dirs nor " \
290-
"the generated_assets_dir when using #{packer_name}. This is defined by " \
291-
"public_output_path specified in #{ReactOnRails::PackerUtils.packer_type}.yml = #{packer_public_output_path}."
292-
# rubocop:enable Layout/LineLength
293-
return
294-
end
295-
296-
Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config.generated_assets_dir rather than " \
297-
"generated_assets_dirs"
298-
if generated_assets_dir.blank?
299-
self.generated_assets_dir = generated_assets_dirs
300-
else
301-
Rails.logger.warn "[DEPRECATION] ReactOnRails. You have both generated_assets_dirs and " \
302-
"generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Shakapacker " \
303-
"and define neither if using Webpacker"
304-
end
291+
packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
292+
Rails.logger.warn "You specified generated_assets_dirs in `config/initializers/react_on_rails.rb` " \
293+
"with Shakapacker. Remove this configuration as the output path is automatically " \
294+
"determined by `public_output_path` in shakapacker.yml " \
295+
"(currently: #{packer_public_output_path})."
305296
end
306297

307298
def ensure_webpack_generated_files_exists
@@ -333,17 +324,15 @@ def raise_missing_components_subdirectory
333324
end
334325

335326
def compile_command_conflict_message
336-
packer_name = ReactOnRails::PackerUtils.packer_type.upcase_first
337-
packer_type = ReactOnRails::PackerUtils.packer_type
338327
<<~MSG
339328
340-
React on Rails and #{packer_name} error in configuration!
329+
React on Rails and Shakapacker error in configuration!
341330
In order to use config/react_on_rails.rb config.build_production_command,
342-
you must edit config/#{packer_type}.yml to include this value in the default configuration:
343-
'#{packer_type}_precompile: false'
331+
you must edit config/shakapacker.yml to include this value in the default configuration:
332+
'shakapacker_precompile: false'
344333
345334
Alternatively, remove the config/react_on_rails.rb config.build_production_command and the
346-
default bin/#{packer_type} script will be used for assets:precompile.
335+
default bin/shakapacker script will be used for assets:precompile.
347336
348337
MSG
349338
end

0 commit comments

Comments
 (0)