use_packwerk 0.67.0 → 0.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3044a336515f7443c6cfcf3814d066d8b2cfdf812de19214cfacddc49dbfcb8d
4
- data.tar.gz: c249aea974522df11a037f8b1e46b956d27d2f06ad2dfab9d8076e5399031a15
3
+ metadata.gz: fb9fada6d2dddd8ab4f85d7133c16fb28557c191ebd10e4e4e98e95d2bc3bb43
4
+ data.tar.gz: d6c81594392166bb4ca6e849bb5c3366276f1643fdb41243187edb3413d4bce3
5
5
  SHA512:
6
- metadata.gz: fb2a5a22e390444fcb14f9ef039dfaaa2678c018cbe478794c8fba1ec40ccbcb713ab996611bbbdb6ed2f13a39c773e5a3d080ff1d35276ba0b0e24bd755c516
7
- data.tar.gz: 806f18afe7e10d280dcd179539401a12dc3078d79b60d44731c3bb608e639f1a10986e077dcaec578b5a6f2d706de746d39e495ff075f03cf1442f141ec48ece
6
+ metadata.gz: d24503a5e649108ef31d5632e8f42b688684d95772aff2802c76cc08e45955cc360006ca51682506cac20bc85c3bfc65f31e4d64b4da9d30112da5a64742f165
7
+ data.tar.gz: c77c2e8e436e6c0a116746998a064fbc5551ac78f8f5dc3896a54d06faf09c66481f59c5efe72641f6d91a4cb0c12cd9b9c896ed213d3de3f7e3ba7a8bb4ce13
@@ -87,8 +87,41 @@ module UsePackwerk
87
87
  desc 'lint_package_yml_files [ packs/my_pack packs/my_other_pack ]', 'Lint `package.yml` files'
88
88
  sig { params(pack_names: String).void }
89
89
  def lint_package_yml_files(*pack_names)
90
- packages = pack_names.empty? ? ParsePackwerk.all : pack_names.map { |p| ParsePackwerk.find(p.gsub(%r{/$}, '')) }.compact
91
- UsePackwerk.lint_package_yml_files!(packages)
90
+ UsePackwerk.lint_package_yml_files!(parse_pack_names(pack_names))
91
+ end
92
+
93
+ desc 'validate', 'Run bin/packwerk validate (detects cycles)'
94
+ sig { void }
95
+ def validate
96
+ system('bin/packwerk validate')
97
+ end
98
+
99
+ desc 'check [ packs/my_pack ]', 'Run bin/packwerk check'
100
+ sig { params(paths: String).void }
101
+ def check(*paths)
102
+ system("bin/packwerk check #{paths.join(' ')}")
103
+ end
104
+
105
+ desc 'update [ packs/my_pack ]', 'Run bin/packwerk update-deprecations'
106
+ sig { params(paths: String).void }
107
+ def update(*paths)
108
+ system("bin/packwerk update-deprecations #{paths.join(' ')}")
109
+ end
110
+
111
+ desc 'regenerate_rubocop_todo [ packs/my_pack packs/my_other_pack ]', "Regenerate packs/*/#{RuboCop::Packs::PACK_LEVEL_RUBOCOP_TODO_YML} for one or more packs"
112
+ sig { params(pack_names: String).void }
113
+ def regenerate_rubocop_todo(*pack_names)
114
+ RuboCop::Packs.regenerate_todo(packs: parse_pack_names(pack_names))
115
+ end
116
+
117
+ private
118
+
119
+ # This is used by thor to know that these private methods are not intended to be CLI commands
120
+ no_commands do
121
+ sig { params(pack_names: T::Array[String]).returns(T::Array[ParsePackwerk::Package]) }
122
+ def parse_pack_names(pack_names)
123
+ pack_names.empty? ? ParsePackwerk.all : pack_names.map { |p| ParsePackwerk.find(p.gsub(%r{/$}, '')) }.compact
124
+ end
92
125
  end
93
126
  end
94
127
  end
@@ -40,8 +40,8 @@ module UsePackwerk
40
40
  end
41
41
  end
42
42
 
43
- sig { void }
44
- def print_final_message!
43
+ sig { params(file_move_operations: T::Array[Private::FileMoveOperation]).void }
44
+ def after_move_files!(file_move_operations)
45
45
  if @teams.any?
46
46
  Logging.section('Code Ownership') do
47
47
  Logging.print('This section contains info about the current ownership distribution of the moved files.')
@@ -10,8 +10,8 @@ module UsePackwerk
10
10
  sig { abstract.params(file_move_operation: Private::FileMoveOperation).void }
11
11
  def before_move_file!(file_move_operation); end
12
12
 
13
- sig { void }
14
- def print_final_message!
13
+ sig { params(file_move_operations: T::Array[Private::FileMoveOperation]).void }
14
+ def after_move_files!(file_move_operations)
15
15
  nil
16
16
  end
17
17
  end
@@ -0,0 +1,25 @@
1
+ # typed: strict
2
+
3
+ module UsePackwerk
4
+ module Private
5
+ module InteractiveCli
6
+ module UseCases
7
+ class Check
8
+ extend T::Sig
9
+ extend T::Helpers
10
+ include Interface
11
+
12
+ sig { override.returns(String) }
13
+ def user_facing_name
14
+ 'Run bin/packwerk check'
15
+ end
16
+
17
+ sig { override.params(prompt: TTY::Prompt).void }
18
+ def perform!(prompt)
19
+ system('bin/packwerk check')
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -12,7 +12,7 @@ module UsePackwerk
12
12
  sig { override.params(prompt: TTY::Prompt).void }
13
13
  def perform!(prompt)
14
14
  packs = PackSelector.single_or_all_pack_multi_select(prompt, question_text: "Please select the packs you want to regenerate `#{RuboCop::Packs::PACK_LEVEL_RUBOCOP_TODO_YML}` for")
15
- RuboCop::Packs.auto_generate_rubocop_todo(packs: packs)
15
+ RuboCop::Packs.regenerate_todo(packs: packs)
16
16
  end
17
17
 
18
18
  sig { override.returns(String) }
@@ -14,6 +14,7 @@ require 'use_packwerk/private/interactive_cli/use_cases/query'
14
14
  require 'use_packwerk/private/interactive_cli/use_cases/make_public'
15
15
  require 'use_packwerk/private/interactive_cli/use_cases/nest'
16
16
  require 'use_packwerk/private/interactive_cli/use_cases/rename'
17
+ require 'use_packwerk/private/interactive_cli/use_cases/check'
17
18
  require 'use_packwerk/private/interactive_cli/use_cases/update_deprecations'
18
19
  require 'use_packwerk/private/interactive_cli/use_cases/validate'
19
20
  require 'use_packwerk/private/interactive_cli/use_cases/regenerate_rubocop_todo'
@@ -4,7 +4,7 @@ module UsePackwerk
4
4
  module Private
5
5
  module PackwerkWrapper
6
6
  #
7
- # This formatter simply collects offenses so we can feed them into PackageProtections
7
+ # This formatter simply collects offenses so we can feed them into other systems
8
8
  #
9
9
  class OffensesAggregatorFormatter
10
10
  extend T::Sig
@@ -87,6 +87,8 @@ module UsePackwerk
87
87
  add_readme_todo(package)
88
88
  package_location = package.directory
89
89
 
90
+ file_move_operations = T.let([], T::Array[Private::FileMoveOperation])
91
+
90
92
  if paths_relative_to_root.any?
91
93
  Logging.section('File Operations') do
92
94
  file_paths = paths_relative_to_root.flat_map do |path|
@@ -113,21 +115,26 @@ module UsePackwerk
113
115
  origin_pathname
114
116
  end
115
117
  end
116
- file_move_operations = file_paths.map do |origin_pathname|
117
- FileMoveOperation.new(
118
+ file_move_operations = file_paths.flat_map do |origin_pathname|
119
+ file_move_operation = FileMoveOperation.new(
118
120
  origin_pathname: origin_pathname,
119
121
  destination_pathname: FileMoveOperation.destination_pathname_for_package_move(origin_pathname, package_location),
120
122
  destination_pack: package
121
123
  )
124
+ [
125
+ file_move_operation,
126
+ file_move_operation.spec_file_move_operation
127
+ ]
122
128
  end
123
129
  file_move_operations.each do |file_move_operation|
124
130
  Private.package_filepath(file_move_operation, per_file_processors)
125
- Private.package_filepath_spec(file_move_operation, per_file_processors)
126
131
  end
127
132
  end
128
133
  end
129
134
 
130
- per_file_processors.each(&:print_final_message!)
135
+ per_file_processors.each do |processor|
136
+ processor.after_move_files!(file_move_operations)
137
+ end
131
138
  end
132
139
 
133
140
  sig do
@@ -217,6 +224,8 @@ module UsePackwerk
217
224
  end
218
225
  def self.make_public!(paths_relative_to_root:, per_file_processors:)
219
226
  if paths_relative_to_root.any?
227
+ file_move_operations = T.let([], T::Array[Private::FileMoveOperation])
228
+
220
229
  Logging.section('File Operations') do
221
230
  file_paths = paths_relative_to_root.flat_map do |path|
222
231
  origin_pathname = Pathname.new(path).cleanpath
@@ -227,22 +236,30 @@ module UsePackwerk
227
236
  end
228
237
  end
229
238
 
230
- file_move_operations = file_paths.map do |path|
239
+ file_move_operations = file_paths.flat_map do |path|
231
240
  package = ParsePackwerk.package_from_path(path)
232
241
  origin_pathname = Pathname.new(path).cleanpath
233
242
 
234
- FileMoveOperation.new(
243
+ file_move_operation = FileMoveOperation.new(
235
244
  origin_pathname: origin_pathname,
236
245
  destination_pathname: FileMoveOperation.destination_pathname_for_new_public_api(origin_pathname),
237
246
  destination_pack: package
238
247
  )
248
+
249
+ [
250
+ file_move_operation,
251
+ file_move_operation.spec_file_move_operation
252
+ ]
239
253
  end
240
254
 
241
255
  file_move_operations.each do |file_move_operation|
242
256
  Private.package_filepath(file_move_operation, per_file_processors)
243
- Private.package_filepath_spec(file_move_operation, per_file_processors)
244
257
  end
245
258
  end
259
+
260
+ per_file_processors.each do |processor|
261
+ processor.after_move_files!(file_move_operations)
262
+ end
246
263
  end
247
264
  end
248
265
 
@@ -290,11 +307,6 @@ module UsePackwerk
290
307
  idempotent_mv(origin, destination)
291
308
  end
292
309
 
293
- sig { params(file_move_operation: FileMoveOperation, per_file_processors: T::Array[UsePackwerk::PerFileProcessorInterface]).void }
294
- def self.package_filepath_spec(file_move_operation, per_file_processors)
295
- package_filepath(file_move_operation.spec_file_move_operation, per_file_processors)
296
- end
297
-
298
310
  sig { params(origin: Pathname, destination: Pathname).void }
299
311
  def self.idempotent_mv(origin, destination)
300
312
  if origin.exist? && destination.exist?
@@ -385,8 +397,8 @@ module UsePackwerk
385
397
  sig { void }
386
398
  def self.bust_cache!
387
399
  UsePackwerk.config.bust_cache!
388
- # This comes explicitly after `PackageProtections.config.bust_cache!` because
389
- # otherwise `PackageProtections.config` will attempt to reload the client configuratoin.
400
+ # This comes explicitly after `UsePackwerk.config.bust_cache!` because
401
+ # otherwise `UsePackwerk.config` will attempt to reload the client configuratoin.
390
402
  @loaded_client_configuration = false
391
403
  end
392
404
 
@@ -21,6 +21,7 @@ module UsePackwerk
21
21
 
22
22
  if file_move_operation.origin_pack.name != ParsePackwerk::ROOT_PACKAGE_NAME && file_move_operation.destination_pack.name != ParsePackwerk::ROOT_PACKAGE_NAME
23
23
  origin_rubocop_todo = file_move_operation.origin_pack.directory.join(RuboCop::Packs::PACK_LEVEL_RUBOCOP_TODO_YML)
24
+ # If there were TODOs for this file in the origin pack's pack-based rubocop, we want to move it to the destination
24
25
  if origin_rubocop_todo.exist?
25
26
  loaded_origin_rubocop_todo = YAML.load_file(origin_rubocop_todo)
26
27
  new_origin_rubocop_todo = loaded_origin_rubocop_todo.dup
@@ -46,5 +47,21 @@ module UsePackwerk
46
47
  end
47
48
  end
48
49
  end
50
+
51
+ sig { params(file_move_operations: T::Array[Private::FileMoveOperation]).void }
52
+ def after_move_files!(file_move_operations)
53
+ # There could also be no TODOs for this file, but moving it produced TODOs. This could happen if:
54
+ # 1) The origin pack did not enforce a rubocop, such as typed public APIs
55
+ # 2) The file satisfied the cop in the origin pack, such as the Packs/RootNamespaceIsPackName, but the desired
56
+ # namespace changed once the file was moved to a different pack.
57
+ files = []
58
+ file_move_operations.each do |file_move_operation|
59
+ if file_move_operation.destination_pathname.exist?
60
+ files << file_move_operation.destination_pathname.to_s
61
+ end
62
+ end
63
+
64
+ RuboCop::Packs.regenerate_todo(files: files)
65
+ end
49
66
  end
50
67
  end
@@ -23,11 +23,9 @@ module UsePackwerk
23
23
 
24
24
  2) Run `bin/packwerk update-deprecations` to update the violations. Make sure to run `spring stop` if you've added new load paths (new top-level directories) in your pack.
25
25
 
26
- 3) Update TODO lists for rubocop implemented protections. See #{documentation_link} for more info
26
+ 3) Expose public API in #{pack_name}/app/public. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
27
27
 
