Commit 78dbac2
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]>1 parent 31fafe3 commit 78dbac2
File tree
2 files changed
+6
-1
lines changed- docs
- lib/view_component/rails/tasks
2 files changed
+6
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
0 commit comments