You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't break "rails stats" if app/components is missing (#1927)
* Don't break "rails stats" if app/components is missing
After #1050, running `rails stats` on a Rails app with `view_component` in its Gemfile will also include the statistics (lines of code, …) for the `ViewComponent` code which, by default, is included in `app/components`.
A Rails app, however, could have the `view_component` library in the Gemfile and not have the matching folder (`app/components` by default). In this scenario, `rails stats` fails:
```
rails stats --trace
** Invoke stats (first_time)
** Invoke view_component:statsetup (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute view_component:statsetup
** Execute stats
rails aborted!
Errno::ENOENT: No such file or directory @ dir_initialize - app/components (Errno::ENOENT)
<internal:dir>:98:in `open'
/gems/3.2.0/gems/railties-7.0.7.2/lib/rails/code_statistics.rb:46:in `foreach'
/gems/3.2.0/gems/railties-7.0.7.2/lib/rails/code_statistics.rb:46:in `calculate_directory_statistics'
/gems/3.2.0/gems/railties-7.0.7.2/lib/rails/code_statistics.rb:40:in `block in calculate_statistics'
/gems/3.2.0/gems/railties-7.0.7.2/lib/rails/code_statistics.rb:40:in `map'
/gems/3.2.0/gems/railties-7.0.7.2/lib/rails/code_statistics.rb:40:in `calculate_statistics'
/gems/3.2.0/gems/railties-7.0.7.2/lib/rails/code_statistics.rb:21:in `initialize'
/gems/3.2.0/gems/railties-7.0.7.2/lib/rails/tasks/statistics.rake:36:in `new'
/gems/3.2.0/gems/railties-7.0.7.2/lib/rails/tasks/statistics.rake:36:in `block in <main>'
...
```
---
This PR solves the issue by following the example of the original statistics.rake file (https://github.com/rails/rails/blob/5621c93bfc8e8aefab90223dcf0edf4b10e5dcf6/railties/lib/rails/tasks/statistics.rake#L36) which checks whether a folder exists before trying to output stats for it.
* Update docs/CHANGELOG.md
---------
Co-authored-by: Joel Hawksley <[email protected]>
0 commit comments