use_packwerk 0.66.0 → 0.68.0

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: 2c36d9aa08d6196fcfc0a96e3846d0a44f8637f5dc800ac6a0778b7deac637df
4
- data.tar.gz: 07b0910be565a9df52b31c63982ad8e8b75808b80de5b77ad78120293a48c890
3
+ metadata.gz: 277da7b20ce7c61ddaca0c55a9db85d83ced70f6ead305861a91dba3b3a85316
4
+ data.tar.gz: 9841971587ea4f7bb9f18fc61bb48293e485594a738eff3825156ac36ec24775
5
5
  SHA512:
6
- metadata.gz: 46635409558c2c7c0557fb6164a979988558c4d47d0b2467dd97728bd67a6b0c6b77c4614e2c25b49ac075b74de392d7b062b435e0b81b1f60cf2c0c4a044f05
7
- data.tar.gz: 6ebd403c29e4a432d43e7ace961e68c84192e238f0ad3172ad6af8fc1800c6900684cf5e010eb2bd679870258e3ea7b8ddd0b6d9a87612d03c9809db303ccd39
6
+ metadata.gz: 1e0c11e3f4fec41cb8c585f1c533ef06015b4f129c3dc8423d5bdaf1bed7ce2f334042325f81aca8a660d63648005f1a3eba36677c7ae26d7a897aa7197448ce
7
+ data.tar.gz: f735885b3a452f5969219fe7e7949678b2e91e304fd603e442dcf78ce37bb0202ddf8fc8822c8afb8135d683303324448b869640a62d3de28a5369c0744c7c0d
@@ -78,10 +78,32 @@ module UsePackwerk
78
78
  )
79
79
  end
80
80
 
81
- desc 'lint_deprecated_references', 'Ensures `deprecated_references.yml` files are up to date'
81
+ desc 'lint_deprecated_references_yml_files', 'Ensures `deprecated_references.yml` files are up to date'
82
82
  sig { void }
83
- def lint_deprecated_references
84
- UsePackwerk.lint_deprecated_references!
83
+ def lint_deprecated_references_yml_files
84
+ UsePackwerk.lint_deprecated_references_yml_files!
85
+ end
86
+
87
+ desc 'lint_package_yml_files [ packs/my_pack packs/my_other_pack ]', 'Lint `package.yml` files'
88
+ sig { params(pack_names: String).void }
89
+ def lint_package_yml_files(*pack_names)
90
+ UsePackwerk.lint_package_yml_files!(parse_pack_names(pack_names))
91
+ end
92
+
93
+ 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"
94
+ sig { params(pack_names: String).void }
95
+ def regenerate_rubocop_todo(*pack_names)
96
+ RuboCop::Packs.regenerate_todo(packs: parse_pack_names(pack_names))
97
+ end
98
+
99
+ private
100
+
101
+ # This is used by thor to know that these private methods are not intended to be CLI commands
102
+ no_commands do
103
+ sig { params(pack_names: T::Array[String]).returns(T::Array[ParsePackwerk::Package]) }
104
+ def parse_pack_names(pack_names)
105
+ pack_names.empty? ? ParsePackwerk.all : pack_names.map { |p| ParsePackwerk.find(p.gsub(%r{/$}, '')) }.compact
106
+ end
85
107
  end
86
108
  end
87
109
  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
@@ -12,16 +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 lint package.yml files for')
15
- packs.each do |p|
16
- new_package = ParsePackwerk::Package.new(
17
- name: p.name,
18
- enforce_privacy: p.enforce_privacy,
19
- enforce_dependencies: p.enforce_dependencies,
20
- dependencies: p.dependencies.uniq.sort,
21
- metadata: p.metadata
22
- )
23
- ParsePackwerk.write_package_yml!(new_package)
24
- end
15
+ UsePackwerk.lint_package_yml_files!(packs)
25
16
  end
26
17
 
27
18
  sig { override.returns(String) }
@@ -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) }
@@ -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
 
data/lib/use_packwerk.rb CHANGED
@@ -247,7 +247,7 @@ module UsePackwerk
247
247
  end
248
248
 
249
249
  sig { void }
250
- def self.lint_deprecated_references!
250
+ def self.lint_deprecated_references_yml_files!
251
251
  contents_before = Private.get_deprecated_references_contents
252
252
  UsePackwerk.execute(['update-deprecations'])
253
253
  contents_after = Private.get_deprecated_references_contents
@@ -281,4 +281,18 @@ module UsePackwerk
281
281
  exit 1
282
282
  end
283
283
  end
284
+
285
+ sig { params(packs: T::Array[ParsePackwerk::Package]).void }
286
+ def self.lint_package_yml_files!(packs)
287
+ packs.each do |p|
288
+ new_package = ParsePackwerk::Package.new(
289
+ name: p.name,
290
+ enforce_privacy: p.enforce_privacy,
291
+ enforce_dependencies: p.enforce_dependencies,
292
+ dependencies: p.dependencies.uniq.sort,
293
+ metadata: p.metadata
294
+ )
295
+ ParsePackwerk.write_package_yml!(new_package)
296
+ end
297
+ end
284
298
  end
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.66.0
4
+ version: 0.68.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