use_packs 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb4b5cfe33a3c5881971d27c78fefe591378e9728baf6513beffc14058ef23d6
4
- data.tar.gz: 15144da46c38e628af6bfc3c5243d8d0c42a46b2fa739b66339fb120e31c6d36
3
+ metadata.gz: 5450c6c78c1c7257449c5b3e9cd7e9301be0642af31a9324051cfd97cea5045f
4
+ data.tar.gz: 13028e1163d760e183bff5d9840b11e1148ca9718900652fe9a4246ae040ad23
5
5
  SHA512:
6
- metadata.gz: ce3dbd0c9c3b103887e0ff3e84421396cc3e711b4cac3626e34e622d403ab806eb63ec50e3bb4daf64b647d7f991d940e5973e60cd28e1a8b1a4880635be2525
7
- data.tar.gz: 9f38e2e00c87dc857a279a726bd7539d5344a0a51dbd5acfeac4153194dcaef5bcab1e577c9a11417963602f652d7559e33a9dba5a77f6372bec066e8ac058c2
6
+ metadata.gz: cf4115115841e5242ca58aafbf105e6c0cd35acf1e945a20f67b71e8163866705e03ac58ae9a0dfe412342b95b1e7ffe60e9662e61a1ef0f3aa7e182e0b8bf8a
7
+ data.tar.gz: 9ae241757c61197ccda052f06263180ece2e907680125e69405a533d0063875eb43217ee078f22654f43e1a98c558db6ed29c0477964197946482b4bc417b16b
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  UsePacks is a gem that helps in creating and maintaining packs. It exists to help perform some basic operations needed for pack setup and configuration. It provides a basic ruby file packager utility for [`packwerk`](https://github.com/Shopify/packwerk/). It assumes you are using [`stimpack`](https://github.com/rubyatscale/stimpack) to organize your packages.
4
4
 
5
5
  ## Usage
6
+ Make sure to run `bundle binstub use_packs` to generate `bin/packs` within your application.
7
+
6
8
  ### General Help
7
9
  `bin/packs --help` or just `bin/packs` to enter interactive mode.
8
10
 
data/lib/use_packs/cli.rb CHANGED
@@ -68,16 +68,6 @@ module UsePacks
68
68
  )
69
69
  end
70
70
 
71
- desc 'move_to_parent packs/parent_pack packs/child_pack', 'Pass in a parent pack and another pack to be made as a child to the parent pack!'
72
- sig { params(parent_name: String, pack_name: String).void }
73
- def move_to_parent(parent_name, pack_name)
74
- UsePacks.move_to_parent!(
75
- parent_name: parent_name,
76
- pack_name: pack_name,
77
- per_file_processors: [UsePacks::RubocopPostProcessor.new, UsePacks::CodeOwnershipPostProcessor.new]
78
- )
79
- end
80
-
81
71
  desc 'lint_package_todo_yml_files', 'Ensures `package_todo.yml` files are up to date'
82
72
  sig { void }
83
73
  def lint_package_todo_yml_files
@@ -114,6 +104,34 @@ module UsePacks
114
104
  RuboCop::Packs.regenerate_todo(packs: parse_pack_names(pack_names))
115
105
  end
116
106
 
107
+ desc 'get_info [ packs/my_pack packs/my_other_pack ]', 'Get info about size and violations for packs'
108
+ sig { params(pack_names: String).void }
109
+ def get_info(*pack_names)
110
+ Private.get_info(packs: parse_pack_names(pack_names))
111
+ end
112
+
113
+ desc 'visualize [ packs/my_pack packs/my_other_pack ]', 'Visualize packs'
114
+ sig { params(pack_names: String).void }
115
+ def visualize(*pack_names)
116
+ Private.visualize(packs: parse_pack_names(pack_names))
117
+ end
118
+
119
+ desc 'rename', 'Rename a pack'
120
+ sig { void }
121
+ def rename
122
+ puts Private.rename_pack
123
+ end
124
+
125
+ desc 'move_to_parent packs/child_pack packs/parent_pack ', 'Sets packs/child_pack as a child of packs/parent_pack'
126
+ sig { params(child_pack_name: String, parent_pack_name: String).void }
127
+ def move_to_parent(child_pack_name, parent_pack_name)
128
+ UsePacks.move_to_parent!(
129
+ parent_name: parent_pack_name,
130
+ pack_name: child_pack_name,
131
+ per_file_processors: [UsePacks::RubocopPostProcessor.new, UsePacks::CodeOwnershipPostProcessor.new]
132
+ )
133
+ end
134
+
117
135
  private
118
136
 
119
137
  # This is used by thor to know that these private methods are not intended to be CLI commands
@@ -17,7 +17,6 @@ module UsePacks
17
17
  sig { override.params(prompt: TTY::Prompt).void }
18
18
  def perform!(prompt)
19
19
  team_or_pack = prompt.select('Do you want info by team or by pack?', ['By team', 'By pack'])
20
-
21
20
  if team_or_pack == 'By team'
22
21
  teams = TeamSelector.multi_select(prompt)
23
22
  selected_packs = Packs.all.select do |p|
@@ -27,45 +26,9 @@ module UsePacks
27
26
  selected_packs = PackSelector.single_or_all_pack_multi_select(prompt, question_text: 'What pack(s) would you like info on?')
28
27
  end
29
28
 
30
- inbound_violations = {}
31
- outbound_violations = {}
32
- ParsePackwerk.all.each do |p|
33
- p.violations.each do |violation|
34
- outbound_violations[p.name] ||= []
35
- outbound_violations[p.name] << violation
36
- inbound_violations[violation.to_package_name] ||= []
37
- inbound_violations[violation.to_package_name] << violation
38
- end
39
- end
40
-
41
29
  puts "You've selected #{selected_packs.count} packs. Wow! Here's all the info."
42
- all_inbound = T.let([], T::Array[ParsePackwerk::Violation])
43
- all_outbound = T.let([], T::Array[ParsePackwerk::Violation])
44
- selected_packs.each do |pack|
45
- all_inbound += inbound_violations[pack.name] || []
46
- all_outbound += outbound_violations[pack.name] || []
47
- end
48
30
 
49
- puts "There are #{all_inbound.select(&:privacy?).sum { |v| v.files.count }} total inbound privacy violations"
50
- puts "There are #{all_inbound.select(&:dependency?).sum { |v| v.files.count }} total inbound dependency violations"
51
- puts "There are #{all_outbound.select(&:privacy?).sum { |v| v.files.count }} total outbound privacy violations"
52
- puts "There are #{all_outbound.select(&:dependency?).sum { |v| v.files.count }} total outbound dependency violations"
53
-
54
- selected_packs.sort_by { |p| -p.relative_path.glob('**/*.rb').count }.each do |pack|
55
- puts "\n=========== Info about: #{pack.name}"
56
-
57
- owner = CodeOwnership.for_package(pack)
58
- puts "Owned by: #{owner.nil? ? 'No one' : owner.name}"
59
- puts "Size: #{pack.relative_path.glob('**/*.rb').count} ruby files"
60
- puts "Public API: #{pack.relative_path.join('app/public')}"
61
-
62
- inbound_for_pack = inbound_violations[pack.name] || []
63
- outbound_for_pack = outbound_violations[pack.name] || []
64
- puts "There are #{inbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} inbound privacy violations"
65
- puts "There are #{inbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} inbound dependency violations"
66
- puts "There are #{outbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} outbound privacy violations"
67
- puts "There are #{outbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} outbound dependency violations"
68
- end
31
+ Private.get_info(packs: selected_packs)
69
32
  end
70
33
  end
71
34
  end
@@ -0,0 +1,25 @@
1
+ # typed: strict
2
+
3
+ module UsePacks
4
+ module Private
5
+ module InteractiveCli
6
+ module UseCases
7
+ class LintPackageYmlTodoFiles
8
+ extend T::Sig
9
+ extend T::Helpers
10
+ include Interface
11
+
12
+ sig { override.params(prompt: TTY::Prompt).void }
13
+ def perform!(prompt)
14
+ Private.lint_package_todo_yml_files!
15
+ end
16
+
17
+ sig { override.returns(String) }
18
+ def user_facing_name
19
+ 'Lint .package_todo.yml files'
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -4,7 +4,7 @@ module UsePacks
4
4
  module Private
5
5
  module InteractiveCli
6
6
  module UseCases
7
- class LintPackageYml
7
+ class LintPackageYmlFiles
8
8
  extend T::Sig
9
9
  extend T::Helpers
10
10
  include Interface
@@ -4,14 +4,14 @@ module UsePacks
4
4
  module Private
5
5
  module InteractiveCli
6
6
  module UseCases
7
- class Nest
7
+ class MoveToParent
8
8
  extend T::Sig
9
9
  extend T::Helpers
10
10
  include Interface
11
11
 
12
12
  sig { override.params(prompt: TTY::Prompt).void }
13
13
  def perform!(prompt)
14
- child_pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the pack that will be nested')
14
+ child_pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the child pack that will be nested')
15
15
  parent_pack = PackSelector.single_pack_select(prompt, question_text: 'Please select the pack that will be the parent')
16
16
  UsePacks.move_to_parent!(
17
17
  parent_name: parent_pack.name,
@@ -22,7 +22,7 @@ module UsePacks
22
22
 
23
23
  sig { override.returns(String) }
24
24
  def user_facing_name
25
- 'Nest one pack under another'
25
+ 'Move a child pack to be nested under a parent pack'
26
26
  end
27
27
  end
28
28
  end
@@ -16,16 +16,7 @@ module UsePacks
16
16
 
17
17
  sig { override.params(prompt: TTY::Prompt).void }
18
18
  def perform!(prompt)
19
- prompt.warn(<<~WARNING)
20
- We do not yet have an automated API for this.
21
-
22
- Follow these steps:
23
- 1. Rename the `packs/your_pack` directory to the name of the new pack, `packs/new_pack_name
24
- 2. Replace references to `- packs/your_pack` in `package.yml` files with `- packs/new_pack_name`
25
- 3. Rerun `bin/packwerk update-todo` to update violations
26
- 4. Run `bin/codeownership validate` to update ownership information
27
- 5. Please let us know if anything is missing.
28
- WARNING
19
+ prompt.warn(Private.rename_pack)
29
20
  end
30
21
  end
31
22
  end
@@ -4,19 +4,19 @@ module UsePacks
4
4
  module Private
5
5
  module InteractiveCli
6
6
  module UseCases
7
- class UpdateTodo
7
+ class Update
8
8
  extend T::Sig
9
9
  extend T::Helpers
10
10
  include Interface
11
11
 
12
12
  sig { override.returns(String) }
13
13
  def user_facing_name
14
- 'Run bin/packwerk update-todo'
14
+ 'Run bin/packwerk update'
15
15
  end
16
16
 
17
17
  sig { override.params(prompt: TTY::Prompt).void }
18
18
  def perform!(prompt)
19
- system('bin/packwerk update-todo')
19
+ system('bin/packwerk update')
20
20
  end
21
21
  end
22
22
  end
@@ -29,10 +29,7 @@ module UsePacks
29
29
  selected_packs = PackSelector.single_or_all_pack_multi_select(prompt)
30
30
  end
31
31
 
32
- packwerk_packages = selected_packs.map do |pack|
33
- T.must(ParsePackwerk.find(pack.name))
34
- end
35
- VisualizePackwerk.package_graph!(packwerk_packages)
32
+ Private.visualize(packs: selected_packs)
36
33
  end
37
34
  end
38
35
 
@@ -13,13 +13,13 @@ require 'use_packs/private/interactive_cli/use_cases/add_dependency'
13
13
  require 'use_packs/private/interactive_cli/use_cases/get_info'
14
14
  require 'use_packs/private/interactive_cli/use_cases/query'
15
15
  require 'use_packs/private/interactive_cli/use_cases/make_public'
16
- require 'use_packs/private/interactive_cli/use_cases/nest'
16
+ require 'use_packs/private/interactive_cli/use_cases/move_to_parent'
17
17
  require 'use_packs/private/interactive_cli/use_cases/rename'
18
18
  require 'use_packs/private/interactive_cli/use_cases/check'
19
- require 'use_packs/private/interactive_cli/use_cases/update_todo'
19
+ require 'use_packs/private/interactive_cli/use_cases/update'
20
20
  require 'use_packs/private/interactive_cli/use_cases/validate'
21
21
  require 'use_packs/private/interactive_cli/use_cases/regenerate_rubocop_todo'
22
- require 'use_packs/private/interactive_cli/use_cases/lint_package_yml'
22
+ require 'use_packs/private/interactive_cli/use_cases/lint_package_yml_files'
23
23
  require 'use_packs/private/interactive_cli/use_cases/visualize'
24
24
 
25
25
  module UsePacks
@@ -477,6 +477,106 @@ module UsePacks
477
477
  def self.packwerk_package_to_pack(package)
478
478
  Packs.find(package.name)
479
479
  end
480
+
481
+ sig { params(packs: T::Array[Packs::Pack]).void }
482
+ def self.get_info(packs: Packs.all)
483
+ inbound_violations = {}
484
+ outbound_violations = {}
485
+ ParsePackwerk.all.each do |p|
486
+ p.violations.each do |violation|
487
+ outbound_violations[p.name] ||= []
488
+ outbound_violations[p.name] << violation
489
+ inbound_violations[violation.to_package_name] ||= []
490
+ inbound_violations[violation.to_package_name] << violation
491
+ end
492
+ end
493
+
494
+ all_inbound = T.let([], T::Array[ParsePackwerk::Violation])
495
+ all_outbound = T.let([], T::Array[ParsePackwerk::Violation])
496
+ packs.each do |pack|
497
+ all_inbound += inbound_violations[pack.name] || []
498
+ all_outbound += outbound_violations[pack.name] || []
499
+ end
500
+
501
+ puts "There are #{all_inbound.select(&:privacy?).sum { |v| v.files.count }} total inbound privacy violations"
502
+ puts "There are #{all_inbound.select(&:dependency?).sum { |v| v.files.count }} total inbound dependency violations"
503
+ puts "There are #{all_outbound.select(&:privacy?).sum { |v| v.files.count }} total outbound privacy violations"
504
+ puts "There are #{all_outbound.select(&:dependency?).sum { |v| v.files.count }} total outbound dependency violations"
505
+
506
+ packs.sort_by { |p| -p.relative_path.glob('**/*.rb').count }.each do |pack|
507
+ puts "\n=========== Info about: #{pack.name}"
508
+
509
+ owner = CodeOwnership.for_package(pack)
510
+ puts "Owned by: #{owner.nil? ? 'No one' : owner.name}"
511
+ puts "Size: #{pack.relative_path.glob('**/*.rb').count} ruby files"
512
+ puts "Public API: #{pack.relative_path.join('app/public')}"
513
+
514
+ inbound_for_pack = inbound_violations[pack.name] || []
515
+ outbound_for_pack = outbound_violations[pack.name] || []
516
+ puts "There are #{inbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} inbound privacy violations"
517
+ puts "There are #{inbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} inbound dependency violations"
518
+ puts "There are #{outbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} outbound privacy violations"
519
+ puts "There are #{outbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} outbound dependency violations"
520
+ end
521
+ end
522
+
523
+ sig { void }
524
+ def self.lint_package_todo_yml_files!
525
+ contents_before = Private.get_package_todo_contents
526
+ UsePacks.execute(['update-todo'])
527
+ contents_after = Private.get_package_todo_contents
528
+ diff = Private.diff_package_todo_yml(contents_before, contents_after)
529
+
530
+ if diff == ''
531
+ # No diff generated by `update-todo`
532
+ exit 0
533
+ else
534
+ output = <<~OUTPUT
535
+ All `package_todo.yml` files must be up-to-date and that no diff is generated when running `bin/packwerk update-todo`.
536
+ This helps ensure a high quality signal in other engineers' PRs when inspecting new violations by ensuring there are no unrelated changes.
537
+
538
+ There are three main reasons there may be a diff:
539
+ 1) Most likely, you may have stale violations, meaning there are old violations that no longer apply.
540
+ 2) You may have some sort of auto-formatter set up somewhere (e.g. something that reformats YML files) that is, for example, changing double quotes to single quotes. Ensure this is turned off for these auto-generated files.
541
+ 3) You may have edited these files manually. It's recommended to use the `bin/packwerk update-todo` command to make changes to `package_todo.yml` files.
542
+
543
+ In all cases, you can run `bin/packwerk update-todo` to update these files.
544
+
545
+ Here is the diff generated after running `update-todo`:
546
+ ```
547
+ #{diff}
548
+ ```
549
+
550
+ OUTPUT
551
+
552
+ puts output
553
+ UsePacks.config.on_package_todo_lint_failure.call(output)
554
+
555
+ exit 1
556
+ end
557
+ end
558
+
559
+ sig { params(packs: T::Array[Packs::Pack]).void }
560
+ def self.visualize(packs: Packs.all)
561
+ packwerk_packages = packs.map do |pack|
562
+ T.must(ParsePackwerk.find(pack.name))
563
+ end
564
+ VisualizePackwerk.package_graph!(packwerk_packages)
565
+ end
566
+
567
+ sig { returns(String) }
568
+ def self.rename_pack
569
+ <<~WARNING
570
+ We do not yet have an automated API for this.
571
+
572
+ Follow these steps:
573
+ 1. Rename the `packs/your_pack` directory to the name of the new pack, `packs/new_pack_name
574
+ 2. Replace references to `- packs/your_pack` in `package.yml` files with `- packs/new_pack_name`
575
+ 3. Rerun `bin/packwerk update-todo` to update violations
576
+ 4. Run `bin/codeownership validate` to update ownership information
577
+ 5. Please let us know if anything is missing.
578
+ WARNING
579
+ end
480
580
  end
481
581
 
482
582
  private_constant :Private
data/lib/use_packs.rb CHANGED
@@ -248,38 +248,7 @@ module UsePacks
248
248
 
249
249
  sig { void }
250
250
  def self.lint_package_todo_yml_files!
251
- contents_before = Private.get_package_todo_contents
252
- UsePacks.execute(['update-todo'])
253
- contents_after = Private.get_package_todo_contents
254
- diff = Private.diff_package_todo_yml(contents_before, contents_after)
255
-
256
- if diff == ''
257
- # No diff generated by `update-todo`
258
- exit 0
259
- else
260
- output = <<~OUTPUT
261
- All `package_todo.yml` files must be up-to-date and that no diff is generated when running `bin/packwerk update-todo`.
262
- This helps ensure a high quality signal in other engineers' PRs when inspecting new violations by ensuring there are no unrelated changes.
263
-
264
- There are three main reasons there may be a diff:
265
- 1) Most likely, you may have stale violations, meaning there are old violations that no longer apply.
266
- 2) You may have some sort of auto-formatter set up somewhere (e.g. something that reformats YML files) that is, for example, changing double quotes to single quotes. Ensure this is turned off for these auto-generated files.
267
- 3) You may have edited these files manually. It's recommended to use the `bin/packwerk update-todo` command to make changes to `package_todo.yml` files.
268
-
269
- In all cases, you can run `bin/packwerk update-todo` to update these files.
270
-
271
- Here is the diff generated after running `update-todo`:
272
- ```
273
- #{diff}
274
- ```
275
-
276
- OUTPUT
277
-
278
- puts output
279
- UsePacks.config.on_package_todo_lint_failure.call(output)
280
-
281
- exit 1
282
- end
251
+ Private.lint_package_todo_yml_files!
283
252
  end
284
253
 
285
254
  sig { params(packs: T::Array[Packs::Pack]).void }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: use_packs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-30 00:00:00.000000000 Z
11
+ date: 2023-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_ownership
@@ -320,14 +320,15 @@ files:
320
320
  - lib/use_packs/private/interactive_cli/use_cases/create.rb
321
321
  - lib/use_packs/private/interactive_cli/use_cases/get_info.rb
322
322
  - lib/use_packs/private/interactive_cli/use_cases/interface.rb
323
- - lib/use_packs/private/interactive_cli/use_cases/lint_package_yml.rb
323
+ - lib/use_packs/private/interactive_cli/use_cases/lint_package_todo_yml_files.rb
324
+ - lib/use_packs/private/interactive_cli/use_cases/lint_package_yml_files.rb
324
325
  - lib/use_packs/private/interactive_cli/use_cases/make_public.rb
325
326
  - lib/use_packs/private/interactive_cli/use_cases/move.rb
326
- - lib/use_packs/private/interactive_cli/use_cases/nest.rb
327
+ - lib/use_packs/private/interactive_cli/use_cases/move_to_parent.rb
327
328
  - lib/use_packs/private/interactive_cli/use_cases/query.rb
328
329
  - lib/use_packs/private/interactive_cli/use_cases/regenerate_rubocop_todo.rb
329
330
  - lib/use_packs/private/interactive_cli/use_cases/rename.rb
330
- - lib/use_packs/private/interactive_cli/use_cases/update_todo.rb
331
+ - lib/use_packs/private/interactive_cli/use_cases/update.rb
331
332
  - lib/use_packs/private/interactive_cli/use_cases/validate.rb
332
333
  - lib/use_packs/private/interactive_cli/use_cases/visualize.rb
333
334
  - lib/use_packs/private/pack_relationship_analyzer.rb