From 4d006ffd3c1ebeb6ace204460c473efd02c948a9 Mon Sep 17 00:00:00 2001 From: Mikhail Boutylin Date: Tue, 11 Jun 2024 11:48:41 +0400 Subject: [PATCH] added support for shakapacker 8+ --- CHANGELOG.md | 8 +++++++- docs/getting-started.md | 3 ++- lib/generators/react_on_rails/base_generator.rb | 3 +-- lib/generators/react_on_rails/install_generator.rb | 8 ++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f04b26c7..bf048ba23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac ### [Unreleased] Changes since the last non-beta release. +### [14.0.2] - 2024-06-11 + +#### Fixed +- Project initialization with Shakapacker v8+ fixed [PR 1629](https://github.com/shakacode/react_on_rails/pull/1629) by [vaukalak](https://github.com/vaukalak) + ### [14.0.1] - 2024-05-16 #### Fixed @@ -1128,7 +1133,8 @@ Best done with Object destructing: ##### Fixed - Fix several generator-related issues. -[Unreleased]: https://github.com/shakacode/react_on_rails/compare/14.0.1...master +[Unreleased]: https://github.com/shakacode/react_on_rails/compare/14.0.2...master +[14.0.2]: https://github.com/shakacode/react_on_rails/compare/14.0.1...14.0.2 [14.0.1]: https://github.com/shakacode/react_on_rails/compare/14.0.0...14.0.1 [14.0.0]: https://github.com/shakacode/react_on_rails/compare/13.4.0...14.0.0 [13.4.0]: https://github.com/shakacode/react_on_rails/compare/13.3.5...13.4.0 diff --git a/docs/getting-started.md b/docs/getting-started.md index e26f490a0..05500a53d 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -17,7 +17,8 @@ You need a Rails application with Shakapacker installed and configured on it. Ch rails new PROJECT_NAME --skip-javascript cd PROJECT_NAME bundle add shakapacker --strict -rails shakapacker:install +# currently react_on_rails uses yarn classic by default +PACKAGE_JSON_FALLBACK_MANAGER=yarn_classic rails shakapacker:install ``` You may need to check [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/) if you have an already working Rails application. diff --git a/lib/generators/react_on_rails/base_generator.rb b/lib/generators/react_on_rails/base_generator.rb index 08f76b53f..14148dfc9 100644 --- a/lib/generators/react_on_rails/base_generator.rb +++ b/lib/generators/react_on_rails/base_generator.rb @@ -40,8 +40,7 @@ def copy_base_files def copy_js_bundle_files base_path = "base/base/" base_files = %w[app/javascript/packs/server-bundle.js - app/javascript/bundles/HelloWorld/components/HelloWorldServer.js - app/javascript/bundles/HelloWorld/components/HelloWorld.module.css] + app/javascript/bundles/HelloWorld/components/HelloWorldServer.js] base_files.each { |file| copy_file("#{base_path}#{file}", file) } end diff --git a/lib/generators/react_on_rails/install_generator.rb b/lib/generators/react_on_rails/install_generator.rb index a3d7c36f2..651af8d04 100644 --- a/lib/generators/react_on_rails/install_generator.rb +++ b/lib/generators/react_on_rails/install_generator.rb @@ -54,7 +54,7 @@ def invoke_generators invoke "react_on_rails:react_no_redux" end - invoke "react_on_rails:adapt_for_older_shakapacker" unless using_shakapacker_7? + invoke "react_on_rails:adapt_for_older_shakapacker" unless using_shakapacker_7_or_above? end # NOTE: other requirements for existing files such as .gitignore or application. @@ -95,7 +95,7 @@ def add_bin_scripts def add_post_install_message message = GeneratorMessages.helpful_message_after_installation - unless using_shakapacker_7? + unless using_shakapacker_7_or_above? message = message.gsub("config/shakapacker", "config/webpacker") message = message.gsub("bin/shakapacker", "bin/webpacker") end @@ -103,9 +103,9 @@ def add_post_install_message GeneratorMessages.add_info(message) end - def using_shakapacker_7? + def using_shakapacker_7_or_above? shakapacker_gem = Gem::Specification.find_by_name("shakapacker") - shakapacker_gem.version.segments.first == 7 + shakapacker_gem.version.segments.first >= 7 rescue Gem::MissingSpecError # In case using Webpacker false