Skip to content

rails g react_on_rails:install --pretend runs shell commands for real and crashes #2490

@ihabadham

Description

@ihabadham

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.

Metadata

Metadata

Assignees

Labels

Metr-PendingPending Metr trackingP1Target this sprintbugrelease:16.4.0-must-haveMust-have for 16.4.0: critical bug/perf/usabilityruntime-fixUser-facing behavior fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions