Skip to content

Commit d07e763

Browse files
justin808claude
andcommitted
Restore version checking methods and add AUTO_BUNDLING constant
- Add caching to shakapacker_version_requirement_met? for performance - Add supports_basic_pack_generation? and supports_autobundling? methods - Add MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_BUNDLING constant - Restore raise_shakapacker_version_incompatible_for_autobundling method - Add raise_shakapacker_version_incompatible_for_basic_pack_generation method - Update error messages to reference correct constants and include guidance - Make generated_assets_dirs configuration throw exception instead of deprecation BREAKING CHANGE: The `config.generated_assets_dirs` configuration option is no longer supported since Shakapacker is now required. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent aaad32f commit d07e763

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ After a release, please make sure to run `bundle exec rake update_changelog`. Th
2323

2424
Changes since the last non-beta release.
2525

26+
#### Breaking Changes
27+
28+
- **Removed `generated_assets_dirs` configuration**: The legacy `config.generated_assets_dirs` option is no longer supported and will raise an error if used. Since Shakapacker is now required, asset paths are automatically determined from `shakapacker.yml` configuration. Remove any `config.generated_assets_dirs` from your `config/initializers/react_on_rails.rb` file. Use `public_output_path` in `config/shakapacker.yml` to customize asset output location instead. [PR 1798](https://github.com/shakacode/react_on_rails/pull/1798)
29+
2630
#### New Features
2731

2832
- **Server Bundle Security**: Added new configuration options for enhanced server bundle security and organization:

lib/react_on_rails/configuration.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,20 +306,20 @@ def ensure_generated_assets_dir_present
306306
def configure_generated_assets_dirs_deprecation
307307
return if generated_assets_dirs.blank?
308308

309-
# With Shakapacker always available:
310309
packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
311-
# rubocop:disable Layout/LineLength
312-
Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the generated_assets_dirs nor " \
313-
"the generated_assets_dir when using Shakapacker. This is defined by " \
314-
"public_output_path specified in shakapacker.yml = #{packer_public_output_path}."
315-
# rubocop:enable Layout/LineLength
316-
if generated_assets_dir.blank?
317-
self.generated_assets_dir = generated_assets_dirs
318-
else
319-
Rails.logger.warn "[DEPRECATION] ReactOnRails. You have both generated_assets_dirs and " \
320-
"generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Shakapacker " \
321-
"and define neither if using Webpacker"
322-
end
310+
311+
msg = <<~MSG
312+
ReactOnRails Configuration Error: The 'generated_assets_dirs' configuration option is no longer supported.
313+
314+
Since Shakapacker is now required, asset paths are automatically determined from your shakapacker.yml configuration.
315+
316+
Please remove 'config.generated_assets_dirs' from your config/initializers/react_on_rails.rb file.
317+
Assets will be loaded from: #{packer_public_output_path}
318+
319+
If you need to customize the output path, configure it in config/shakapacker.yml under 'public_output_path'.
320+
MSG
321+
322+
raise ReactOnRails::Error, msg
323323
end
324324

325325
def ensure_webpack_generated_files_exists

lib/react_on_rails/packer_utils.rb

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,21 @@ def self.shakapacker_version_as_array
2626
end
2727

2828
def self.shakapacker_version_requirement_met?(required_version)
29-
Gem::Version.new(shakapacker_version) >= Gem::Version.new(required_version)
29+
@version_checks ||= {}
30+
@version_checks[required_version] ||= Gem::Version.new(shakapacker_version) >= Gem::Version.new(required_version)
3031
end
3132

32-
def self.supports_autobundling?
33+
def self.supports_async_loading?
34+
shakapacker_version_requirement_met?("8.2.0")
35+
end
36+
37+
def self.supports_basic_pack_generation?
3338
shakapacker_version_requirement_met?(ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION)
3439
end
3540

36-
def self.supports_async_loading?
37-
shakapacker_version_requirement_met?("8.2.0")
41+
def self.supports_autobundling?
42+
min_version = ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_BUNDLING
43+
::Shakapacker.config.respond_to?(:nested_entries?) && shakapacker_version_requirement_met?(min_version)
3844
end
3945

4046
# This returns either a URL for the webpack-dev-server, non-server bundle or
@@ -137,9 +143,19 @@ def self.raise_nested_entries_disabled
137143

138144
def self.raise_shakapacker_version_incompatible_for_autobundling
139145
msg = <<~MSG
140-
**ERROR** ReactOnRails: Please upgrade Shakapacker to version #{ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION} or \
141-
above to use the automated bundle generation feature. The currently installed version is \
142-
#{ReactOnRails::PackerUtils.shakapacker_version}.
146+
**ERROR** ReactOnRails: Please upgrade ::Shakapacker to version #{ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_BUNDLING} or \
147+
above to use the automated bundle generation feature (which requires nested_entries support). \
148+
The currently installed version is #{ReactOnRails::PackerUtils.shakapacker_version}. \
149+
Basic pack generation requires ::Shakapacker #{ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION} or above.
150+
MSG
151+
152+
raise ReactOnRails::Error, msg
153+
end
154+
155+
def self.raise_shakapacker_version_incompatible_for_basic_pack_generation
156+
msg = <<~MSG
157+
**ERROR** ReactOnRails: Please upgrade ::Shakapacker to version #{ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION} or \
158+
above to use basic pack generation features. The currently installed version is #{ReactOnRails::PackerUtils.shakapacker_version}.
143159
MSG
144160

145161
raise ReactOnRails::Error, msg

lib/react_on_rails/packs_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class PacksGenerator
99
CONTAINS_CLIENT_OR_SERVER_REGEX = /\.(server|client)($|\.)/
1010
COMPONENT_EXTENSIONS = /\.(jsx?|tsx?)$/
1111
MINIMUM_SHAKAPACKER_VERSION = "6.5.1"
12+
MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_BUNDLING = "7.0.0"
1213

1314
def self.instance
1415
@instance ||= PacksGenerator.new

0 commit comments

Comments
 (0)