Summary
Running rails g react_on_rails:install --pretend (dry-run mode) does not produce a safe preview — it fully modifies the user's environment and then crashes.
Reproduction
rails new /tmp/test_app --minimal --skip-git
cd /tmp/test_app
# add react_on_rails to Gemfile, bundle install, git init && git commit
rails g react_on_rails:install --pretend
Observed behavior
Two distinct bugs surface:
Bug 1 — Shell commands in ensure_shakapacker_installed run for real:
bundle add shakapacker, bundle install, and rails shakapacker:install are called via system(), which has no knowledge of Thor's --pretend flag. All three execute unconditionally:
- Gemfile is modified:
gem "shakapacker", "= 9.5" added
- Gemfile.lock updated
- 363 npm packages installed into
node_modules/
bin/shakapacker, config/shakapacker.yml, config/webpack/ created on disk
Bug 2 — File.chmod crashes because pretend skipped file creation:
add_bin_scripts uses raw File.chmod(0o755, *files_to_become_executable) after creating files via Thor's directory action. Thor's pretend mode correctly skips writing bin/switch-bundler, but File.chmod is not a Thor action and has no pretend guard — it attempts to chmod the non-existent file and crashes:
File.chmod: No such file or directory @ apply2files - bin/switch-bundler (Errno::ENOENT)
lib/generators/react_on_rails/install_generator.rb:270:in `chmod'
Expected behavior
--pretend should show what the generator would do without making any changes. At minimum, shell commands should be skipped. Ideally, the generator completes cleanly and shows a full preview of all file operations.
Fix direction
- Bug 1: Guard all
system() calls with unless options[:pretend] (or a helper)
- Bug 2: Replace
File.chmod with a Thor-aware equivalent, or guard with unless options[:pretend]
Note: --pretend is a standard Thor/Rails generator runtime flag. This was discovered while investigating pre-existing behavior — not introduced by any recent PR.
Summary
Running
rails g react_on_rails:install --pretend(dry-run mode) does not produce a safe preview — it fully modifies the user's environment and then crashes.Reproduction
Observed behavior
Two distinct bugs surface:
Bug 1 — Shell commands in
ensure_shakapacker_installedrun for real:bundle add shakapacker,bundle install, andrails shakapacker:installare called viasystem(), which has no knowledge of Thor's--pretendflag. All three execute unconditionally:gem "shakapacker", "= 9.5"addednode_modules/bin/shakapacker,config/shakapacker.yml,config/webpack/created on diskBug 2 —
File.chmodcrashes because pretend skipped file creation:add_bin_scriptsuses rawFile.chmod(0o755, *files_to_become_executable)after creating files via Thor'sdirectoryaction. Thor's pretend mode correctly skips writingbin/switch-bundler, butFile.chmodis not a Thor action and has no pretend guard — it attempts to chmod the non-existent file and crashes:Expected behavior
--pretendshould show what the generator would do without making any changes. At minimum, shell commands should be skipped. Ideally, the generator completes cleanly and shows a full preview of all file operations.Fix direction
system()calls withunless options[:pretend](or a helper)File.chmodwith a Thor-aware equivalent, or guard withunless options[:pretend]Note:
--pretendis a standard Thor/Rails generator runtime flag. This was discovered while investigating pre-existing behavior — not introduced by any recent PR.