diff --git a/CHANGELOG.md b/CHANGELOG.md index f846ae5ff..a95ec6ec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ #### Deprecation #### Bug Fixes +- Fix installation crash caused by absolute path for `source_entry_path` in default `config/webpacker.yml` coming from `shakapacker` version 6.x - #1216 ## 2.6.2 diff --git a/lib/generators/react/install_generator.rb b/lib/generators/react/install_generator.rb index 694b3e549..7164cfbfc 100644 --- a/lib/generators/react/install_generator.rb +++ b/lib/generators/react/install_generator.rb @@ -16,6 +16,19 @@ class InstallGenerator < ::Rails::Generators::Base default: false, desc: "Don't generate server_rendering.js or config/initializers/react_server_rendering.rb" + # For Shakapacker below version 7, we need to set relative path for source_entry_path + def modify_webpacker_yml + webpacker_yml_path = 'config/webpacker.yml' + if webpacker? && Pathname.new(webpacker_yml_path).exist? + gsub_file( + webpacker_yml_path, + "source_entry_path: /\n", + "source_entry_path: packs\n" + ) + reloaded_webpacker_config + end + end + # Make an empty `components/` directory in the right place: def create_directory components_dir = if webpacker? @@ -119,6 +132,11 @@ def webpack_source_path Webpacker::Configuration.source_path.join(Webpacker::Configuration.entry_path) # Webpacker <3 end end + + def reloaded_webpacker_config + Webpacker.instance.instance_variable_set(:@config, nil) + Webpacker.config + end end end end