Skip to content

Commit 36f04d8

Browse files
justin808claude
andcommitted
Fix file existence checks in adapt_for_older_shakapacker_generator
Fixes CI failures where generator tests fail due to missing files: - Add File.exist? checks before calling gsub_file on files that may not exist - Add File.exist? check before renaming shakapacker.yml to webpacker.yml - Add File.exist? check before modifying commonWebpackConfig.js The adapt_for_older_shakapacker generator was failing in test environments where config/shakapacker.yml and other expected files don't exist, causing "No such file or directory" errors during RSpec generator tests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4ca85b7 commit 36f04d8

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,28 @@ def change_spelling_to_webpacker
1919
config/shakapacker.yml
2020
config/initializers/react_on_rails.rb
2121
]
22-
files.each { |file| gsub_file(file, "shakapacker", "webpacker") }
22+
files.each { |file| gsub_file(file, "shakapacker", "webpacker") if File.exist?(file) }
2323
end
2424

2525
def rename_config_file
26-
puts "Rename to config/webpacker.yml"
27-
puts "Renaming shakapacker.yml into webpacker.yml"
28-
FileUtils.mv("config/shakapacker.yml", "config/webpacker.yml")
26+
if File.exist?("config/shakapacker.yml")
27+
puts "Rename to config/webpacker.yml"
28+
puts "Renaming shakapacker.yml into webpacker.yml"
29+
FileUtils.mv("config/shakapacker.yml", "config/webpacker.yml")
30+
end
2931
end
3032

3133
def modify_requiring_webpack_config_in_js
32-
puts "Update commonWebpackConfig.js to follow the Shakapacker v6 interface"
3334
file = "config/webpack/commonWebpackConfig.js"
34-
gsub_file(file, "const baseClientWebpackConfig = generateWebpackConfig();\n\n", "")
35-
gsub_file(
36-
file,
37-
"const { generateWebpackConfig, merge } = require('shakapacker');",
38-
"const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');"
39-
)
35+
if File.exist?(file)
36+
puts "Update commonWebpackConfig.js to follow the Shakapacker v6 interface"
37+
gsub_file(file, "const baseClientWebpackConfig = generateWebpackConfig();\n\n", "")
38+
gsub_file(
39+
file,
40+
"const { generateWebpackConfig, merge } = require('shakapacker');",
41+
"const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');"
42+
)
43+
end
4044
end
4145
end
4246
end

0 commit comments

Comments
 (0)