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

Is there a reason components are in app as opposed to lib? #171

Open
joelzwarrington opened this issue Aug 20, 2024 · 2 comments
Open

Is there a reason components are in app as opposed to lib? #171

joelzwarrington opened this issue Aug 20, 2024 · 2 comments

Comments

@joelzwarrington
Copy link
Contributor

I'm working on a UI library which will use ViewComponent::Form and Zeitwerk doesn't like the non-standard file structure.

There is an engine which configures autoload paths, but this doesn't work well when used in the context of another gem.

I've setup a 'hack' to auto load the app paths:

require "zeitwerk"
loader = Zeitwerk::Loader.for_gem

vcf_gem_dir = Gem::Specification.find_by_name("view_component-form").gem_dir
loader.push_dir File.join(vcf_gem_dir, "app", "components")
loader.push_dir File.join(vcf_gem_dir, "app", "components", "concerns")

loader.setup

I'm wondering if there's a reason it's setup this way which might not be immediately obvious?

@joelzwarrington
Copy link
Contributor Author

That example ^ doesn't exactly work though, it works if you're not using Rails, but as soon as you add the gem to Rails it conflicts with the Zeitwerk loader added by the gem:

Zeitwerk::Loader

wants to manage directory /xyz, which is already managed by

Zeitwerk::GemLoader

@Spone
Copy link
Collaborator

Spone commented Aug 30, 2024

Hi @joelzwarrington, no particular reason if I remember correctly. I think we can totally move the files to lib. Would that imply that when we want to override a ViewComponent::Form component locally, the file would need to be in lib as well, rather than app? In this case this would be a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants