Skip to content

Commit 719c53f

Browse files
justin808claude
andcommitted
Fix webpack config backup bug - copy actual file instead of template
The backup operation was incorrectly using copy_file() which copies from the generator's template directory, not the user's actual webpack config. This would fail or backup the wrong file. Fixed by: - Adding require 'fileutils' - Using FileUtils.cp() to copy the actual user's webpack config file - Adding existence check before copying to prevent errors - Keeping the same backup path and success message 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent ce3a7ba commit 719c53f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/generators/react_on_rails/base_generator.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "rails/generators"
4+
require "fileutils"
45
require_relative "generator_messages"
56
require_relative "generator_helper"
67
module ReactOnRails
@@ -214,8 +215,10 @@ def handle_custom_webpack_config(base_path, config, webpack_config_path)
214215
if yes?("Replace webpack.config.js with React on Rails version? (Y/n)")
215216
# Create backup
216217
backup_path = "#{webpack_config_path}.backup"
217-
copy_file(webpack_config_path, backup_path)
218-
puts " #{set_color('create', :green)} #{backup_path} (backup of your custom config)"
218+
if File.exist?(webpack_config_path)
219+
FileUtils.cp(webpack_config_path, backup_path)
220+
puts " #{set_color('create', :green)} #{backup_path} (backup of your custom config)"
221+
end
219222

220223
template("#{base_path}/#{webpack_config_path}.tt", webpack_config_path, config)
221224
else

0 commit comments

Comments
 (0)