Skip to content

Refactor spec/dummy bin scripts auto-configuration #716

@justin808

Description

@justin808

Background

In PR #706 (Add timing logs for webpack and rspack builds), auto-configuration logic was added to spec/dummy/bin/shakapacker and spec/dummy/bin/shakapacker-dev-server to automatically copy shakapacker-webpack.yml to shakapacker.yml if it doesn't exist.

While this improves the developer experience for the test app, there are some considerations:

Issues

  1. Scope creep: This feature is outside the stated scope of the timing logs PR
  2. Emoji usage: Uses emojis (📦, 💡) but CLAUDE.md says to avoid emojis unless requested
  3. Code duplication: The auto-setup logic is duplicated between both bin scripts
  4. Not git-ignored: The generated config/shakapacker.yml isn't git-ignored, which could lead to unwanted commits

Recommendations

Option 1: Extract to Shared Helper

Create a shared helper method in spec/dummy/config/application.rb or a new lib/ file:

# spec/dummy/lib/shakapacker_auto_setup.rb
module ShakapackerAutoSetup
  def self.ensure_config!(app_root)
    config_dir = File.join(app_root, "config")
    shakapacker_config = File.join(config_dir, "shakapacker.yml")
    webpack_config = File.join(config_dir, "shakapacker-webpack.yml")

    return if File.exist?(shakapacker_config)
    return unless File.exist?(webpack_config)

    require "fileutils"
    FileUtils.cp(webpack_config, shakapacker_config)
    
    $stderr.puts "Auto-configured with webpack (copied shakapacker-webpack.yml -> shakapacker.yml)"
    $stderr.puts "To switch bundlers, use: bin/test-bundler [webpack|rspack]"
  end
end

Then both bin scripts can call: ShakapackerAutoSetup.ensure_config!(APP_ROOT)

Option 2: Use .gitignore

Add to spec/dummy/.gitignore:

config/shakapacker.yml

This prevents accidental commits of the auto-generated config.

Option 3: Remove Auto-Configuration

If we want to keep the test app strictly manual, remove the auto-configuration and rely on the README instructions to run bin/test-bundler first.

Priority

Low - This is a nice-to-have improvement for code quality and maintainability, not a critical issue.

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions