Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Application < Rails::Application
# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w[assets tasks generators])
config.autoload_lib(ignore: %w[assets tasks])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify that runtime generator invocation is the intended design.

Removing generators from the autoload ignore list contradicts Rails conventions and the comment above (lines 14-16) which explicitly lists generators as a common directory that should NOT be reloaded or eager loaded. Generators are typically development-time tools invoked via rails generate, not runtime components.

If the webpacker generator is being invoked at runtime in staging/production, this may indicate an architectural concern. Code generation should generally occur during development or deployment, not at request time.

Please confirm:

  1. Is this generator actually being invoked at runtime in staging/production?
  2. If so, what triggers the generator execution?
  3. Have you considered alternative approaches like pre-generating assets during deployment?

🏁 Script executed:

#!/bin/bash
# Description: Search for runtime invocations of the webpacker_assets generator

# Search for direct generator invocations in non-generator code
rg -n --type=ruby -C3 'WebpackerAssetsGenerator|generate.*webpacker_assets' -g '!**/generators/**' -g '!**/test/**' -g '!**/spec/**'

# Search for Rails.application.load_generators calls
rg -n --type=ruby -C3 'load_generators'

Length of output: 0



---

🏁 Script executed:

```shell
#!/bin/bash
# Find the webpacker_assets generator and understand codebase structure

# Check if lib/generators/webpacker_assets exists
fd -t f "webpacker" --path "*/generators/*"

# Check overall lib/generators structure
fd -t d "generators" lib/

# Search for webpacker configuration files
fd -t f "webpacker" config/

# Search for any rake tasks related to webpacker or generators
rg -n --type=ruby "task.*webpacker|desc.*webpacker" config/ lib/

# Check if there are any initializers that might invoke generators
rg -n --type=ruby "webpacker" config/initializers/ 2>/dev/null || echo "No initializers with webpacker found"

Length of output: 307


🏁 Script executed:

#!/bin/bash
# Verify if there's documentation in PR or config about the staging issue
# Check for any boot-time or initialization code that could invoke generators

# Look at application.rb more broadly for context
rg -n "config.autoload_lib|config.eager_load" config/application.rb -A2 -B2

# Check if generators are referenced in Rakefile
fd -t f "Rakefile" . -exec grep -l "generator" {} \;

Length of output: 501



---

🏁 Script executed:

```shell
#!/bin/bash
# Check what's actually in lib/generators
find lib/generators -type f -name "*.rb" 2>/dev/null | head -20

# Look for any dynamic code loading or generator invocation patterns
rg -n --type=ruby "invoke|execute|run.*generator" --max-count=10

# Check if webpacker.yml references anything about generators or assets
cat config/webpacker.yml 2>/dev/null | head -30

# Search for any Rake task definitions that might invoke code generation
rg -n --type=ruby "namespace.*webpacker|task.*asset" lib/ Rakefile 2>/dev/null | head -20

Length of output: 855


🏁 Script executed:

#!/bin/bash
# Check git history for context about this change
git log --oneline -n 20 -- config/application.rb 2>/dev/null || echo "Git history not available"

# Look at the actual diff for this file to understand what changed
git diff HEAD~1 config/application.rb 2>/dev/null || echo "Git diff not available"

# Check if there are comments in PRs or issues
git log --format="%B" -n 5 -- config/application.rb 2>/dev/null | head -30 || echo "Commit messages not available"

Length of output: 1960



---

🏁 Script executed:

```shell
#!/bin/bash
# Final verification: search for any references to WebpackerAssetsGenerator or that specific file
rg -n "webpacker_assets_generator|WebpackerAssetsGenerator" --type=ruby

# Check if anything requires or loads this generator explicitly
rg -n "require.*generators|load.*generator" --type=ruby -g '!config/application.rb'

# Look for Rails 7.2 specific changes that might explain this
rg -n "eager_load_paths|autoload_paths" config/

Length of output: 236


Revert generators to the ignore list or document why it's needed.

The git history confirms this change was made during the Rails 7.2 migration but provides no explanation. The codebase's own comments (lines 14-16) explicitly identify generators as a directory that should NOT be reloaded or eager loaded. Additionally, searching the entire codebase reveals zero references to WebpackerAssetsGenerator outside its own definition file—there is no code that requires or invokes it at runtime.

This change contradicts both Rails conventions and the stated principles in the same file. Either revert generators back to the ignore list, or add a clear comment explaining why autoloading is necessary in this case.

🤖 Prompt for AI Agents
In config/application.rb around line 17, the change removed "generators" from
the autoload_lib ignore list without explanation; revert the line to include
generators in the ignore list (e.g. config.autoload_lib(ignore: %w[assets tasks
generators]) ) or, if autoloading generators is intentionally required, add a
clear comment above this line documenting exactly why generators must be
autoloaded, referencing the specific constant (WebpackerAssetsGenerator) and
where/when it is loaded at runtime, and run the test suite to ensure no
regressions.


# Configuration for the application, engines, and railties goes here.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
module Rails
class WebpackerAssetsGenerator < Rails::Generators::NamedBase
def create_assets_file
create_file "app/javascript/packs/#{file_name}.js", <<-FILE
your content
FILE
create_file "app/assets/stylesheets/#{file_name}.scss", <<-FILE
your content
FILE
require 'rails/generators'

module Generators
module Rails
module WebpackerAssets
class WebpackerAssetsGenerator < ::Rails::Generators::NamedBase
def create_assets_file
create_file "app/javascript/packs/#{file_name}.js", <<-FILE
// your content
FILE
create_file "app/assets/stylesheets/#{file_name}.scss", <<-FILE
// your content
FILE
end
end
end
end
end