-
Notifications
You must be signed in to change notification settings - Fork 18
Support nested packs with UsePackwerk #6
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
Conversation
|
|
||
| package = ParsePackwerk::Package.from(package_location.join(ParsePackwerk::PACKAGE_YML_NAME)) | ||
|
|
||
| package = T.must(ParsePackwerk.package_from_path(path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above was just a way of finding what package the file belonged to. Now that ParsePackwerk implements this, this could all be removed.
|
|
||
| sig { params(original_package: ParsePackwerk::Package).returns(ParsePackwerk::Package) } | ||
| def self.rewrite_package_with_original_packwerk_values(original_package) | ||
| ParsePackwerk.bust_cache! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because I added a cache to ParsePackwerk.all.
I slightly regret doing that, since it ended up being a bit confusing, and I think I want to change to something closer to what packwerk does later:
rubyatscale/parse_packwerk#9
| new_package_root.join(T.must(parts[2..]).join('/')).cleanpath | ||
| else | ||
| raise StandardError.new("Don't know how to find destination path for #{origin_pathname.inspect}") | ||
| Pathname.new(origin_pathname.to_s.gsub(origin_pack.name, new_package_root.to_s)).cleanpath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old implementation was a bit convoluted because I was basically inferring whether it was the root pack or a parent pack based on the first parts of the directory. It's much more explicit to just swap out the old pack name with the new one! This actually resulted in even less code for the child pack case.
| filepath_without_pack_name = origin_pathname.to_s.gsub("#{origin_pack.name}/", '') | ||
| end | ||
|
|
||
| # We join the pack name with the rest of the path... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above -- I was casing based on whether it was a root or parent pack. This implementation just looks at the path following the pack name, which I think is a lot simpler to understand.
| - packs/organisms/app/services/bug_like/fly.rb | ||
| CONTENTS | ||
|
|
||
| write_file('packs/organisms/package.yml', <<~CONTENTS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new implementation requires that packs exist for us to be able to find what pack a file belongs to, so the tests need to be changed accordingly.
I found the tests a bit convoluted coming back to them, so I want to do some work at some point to clean up UsePackwerk tests (making each test have a smaller, inline setup).
| @@ -1,6 +1,10 @@ | |||
| # typed: false | |||
| RSpec.describe UsePackwerk do | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of new tests for the new behavior. Definitely view with "hide whitespace change" set to true since I did a lot of context nesting of the old tests.
Overall, this turned out to be easier than I thought, since I realized for a lot of the logic to determine new paths I just needed to swap the old path name in the path for the new path name -- nothing too fancy needed.
I did have a hard time with the tests, most of all, because they are a bit convoluted and I'd like to clean them up.