Sha256: 4edac547c1af565da1622fd24d82bb8b0ec0da9f4a808700e864d29f73108ca4

Contents?: true

Size: 1.61 KB

Versions: 37

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

eager_load = ->() do
  puts "Hold on, I am eager loading the application."
  Zeitwerk::Loader.eager_load_all
end

report_not_checked = ->(not_checked) do
  puts
  puts <<~EOS
    WARNING: The following directories will only be checked if you configure
    them to be eager loaded:
  EOS
  puts

  not_checked.each { |dir| puts "  #{dir}" }
  puts

  puts <<~EOS
    You may verify them manually, or add them to config.eager_load_paths
    in config/application.rb and run zeitwerk:check again.
  EOS
  puts
end

report = ->(not_checked) do
  if not_checked.any?
    report_not_checked[not_checked]
    puts "Otherwise, all is good!"
  else
    puts "All is good!"
  end
end

namespace :zeitwerk do
  desc "Checks project structure for Zeitwerk compatibility"
  task check: :environment do
    begin
      eager_load[]
    rescue NameError => e
      if e.message =~ /expected file .*? to define constant [\w:]+/
        abort $&.sub(/expected file #{Regexp.escape(Rails.root.to_s)}./, "expected file ")
      else
        raise
      end
    end

    require "active_support/core_ext/object/try"
    eager_load_paths = Rails.configuration.eager_load_namespaces.filter_map do |eln|
      # Quick regression fix for 6.0.3 to support namespaces that do not have
      # eager load paths, like the recently added i18n. I'll rewrite this task.
      eln.try(:config).try(:eager_load_paths)
    end.flatten

    not_checked = ActiveSupport::Dependencies.autoload_paths - eager_load_paths
    not_checked.select! { |dir| Dir.exist?(dir) }
    not_checked.reject! { |dir| Dir.empty?(dir) }

    report[not_checked]
  end
end

Version data entries

37 entries across 35 versions & 4 rubygems

Version Path
railties-7.0.8.6 lib/rails/tasks/zeitwerk.rake
railties-7.0.8.5 lib/rails/tasks/zeitwerk.rake
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/tasks/zeitwerk.rake
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/railties-7.0.5.1/lib/rails/tasks/zeitwerk.rake
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/railties-7.0.5.1/lib/rails/tasks/zeitwerk.rake
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/railties-7.0.5.1/lib/rails/tasks/zeitwerk.rake
railties-7.0.8.4 lib/rails/tasks/zeitwerk.rake
railties-7.0.8.1 lib/rails/tasks/zeitwerk.rake
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/tasks/zeitwerk.rake
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/railties-7.0.2.3/lib/rails/tasks/zeitwerk.rake
railties-7.0.8 lib/rails/tasks/zeitwerk.rake
railties-7.0.7.2 lib/rails/tasks/zeitwerk.rake
railties-7.0.7.1 lib/rails/tasks/zeitwerk.rake
railties-7.0.7 lib/rails/tasks/zeitwerk.rake
railties-7.0.6 lib/rails/tasks/zeitwerk.rake
railties-7.0.5.1 lib/rails/tasks/zeitwerk.rake
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/railties-7.0.2.3/lib/rails/tasks/zeitwerk.rake
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/tasks/zeitwerk.rake
railties-7.0.5 lib/rails/tasks/zeitwerk.rake
railties-7.0.4.3 lib/rails/tasks/zeitwerk.rake