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

Proof of concept for removing ConstantResolver and using Zeitwerk for ConstantDiscovery #410

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Catsuko
Copy link

@Catsuko Catsuko commented Jul 18, 2024

What are you trying to accomplish?

I am interested in using Zeitwerk features such as collapsing directories however currently Packwerk doesn't support this.

Based on this comment in a related issue, this PR adds an implementation of ConstantDiscovery using Zeitwerk rather than ConstantResolver as a proof of concept.

What approach did you choose and why?

First I refactored to encapsulate ConstantResolver so it is easier for me to play with an alternate ConstantDiscovery implementation.

Then I implemented a Zeitwerk based ConstantDiscovery and copied tests from ConstantDiscovery and the ConstantResolver gem to make sure it worked ok. Private methods for matching constants from the map of paths was taken from ConstantResolver as well as many tests checking edge cases.

Finally I replaced ConstantDiscovery with my version and removed the code related to the old implementation. A lot of test helpers needed to be updated here since now ConstantDiscovery depends on Zeitwerk Loaders 😭

What should reviewers focus on?

  • The second commit contains the zeitwerk implementation as a separate class as well as extended test coverage. I think this should be the focus since the third commit just rigs it all up so I could test on my repo.
  • Is it okay to depend on Zeitwerk in this way?

Type of Change

  • Bugfix
  • New feature
  • Non-breaking change (a change that doesn't alter functionality - i.e., code refactor, configs, etc.)

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • It is safe to rollback this change.

spec.add_dependency("parallel")
spec.add_dependency("sorbet-runtime", ">= 0.5.9914")
spec.add_dependency("zeitwerk", ">= 2.6.1")
spec.add_dependency("zeitwerk", ">= 2.6.14")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For usage of Zeitwerk::Loader#all_expected_cpaths: https://github.com/fxn/zeitwerk/blob/main/CHANGELOG.md#2614-14-may-2024

@Catsuko
Copy link
Author

Catsuko commented Jul 18, 2024

I have signed the CLA!

Copy link
Author

@Catsuko Catsuko Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For an easier to understand idea of the zeitwerk implementation, see this commit.

@Catsuko Catsuko marked this pull request as ready for review July 20, 2024 14:29
@Catsuko Catsuko requested a review from a team as a code owner July 20, 2024 14:29
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

Successfully merging this pull request may close these issues.

1 participant