From 15cc46c6bb5449b6db293ed09ad63e889f23f4ea Mon Sep 17 00:00:00 2001 From: Petrik Date: Mon, 26 Aug 2024 22:19:15 +0200 Subject: [PATCH 1/4] Register stats directories with Rails::CodeStatistics.register_directory. Rails `main` uses Thor for the `bin/rails stats` command instead of Rake. This means stats directories need to be added in the Railtie. The global constant STATS_DIRECTORIES defined by Rails, has been deprecated in favor of Rails::CodeStatistics.register_directory. https://github.com/rails/rails/blob/8c7754dfdf39ed94cc93bbc40ee721c311b6d32c/railties/CHANGELOG.md?plain=1#L1-L11 --- lib/view_component/engine.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/view_component/engine.rb b/lib/view_component/engine.rb index 8932ad800..2e822f767 100644 --- a/lib/view_component/engine.rb +++ b/lib/view_component/engine.rb @@ -8,8 +8,16 @@ module ViewComponent class Engine < Rails::Engine # :nodoc: config.view_component = ViewComponent::Config.current - rake_tasks do - load "view_component/rails/tasks/view_component.rake" + if Rails.version.to_f < 8.0 + rake_tasks do + load "view_component/rails/tasks/view_component.rake" + end + else + initializer "view_component.stats_directories" do |app| + require "rails/code_statistics" + dir = ViewComponent::Base.view_component_path + Rails::CodeStatistics.register_directory("ViewComponents", dir) + end end initializer "view_component.set_configs" do |app| From 973b37a2dee4ca28e8af1b9786df20eebc5750b2 Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Tue, 27 Aug 2024 10:36:20 -0600 Subject: [PATCH 2/4] add changelog --- docs/CHANGELOG.md | 4 ++++ docs/index.md | 1 + 2 files changed, 5 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3f3411017..711d0721f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -18,6 +18,10 @@ nav_order: 5 *Tomasz Kowalewski* +* Register stats directories with Rails::CodeStatistics.register_directory to support `rails stats` in Rails 8. + + *Petrik de Heus* + ## 3.14.0 * Defer to built-in caching for language environment setup, rather than manually using `actions/cache` in CI. diff --git a/docs/index.md b/docs/index.md index 7ee5b460b..309d7e564 100644 --- a/docs/index.md +++ b/docs/index.md @@ -183,6 +183,7 @@ ViewComponent is built by over a hundred members of the community, including: nshki nshki ozydingo +p8 patrickarnett rainerborene rdavid1099 From 11485b763a6c3086fa60166815daec6ea4903f12 Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Tue, 27 Aug 2024 10:37:18 -0600 Subject: [PATCH 3/4] Update docs/CHANGELOG.md --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 711d0721f..469c26066 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -18,7 +18,7 @@ nav_order: 5 *Tomasz Kowalewski* -* Register stats directories with Rails::CodeStatistics.register_directory to support `rails stats` in Rails 8. +* Register stats directories with `Rails::CodeStatistics.register_directory` to support `rails stats` in Rails 8. *Petrik de Heus* From e12d2a6009deb5dd706d80066270a97353ea13a7 Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Tue, 27 Aug 2024 12:12:12 -0600 Subject: [PATCH 4/4] only test rake task for Rails < 8.0 --- test/sandbox/test/rake_tasks_test.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/sandbox/test/rake_tasks_test.rb b/test/sandbox/test/rake_tasks_test.rb index f486eff18..35d493226 100644 --- a/test/sandbox/test/rake_tasks_test.rb +++ b/test/sandbox/test/rake_tasks_test.rb @@ -2,17 +2,19 @@ require "test_helper" -module ViewComponent - class RakeTasksTest < TestCase - def setup - Kernel.silence_warnings do - Sandbox::Application.load_tasks +if Rails.version.to_f < 8.0 + module ViewComponent + class RakeTasksTest < TestCase + def setup + Kernel.silence_warnings do + Sandbox::Application.load_tasks + end end - end - def test_statsetup_task - Rake::Task["view_component:statsetup"].invoke - assert_includes ::STATS_DIRECTORIES, ["ViewComponents", "app/components"] + def test_statsetup_task + Rake::Task["view_component:statsetup"].invoke + assert_includes ::STATS_DIRECTORIES, ["ViewComponents", "app/components"] + end end end end