-
Notifications
You must be signed in to change notification settings - Fork 2
Fix a Bug with webpacker generator #1106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 15 additions & 9 deletions
24
lib/generators/rails/webpacker_assets/webpacker_assets_generator.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify that runtime generator invocation is the intended design.
Removing
generatorsfrom 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 viarails 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:
🏁 Script executed:
Length of output: 0
Length of output: 307
🏁 Script executed:
Length of output: 501
Length of output: 855
🏁 Script executed:
Length of output: 1960
Length of output: 236
Revert
generatorsto 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
generatorsas a directory that should NOT be reloaded or eager loaded. Additionally, searching the entire codebase reveals zero references toWebpackerAssetsGeneratoroutside 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
generatorsback to the ignore list, or add a clear comment explaining why autoloading is necessary in this case.🤖 Prompt for AI Agents