Skip to content

Conversation

@alexevanczuk
Copy link
Contributor

@alexevanczuk alexevanczuk commented Aug 15, 2022

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.


package = ParsePackwerk::Package.from(package_location.join(ParsePackwerk::PACKAGE_YML_NAME))

package = T.must(ParsePackwerk.package_from_path(path))
Copy link
Contributor Author

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!
Copy link
Contributor Author

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
Copy link
Contributor Author

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...
Copy link
Contributor Author

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)
Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@alexevanczuk alexevanczuk requested review from a team, baweaver and shageman August 15, 2022 12:48
@alexevanczuk alexevanczuk merged commit 00dc34b into main Aug 15, 2022
@alexevanczuk alexevanczuk deleted the ae-nested-packs branch August 15, 2022 13:25
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.

2 participants