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

Improve UX for UsePackwerk.move_to_parent! #13

Merged
merged 5 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
use_packwerk (0.53.0)
use_packwerk (0.54.0)
code_ownership
colorize
package_protections
Expand Down Expand Up @@ -33,7 +33,7 @@ GEM
concurrent-ruby (~> 1.0)
json (2.6.2)
method_source (1.0.0)
minitest (5.16.2)
minitest (5.16.3)
package_protections (1.4.0)
activesupport
parse_packwerk
Expand Down
29 changes: 27 additions & 2 deletions lib/use_packwerk/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,33 @@ def self.move_to_parent!(
deprecated_references_file = ParsePackwerk::DeprecatedReferences.for(package).pathname
deprecated_references_file.delete if deprecated_references_file.exist?

# Add a dependency from parent to child
self.add_dependency!(pack_name: parent_name, dependency_name: new_package_name)
ParsePackwerk.bust_cache!

ParsePackwerk.all.each do |other_package|
new_dependencies = other_package.dependencies.map{|d| d == pack_name ? new_package_name : d}
if other_package.name == parent_name && !new_dependencies.include?(new_package_name)
new_dependencies += [new_package_name]
end

new_other_package = ParsePackwerk::Package.new(
name: other_package.name,
enforce_privacy: other_package.enforce_dependencies,
enforce_dependencies: other_package.enforce_dependencies,
dependencies: new_dependencies.uniq.sort,
metadata: other_package.metadata,
)

ParsePackwerk.write_package_yml!(new_other_package)
end

sorbet_config = Pathname.new('sorbet/config')
if sorbet_config.exist?
UsePackwerk.replace_in_file(
file: sorbet_config.to_s,
find: package.directory.join('spec'),
replace_with: new_package.directory.join('spec'),
)
end
end

sig do
Expand Down
41 changes: 41 additions & 0 deletions spec/use_packwerk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,47 @@ def expect_files_to_not_exist(files)
OUTPUT
end

it 'rewrites other packs package.yml files to point to the new nested package' do
write_package_yml('packs/fruits', dependencies: ['packs/apples'])
write_package_yml('packs/other_pack', dependencies: ['packs/apples', 'packs/something_else'])
write_package_yml('packs/apples')

UsePackwerk.move_to_parent!(
pack_name: 'packs/apples',
parent_name: 'packs/fruits',
)

ParsePackwerk.bust_cache!

expect(ParsePackwerk.find('packs/fruits').dependencies).to eq(['packs/fruits/apples'])
expect(ParsePackwerk.find('packs/other_pack').dependencies).to eq(['packs/fruits/apples', 'packs/something_else'])
end

it 'updates sorbet config to point at the new spec location' do
write_package_yml('packs/fruits')
write_package_yml('packs/apples')
write_file('sorbet/config', <<~CONTENTS)
--dir
.
--ignore=/packs/other_pack/spec
--ignore=/packs/apples/spec
CONTENTS

UsePackwerk.move_to_parent!(
pack_name: 'packs/apples',
parent_name: 'packs/fruits',
)

ParsePackwerk.bust_cache!

expect(Pathname.new('sorbet/config').read).to eq <<~CONTENTS
--dir
.
--ignore=/packs/other_pack/spec
--ignore=/packs/fruits/apples/spec
CONTENTS
end

context 'parent pack does not already exist' do
it 'creates it' do
# Parent pack does not exist!
Expand Down
2 changes: 1 addition & 1 deletion use_packwerk.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'use_packwerk'
spec.version = '0.53.0'
spec.version = '0.54.0'
spec.authors = ['Gusto Engineers']
spec.email = ['dev@gusto.com']

Expand Down