28
- 4) Expose public API in #{pack_name}/app/public. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
29
-
30
- 5) Update your readme at #{pack_name}/README.md
28
+ 4) Update your readme at #{pack_name}/README.md
31
29
  MSG
32
30
  end
33
31
 
@@ -45,13 +43,11 @@ module UsePackwerk
45
43
 
46
44
  1) Run `bin/packwerk update-deprecations` to update the violations. Make sure to run `spring stop` if you've added new load paths (new top-level directories) in your pack.
47
45
 
48
- 2) Update TODO lists for rubocop implemented protections. See #{documentation_link} for more info
49
-
50
- 3) Touch base with each team who owns files involved in this move
46
+ 2) Touch base with each team who owns files involved in this move
51
47
 
52
- 4) Expose public API in #{pack_name}/app/public. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
48
+ 3) Expose public API in #{pack_name}/app/public. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
53
49
 
54
- 5) Update your readme at #{pack_name}/README.md
50
+ 4) Update your readme at #{pack_name}/README.md
55
51
  MSG
56
52
  end
57
53
 
@@ -69,11 +65,9 @@ module UsePackwerk
69
65
 
70
66
  1) Run `bin/packwerk update-deprecations` to update the violations. Make sure to run `spring stop` if you've added new load paths (new top-level directories) in your pack.
71
67
 
72
- 2) Update TODO lists for rubocop implemented protections. See #{documentation_link} for more info
73
-
74
- 3) Work to migrate clients of private API to your new public API
68
+ 2) Work to migrate clients of private API to your new public API
75
69
 
76
- 4) Update your README at packs/your_package_name/README.md
70
+ 3) Update your README at packs/your_package_name/README.md
77
71
  MSG
78
72
  end
79
73
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: use_packwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.67.0
4
+ version: 0.69.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-18 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_ownership
@@ -302,6 +302,7 @@ files:
302
302
  - lib/use_packwerk/private/interactive_cli/pack_selector.rb
303
303
  - lib/use_packwerk/private/interactive_cli/team_selector.rb
304
304
  - lib/use_packwerk/private/interactive_cli/use_cases/add_dependency.rb
305
+ - lib/use_packwerk/private/interactive_cli/use_cases/check.rb
305
306
  - lib/use_packwerk/private/interactive_cli/use_cases/create.rb
306
307
  - lib/use_packwerk/private/interactive_cli/use_cases/get_info.rb
307
308
  - lib/use_packwerk/private/interactive_cli/use_cases/interface.rb