rubyatscale / packs-rails

packs-rails establishes and implements a set of conventions for splitting up large monoliths.
MIT License
268 stars 26 forks source link

Moving routes inside a Pack #60

Closed sarahsehr closed 1 year ago

sarahsehr commented 1 year ago

The documentation states that routes can be split.

I've set up a dummy app to explore how packs-rails behaves, and found that I was not able to get this working.

test app

# config/routes.rb
Rails.application.routes.draw do
  get 'work_orders/index'
  get 'articles/index'
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

  # Defines the root path route ("/")
  # root "articles#index"
  draw(:accounting)
end
# packs/accounting/config/routes/accounting
Rails.application.routes.draw do
  get 'bills/index'
end

This config works as expected when running the server locally. However, it fails when running bin/packwerk check:

Traceback (most recent call last):
    54: from bin/packwerk:29:in `<main>'
    53: from bin/packwerk:29:in `load'
    52: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/exe/packwerk:16:in `<top (required)>'
    51: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `block in _on_method_added'
    50: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `bind_call'
    49: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/lib/packwerk/cli.rb:43:in `run'
    48: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `block in _on_method_added'
    47: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `bind_call'
    46: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/lib/packwerk/cli.rb:54:in `execute_command'
    45: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `block in _on_method_added'
    44: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `bind_call'
    43: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/lib/packwerk/parse_run.rb:62:in `check'
    42: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `block in _on_method_added'
    41: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `bind_call'
    40: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/lib/packwerk/run_context.rb:22:in `from_configuration'
    39: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `block in _on_method_added'
    38: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `bind_call'
    37: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/lib/packwerk/configuration.rb:95:in `load_paths'
    36: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `block in _on_method_added'
    35: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `bind_call'
    34: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/lib/packwerk/rails_load_paths.rb:16:in `for'
    33: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `block in _on_method_added'
    32: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/sorbet-runtime-0.5.10712/lib/types/private/methods/_methods.rb:277:in `bind_call'
    31: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/lib/packwerk/rails_load_paths.rb:58:in `require_application'
    30: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/packwerk-3.0.1/lib/packwerk/rails_load_paths.rb:58:in `require'
    29: from /Users/sarah.sehr/src/packwerk_test_app/config/environment.rb:5:in `<top (required)>'
    28: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application.rb:372:in `initialize!'
    27: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:60:in `run_initializers'
    26: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
    25: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
    24: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
    23: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:347:in `call'
    22: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:347:in `each'
    21: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
    20: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
    19: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    18: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
    17: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'
    16: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `run'
    15: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `instance_exec'
    14: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application/finisher.rb:158:in `block in <module:Finisher>'
    13: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:13:in `execute'
    12: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/activesupport-7.0.4.3/lib/active_support/file_update_checker.rb:83:in `execute'
    11: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:38:in `block in updater'
    10: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:24:in `reload!'
     9: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:50:in `load_paths'
     8: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:50:in `each'
     7: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:50:in `block in load_paths'
     6: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:50:in `load'
     5: from /Users/sarah.sehr/src/packwerk_test_app/config/routes.rb:1:in `<main>'
     4: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/actionpack-7.0.4.3/lib/action_dispatch/routing/route_set.rb:410:in `draw'
     3: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/actionpack-7.0.4.3/lib/action_dispatch/routing/route_set.rb:428:in `eval_block'
     2: from /Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/actionpack-7.0.4.3/lib/action_dispatch/routing/route_set.rb:428:in `instance_exec'
     1: from /Users/sarah.sehr/src/packwerk_test_app/config/routes.rb:12:in `block in <main>'
/Users/sarah.sehr/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/actionpack-7.0.4.3/lib/action_dispatch/routing/mapper.rb:1596:in `draw': Your router tried to #draw the external file accounting.rb, (ArgumentError)
but the file was not found in:

 * /Users/sarah.sehr/src/packwerk_test_app/config/routes

Debugging has indicated that @draw_paths does NOT contain the accounting pack routes.rb file when running bin/packwerk check. However, debugging shows that @draw_paths DOES contain the accounting pack routes.rb file when running the rails server.

It's very possible that I've messed something up, but my app is pretty simple, so I'm wondering if there is some config that isn't documented?

sarahsehr commented 1 year ago

Nevermind. This issue is that I only required the gem in the development environment. The documentation already specifies that the gems should be included in all environments.