Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mounting an engine raises violations #246

Closed
Spence1115 opened this issue Oct 28, 2022 · 2 comments
Closed

Mounting an engine raises violations #246

Spence1115 opened this issue Oct 28, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@Spence1115
Copy link

Description
When I mount an engine in the main app for the purposes of accessing the API, I receive violations from packwerk check

Privacy violation: '::SomeService::Engine' is private to 'modules/some_service' but referenced from '.'.
Is there a public entrypoint in 'modules/some_service/public/' that you can use instead?

Am I missing something in terms of how we should be accessing our engines?

To Reproduce

# ~/config/routes.rb

Rails.application.routes.draw do
  mount SomeService::Engine, at: "/some_service"
end
# ~/package.yml

enforce_dependencies: true
enforce_privacy: false
dependencies:
- "modules/some_service"
@Spence1115 Spence1115 added the bug Something isn't working label Oct 28, 2022
@alexevanczuk
Copy link
Contributor

Hi @Spence1115 !

So packwerk doesn't know about engines or the preferred way to mounting them out of the box. In this case, packwerk is considering this a privacy violation because modules/some_service/package.yml has set enforce_privacy to true, and ::SomeService::Engine is not in the public folder of modules/some_service.

In this case, it seems reasonable that SomeService::Engine is the public API to using your engine and connecting it to Rails. I'm not sure if there's a Rails limitation here (let me know if there is), but you should be able to move ::SomeService::Engine to live in modules/some_service/public so it is considered public API. Your other options are:

  • Turn off enforce_privacy
  • Use the other API to enforce_privacy to specify private constants
  • Have packwerk ignore config/routes by setting an exclusion in packwerk.yml.

Let me know if this doesn't help!

@rafaelfranca
Copy link
Member

Packwerk should never ask people to move Rails defaults to other places. That is the main reason why enforce_privacy is being removed from Packwerk. Don't move your engine to modules/some_service/public. Packwerk should not be forcing you to do that.

So the other three options Alex listed are your best ones.

We need a better mechanism than folder collocation to define what is public API and what is isn't. Unfortunately the solution is Packwerk isn't good enough and it is going to be removed. Maybe the upcomin privacy plugin will build a different solution.

Thank you for the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants