use_packwerk 0.64.0 → 0.66.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: d6ef7e8cd0b3253daba5690f8c80ad930f5b5fd609bb18bd8760275d64717745
4
- data.tar.gz: 946a5ac17ac9316d6ce4fff47c77e53f228bc94ce95b251813fb00a859e1522e
3
+ metadata.gz: 2c36d9aa08d6196fcfc0a96e3846d0a44f8637f5dc800ac6a0778b7deac637df
4
+ data.tar.gz: 07b0910be565a9df52b31c63982ad8e8b75808b80de5b77ad78120293a48c890
5
5
  SHA512:
6
- metadata.gz: 25b021c870b03ab4ac3086d7620aa773490d1332c49a76e76ccea8f9605c9fc62687b86819bdd7175527dca69bb865374ed7149e3d1af2db3ca89dd434d75e6f
7
- data.tar.gz: c28a6bf619db1a741716de8cfe93e0d634a8c8017e2ea74af3c2e4698b1a6b58de57e6a4b6c378c2dd1e16075e30b28d9dc9ec4b92e575faa8a5bba70cd2bb43
6
+ metadata.gz: 46635409558c2c7c0557fb6164a979988558c4d47d0b2467dd97728bd67a6b0c6b77c4614e2c25b49ac075b74de392d7b062b435e0b81b1f60cf2c0c4a044f05
7
+ data.tar.gz: 6ebd403c29e4a432d43e7ace961e68c84192e238f0ad3172ad6af8fc1800c6900684cf5e010eb2bd679870258e3ea7b8ddd0b6d9a87612d03c9809db303ccd39
data/README.md CHANGED
@@ -4,26 +4,26 @@ UsePackwerk is a gem that helps in creating and maintaining packs. It exists to
4
4
 
5
5
  ## Usage
6
6
  ### General Help
7
- `bin/use_packwerk --help`
7
+ `bin/packs --help` or just `bin/packs` to enter interactive mode.
8
8
 
9
9
  ### Pack Creation
10
- `bin/use_packwerk create packs/your_pack_name_here`
10
+ `bin/packs create packs/your_pack_name_here`
11
11
 
12
12
  ### Moving files to packs
13
- `bin/use_packwerk move packs/your_pack_name_here path/to/file.rb path/to/directory`
13
+ `bin/packs move packs/your_pack_name_here path/to/file.rb path/to/directory`
14
14
  This is used for moving files into a pack (the pack must already exist).
15
15
  Note this works for moving files to packs from the monolith or from other packs
16
16
 
17
17
  Make sure there are no spaces between the comma-separated list of paths of directories.
18
18
 
19
19
  ### Moving a file to public API
20
- `bin/use_packwerk make_public path/to/file.rb,path/to/directory`
20
+ `bin/packs make_public path/to/file.rb,path/to/directory`
21
21
  This moves a file or directory to public API (that is -- the `app/public` folder).
22
22
 
23
23
  Make sure there are no spaces between the comma-separated list of paths of directories.
24
24
 
25
25
  ### Listing top privacy violations
26
- `bin/use_packwerk list_top_privacy_violations packs/my_pack`
26
+ `bin/packs list_top_privacy_violations packs/my_pack`
27
27
  Want to create interfaces? Not sure how your pack's code is being used?
28
28
 
29
29
  You can use this command to list the top privacy violations.
@@ -31,7 +31,7 @@ You can use this command to list the top privacy violations.
31
31
  If no pack name is passed in, this will list out violations across all packs.
32
32
 
33
33
  ### Listing top dependency violations
34
- `bin/use_packwerk list_top_dependency_violations packs/my_pack`
34
+ `bin/packs list_top_dependency_violations packs/my_pack`
35
35
  Want to see who is depending on you? Not sure how your pack's code is being used in an unstated way
36
36
 
37
37
  You can use this command to list the top dependency violations.
@@ -39,7 +39,7 @@ You can use this command to list the top dependency violations.
39
39
  If no pack name is passed in, this will list out violations across all packs.
40
40
 
41
41
  ### Adding a dependency
42
- `bin/use_packwerk add_dependency packs/my_pack packs/dependency_pack_name`
42
+ `bin/packs add_dependency packs/my_pack packs/dependency_pack_name`
43
43
 
44
44
  This can be used to quickly modify a `package.yml` file and add a dependency. It also cleans up the list of dependencies to sort the list and remove redundant entries.
45
45
 
data/bin/packs CHANGED
@@ -2,4 +2,9 @@
2
2
  # typed: strict
3
3
 
4
4
  require_relative '../lib/use_packwerk'
5
- UsePackwerk.start_interactive_mode!
5
+
6
+ if ARGV.empty?
7
+ UsePackwerk.start_interactive_mode!
8
+ else
9
+ UsePackwerk::CLI.start(ARGV)
10
+ end
@@ -16,7 +16,7 @@ module UsePackwerk
16
16
  long_desc <<~LONG_DESC
17
17
  Use this to add a dependency between packs.
18
18
 
19
- When you use bin/use_packwerk add_dependency packs/from_pack packs/to_pack, this command will
19
+ When you use bin/packs add_dependency packs/from_pack packs/to_pack, this command will
20
20
  modify packs/from_pack/package.yml's list of dependencies and add packs/to_pack.
21
21
 
22
22
  This command will also sort the list and make it unique.
@@ -77,5 +77,11 @@ module UsePackwerk
77
77
  per_file_processors: [UsePackwerk::RubocopPostProcessor.new, UsePackwerk::CodeOwnershipPostProcessor.new]
78
78
  )
79
79
  end
80
+
81
+ desc 'lint_deprecated_references', 'Ensures `deprecated_references.yml` files are up to date'
82
+ sig { void }
83
+ def lint_deprecated_references
84
+ UsePackwerk.lint_deprecated_references!
85
+ end
80
86
  end
81
87
  end
@@ -13,10 +13,18 @@ module UsePackwerk
13
13
  sig { returns(UserEventLogger) }
14
14
  attr_accessor :user_event_logger
15
15
 
16
+ OnDeprecatedReferencesLintFailure = T.type_alias do
17
+ T.proc.params(output: String).void
18
+ end
19
+
20
+ sig { returns(OnDeprecatedReferencesLintFailure) }
21
+ attr_accessor :on_deprecated_references_lint_failure
22
+
16
23
  sig { void }
17
24
  def initialize
18
25
  @enforce_dependencies = T.let(default_enforce_dependencies, T::Boolean)
19
26
  @user_event_logger = T.let(DefaultUserEventLogger.new, UserEventLogger)
27
+ @on_deprecated_references_lint_failure = T.let(->(output) {}, OnDeprecatedReferencesLintFailure)
20
28
  end
21
29
 
22
30
  sig { returns(T::Boolean) }
@@ -25,9 +25,9 @@ module UsePackwerk
25
25
  module InteractiveCli
26
26
  extend T::Sig
27
27
 
28
- sig { void }
29
- def self.start!
30
- prompt = TTY::Prompt.new(interrupt: lambda {
28
+ sig { params(prompt: T.nilable(TTY::Prompt)).void }
29
+ def self.start!(prompt: nil)
30
+ prompt ||= TTY::Prompt.new(interrupt: lambda {
31
31
  puts "\n\nGoodbye! I hope you have a good day."
32
32
  exit 1 })
33
33
  help_text = '(Press ↑/↓ arrow to move, Enter to select and letters to filter)'
@@ -389,6 +389,52 @@ module UsePackwerk
389
389
  # otherwise `PackageProtections.config` will attempt to reload the client configuratoin.
390
390
  @loaded_client_configuration = false
391
391
  end
392
+
393
+ sig { returns(T::Hash[String, String]) }
394
+ def self.get_deprecated_references_contents
395
+ deprecated_references = {}
396
+ ParsePackwerk.all.each do |package|
397
+ deprecated_references_yml = ParsePackwerk::DeprecatedReferences.for(package).pathname
398
+ if deprecated_references_yml.exist?
399
+ deprecated_references[deprecated_references_yml.to_s] = deprecated_references_yml.read
400
+ end
401
+ end
402
+
403
+ deprecated_references
404
+ end
405
+
406
+ DeprecatedReferencesFiles = T.type_alias do
407
+ T::Hash[String, T.nilable(String)]
408
+ end
409
+
410
+ sig { params(before: DeprecatedReferencesFiles, after: DeprecatedReferencesFiles).returns(String) }
411
+ def self.diff_deprecated_references_yml(before, after)
412
+ dir_containing_contents_before = Dir.mktmpdir
413
+ dir_containing_contents_after = Dir.mktmpdir
414
+ begin
415
+ write_deprecated_references_to_tmp_folder(before, dir_containing_contents_before)
416
+ write_deprecated_references_to_tmp_folder(after, dir_containing_contents_after)
417
+
418
+ diff = `diff -r #{dir_containing_contents_before}/ #{dir_containing_contents_after}/`
419
+ # For ease of reading, sub out the tmp directory from the diff
420
+ diff.gsub(dir_containing_contents_before, '').gsub(dir_containing_contents_after, '')
421
+ ensure
422
+ FileUtils.remove_entry dir_containing_contents_before
423
+ FileUtils.remove_entry dir_containing_contents_after
424
+ end
425
+ end
426
+
427
+ sig { params(deprecated_references_files: DeprecatedReferencesFiles, tmp_folder: String).void }
428
+ def self.write_deprecated_references_to_tmp_folder(deprecated_references_files, tmp_folder)
429
+ deprecated_references_files.each do |filename, contents|
430
+ next if contents.nil?
431
+
432
+ tmp_folder_pathname = Pathname.new(tmp_folder)
433
+ temp_deprecated_references_yml = tmp_folder_pathname.join(filename)
434
+ FileUtils.mkdir_p(temp_deprecated_references_yml.dirname)
435
+ temp_deprecated_references_yml.write(contents)
436
+ end
437
+ end
392
438
  end
393
439
 
394
440
  private_constant :Private
@@ -19,13 +19,13 @@ module UsePackwerk
19
19
  <<~MSG
20
20
  Your next steps might be:
21
21
 
22
- 1) Move files into your pack with `bin/use_packwerk move #{pack_name} path/to/file.rb`
22
+ 1) Move files into your pack with `bin/packs move #{pack_name} path/to/file.rb`
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
26
  3) Update TODO lists for rubocop implemented protections. See #{documentation_link} for more info
27
27
 
28
- 4) Expose public API in #{pack_name}/app/public. Try `bin/use_packwerk make_public #{pack_name}/path/to/file.rb`
28
+ 4) Expose public API in #{pack_name}/app/public. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
29
29
 
30
30
  5) Update your readme at #{pack_name}/README.md
31
31
  MSG
@@ -49,7 +49,7 @@ module UsePackwerk
49
49
 
50
50
  3) Touch base with each team who owns files involved in this move
51
51
 
52
- 4) Expose public API in #{pack_name}/app/public. Try `bin/use_packwerk make_public #{pack_name}/path/to/file.rb`
52
+ 4) Expose public API in #{pack_name}/app/public. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
53
53
 
54
54
  5) Update your readme at #{pack_name}/README.md
55
55
  MSG
@@ -125,10 +125,10 @@ module UsePackwerk
125
125
  You can prevent other packs from using private API by using packwerk.
126
126
 
127
127
  Want to find how your private API is being used today?
128
- Try running: `bin/use_packwerk list_top_privacy_violations #{pack_name}`
128
+ Try running: `bin/packs list_top_privacy_violations #{pack_name}`
129
129
 
130
130
  Want to move something into this folder?
131
- Try running: `bin/use_packwerk make_public #{pack_name}/path/to/file.rb`
131
+ Try running: `bin/packs make_public #{pack_name}/path/to/file.rb`
132
132
 
133
133
  One more thing -- feel free to delete this file and replace it with a README.md describing your package in the main package directory.
134
134
 
@@ -170,7 +170,7 @@ module UsePackwerk
170
170
  else
171
171
  pack_specific_content = <<~PACK_CONTENT
172
172
  You are listing top #{limit} dependency violations for #{pack_name}. See #{documentation_link} for other utilities!
173
- Pass in a limit to display more or less, e.g. `bin/use_packwerk list_top_dependency_violations #{pack_name} -l 1000`
173
+ Pass in a limit to display more or less, e.g. `bin/packs list_top_dependency_violations #{pack_name} -l 1000`
174
174
 
175
175
  This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
176
176
  Anything not in #{pack_name}/app/public is considered private API.
@@ -211,7 +211,7 @@ module UsePackwerk
211
211
  if pack_name.nil?
212
212
  pack_specific_content = <<~PACK_CONTENT
213
213
  You are listing top #{limit} privacy violations for all packs. See #{documentation_link} for other utilities!
214
- Pass in a limit to display more or less, e.g. `bin/use_packwerk list_top_privacy_violations #{pack_name} -l 1000`
214
+ Pass in a limit to display more or less, e.g. `bin/packs list_top_privacy_violations #{pack_name} -l 1000`
215
215
 
216
216
  This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
217
217
  Anything not in pack_name/app/public is considered private API.
@@ -219,7 +219,7 @@ module UsePackwerk
219
219
  else
220
220
  pack_specific_content = <<~PACK_CONTENT
221
221
  You are listing top #{limit} privacy violations for #{pack_name}. See #{documentation_link} for other utilities!
222
- Pass in a limit to display more or less, e.g. `bin/use_packwerk list_top_privacy_violations #{pack_name} -l 1000`
222
+ Pass in a limit to display more or less, e.g. `bin/packs list_top_privacy_violations #{pack_name} -l 1000`
223
223
 
224
224
  This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
225
225
  Anything not in #{pack_name}/app/public is considered private API.
@@ -253,7 +253,7 @@ module UsePackwerk
253
253
  - packs/other_pack_a: 1
254
254
  - packs/other_pack_b: 1
255
255
 
256
- Lastly, remember you can use `bin/use_packwerk make_public #{pack_name}/path/to/file.rb` to make your class, constant, or module public API.
256
+ Lastly, remember you can use `bin/packs make_public #{pack_name}/path/to/file.rb` to make your class, constant, or module public API.
257
257
  MSG
258
258
  end
259
259
 
data/lib/use_packwerk.rb CHANGED
@@ -245,4 +245,40 @@ module UsePackwerk
245
245
  Private::PackwerkWrapper.packwerk_cli_execute_safely(argv, formatter)
246
246
  formatter.aggregated_offenses.compact
247
247
  end
248
+
249
+ sig { void }
250
+ def self.lint_deprecated_references!
251
+ contents_before = Private.get_deprecated_references_contents
252
+ UsePackwerk.execute(['update-deprecations'])
253
+ contents_after = Private.get_deprecated_references_contents
254
+ diff = Private.diff_deprecated_references_yml(contents_before, contents_after)
255
+
256
+ if diff == ''
257
+ # No diff generated by `update-deprecations`
258
+ exit 0
259
+ else
260
+ output = <<~OUTPUT
261
+ All `deprecated_references.yml` files must be up-to-date and that no diff is generated when running `bin/packwerk update-deprecations`.
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-deprecations` command to make changes to `deprecated_references.yml` files.
268
+
269
+ In all cases, you can run `bin/packwerk update-deprecations` to update these files.
270
+
271
+ Here is the diff generated after running `update-deprecations`:
272
+ ```
273
+ #{diff}
274
+ ```
275
+
276
+ OUTPUT
277
+
278
+ puts output
279
+ UsePackwerk.config.on_deprecated_references_lint_failure.call(output)
280
+
281
+ exit 1
282
+ end
283
+ end
248
284
  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.64.0
4
+ version: 0.66.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-16 00:00:00.000000000 Z
11
+ date: 2022-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_ownership
@@ -281,7 +281,6 @@ description: UsePackwerk is a gem that helps in creating and maintaining packwer
281
281
  email:
282
282
  - dev@gusto.com
283
283
  executables:
284
- - use_packwerk
285
284
  - packs
286
285
  extensions: []
287
286
  extra_rdoc_files: []
@@ -290,7 +289,6 @@ files:
290
289
  - bin/packs
291
290
  - bin/rubocop
292
291
  - bin/tapioca
293
- - bin/use_packwerk
294
292
  - lib/use_packwerk.rb
295
293
  - lib/use_packwerk/cli.rb
296
294
  - lib/use_packwerk/code_ownership_post_processor.rb
data/bin/use_packwerk DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # typed: strict
3
-
4
- require_relative '../lib/use_packwerk'
5
- UsePackwerk::CLI.start(ARGV)