Skip to content

Clean up stale config/webpack/ files when installing with --rspack #2549

@ihabadham

Description

@ihabadham

Problem

When switching from webpack to rspack (re-running rails g react_on_rails:install --rspack on an existing webpack project), the old config/webpack/ directory and all its config files are left behind. The generator creates the new config/rspack/ configs but never cleans up the old ones.

Note: On a fresh install with --rspack, this does NOT happen — SHAKAPACKER_ASSETS_BUNDLER=rspack correctly tells Shakapacker to create config/rspack/ from the start. The stale files only appear when:

  1. A project was originally set up with webpack (has config/webpack/)
  2. The user re-runs the generator with --rspack to switch bundlers

Reproduction

# 1. Create app and install with webpack
rails new /tmp/ror_switch_test --minimal --skip-git --skip-bundle --skip-test --skip-javascript
cd /tmp/ror_switch_test
# Add react_on_rails and shakapacker to Gemfile
bundle install
git init && git add -A && git commit -m "init"
bundle exec rails g react_on_rails:install --ignore-warnings
git add -A && git commit -m "After webpack install"

# 2. Switch to rspack
bundle exec rails g react_on_rails:install --rspack --ignore-warnings

# 3. Observe stale files
ls config/webpack/   # Still has all 8 files!
ls config/rspack/    # Has the new configs

Result

Both directories exist with duplicate config files:

config/webpack/   (8 files — stale, unused)
config/rspack/    (8 files — active)

shakapacker.yml correctly points to rspack, so config/webpack/ is dead weight.

Affected Code

  • lib/generators/react_on_rails/base_generator.rbcopy_webpack_config creates new files via destination_config_path but doesn't remove old ones
  • No cleanup logic exists anywhere in the generator flow

Expected Behavior

When --rspack is used on a project that has config/webpack/:

  1. Remove config/webpack/ if it only contains stock configs
  2. If custom configs are detected, warn the user instead of silently leaving them

Context

Found during review of PR #2417. Related to #2410.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Metr-PendingPending Metr trackingP3Parked prioritycodexPRs created from codex-named branchesenhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions