packwerk 2.2.1 → 2.2.2

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: a7968dbdc908eb500726b8af244e0de8e44075b86409eef871003d47174a139d
4
- data.tar.gz: 48037d44dbb482841e64c218a22b98978e5e6dac2dd277b10b2989c508daaa26
3
+ metadata.gz: 6e1c2cdab1129d016428019597dc9f19dbf0836d0c545a13ce780486bf9fbba1
4
+ data.tar.gz: d9556ef773c776283a30f8e22308f0068e4d1a4ea918e81af44a0e126c0ca62e
5
5
  SHA512:
6
- metadata.gz: 8e3c43a046bb108cc76fde787fbdd5d67475c0feba647e9653e6f7e9fc2fc0082994f09791a4fc870e639f3a964ab2727fd3216601f6dad3f69ccdf3059fb0ee
7
- data.tar.gz: 66433d48c993ce76edb6eb2bf08d7ce6a474efcac790e4b42628a1f2371b09be579b7eb58dc84aaef2614e6779302e34f80559dfc179d48141aeb2b2f99e41d3
6
+ metadata.gz: 74cb6f2c95a7d51dc8e5199a47601b53897c29cfd6dde5d0c0ada40566d19bf0f9d0f0fcf9209dbe5b9e0ccbbcfcac9c1282fa74377af0b8e6cee63e75204948
7
+ data.tar.gz: d03e35ab0975d457a9202d2df2f697372f22f5a4072880dc7d308b87581ffd5a30446b8b235b221da0655cd4b31be58552b0a3f658e15a8c48d78cdee23f9794
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- packwerk (2.2.1)
4
+ packwerk (2.2.2)
5
5
  activesupport (>= 5.2)
6
6
  ast
7
7
  better_html
@@ -10,6 +10,7 @@ PATH
10
10
  parallel
11
11
  parser
12
12
  sorbet-runtime (>= 0.5.9914)
13
+ zeitwerk (>= 2.6.1)
13
14
 
14
15
  GEM
15
16
  remote: https://rubygems.org/
@@ -261,7 +262,7 @@ GEM
261
262
  yard-sorbet (0.6.1)
262
263
  sorbet-runtime (>= 0.5)
263
264
  yard (>= 0.9)
264
- zeitwerk (2.6.0)
265
+ zeitwerk (2.6.6)
265
266
 
266
267
  PLATFORMS
267
268
  ruby
@@ -21,7 +21,7 @@ module Packwerk
21
21
  sig { returns(T::Hash[String, Module]) }
22
22
  def extract_application_autoload_paths
23
23
  Rails.autoloaders.inject({}) do |h, loader|
24
- h.merge(loader.root_dirs)
24
+ h.merge(loader.dirs(namespaces: true))
25
25
  end
26
26
  end
27
27
 
data/lib/packwerk/cli.rb CHANGED
@@ -50,8 +50,6 @@ module Packwerk
50
50
  case subcommand
51
51
  when "init"
52
52
  init
53
- when "generate_configs"
54
- generate_configs
55
53
  when "check"
56
54
  output_result(parse_run(args).check)
57
55
  when "detect-stale-violations"
@@ -61,19 +59,11 @@ module Packwerk
61
59
  when "validate"
62
60
  validate(args)
63
61
  when nil, "help"
64
- @err_out.puts(<<~USAGE)
65
- Usage: #{$PROGRAM_NAME} <subcommand>
66
-
67
- Subcommands:
68
- init - set up packwerk
69
- check - run all checks
70
- update-deprecations - update deprecated references
71
- validate - verify integrity of packwerk and package configuration
72
- help - display help information about packwerk
73
- USAGE
74
- true
62
+ usage
75
63
  else
76
- @err_out.puts("'#{subcommand}' is not a packwerk command. See `packwerk help`.")
64
+ @err_out.puts(
65
+ "'#{subcommand}' is not a packwerk command. See `packwerk help`."
66
+ )
77
67
  false
78
68
  end
79
69
  end
@@ -116,6 +106,21 @@ module Packwerk
116
106
  success
117
107
  end
118
108
 
109
+ sig { returns(T::Boolean) }
110
+ def usage
111
+ @err_out.puts(<<~USAGE)
112
+ Usage: #{$PROGRAM_NAME} <subcommand>
113
+
114
+ Subcommands:
115
+ init - set up packwerk
116
+ check - run all checks
117
+ update-deprecations - update deprecated_references.yml files
118
+ validate - verify integrity of packwerk and package configuration
119
+ help - display help information about packwerk
120
+ USAGE
121
+ true
122
+ end
123
+
119
124
  sig { params(result: Result).returns(T::Boolean) }
120
125
  def output_result(result)
121
126
  @out.puts
@@ -84,7 +84,7 @@ module Packwerk
84
84
  sig { void }
85
85
  def dump
86
86
  if @new_entries.empty?
87
- File.delete(@filepath) if File.exist?(@filepath)
87
+ delete_if_exists
88
88
  else
89
89
  prepare_entries_for_dump
90
90
  message = <<~MESSAGE
@@ -102,6 +102,11 @@ module Packwerk
102
102
  end
103
103
  end
104
104
 
105
+ sig { void }
106
+ def delete_if_exists
107
+ File.delete(@filepath) if File.exist?(@filepath)
108
+ end
109
+
105
110
  private
106
111
 
107
112
  sig { returns(EntriesType) }
@@ -57,11 +57,10 @@ module Packwerk
57
57
  end
58
58
  end
59
59
 
60
- sig { void }
61
- def dump_deprecated_references_files
62
- @deprecated_references.each do |_, deprecated_references_file|
63
- deprecated_references_file.dump
64
- end
60
+ sig { params(package_set: Packwerk::PackageSet).void }
61
+ def persist_deprecated_references_files(package_set)
62
+ dump_deprecated_references_files
63
+ cleanup_extra_deprecated_references_files(package_set)
65
64
  end
66
65
 
67
66
  sig { returns(T::Array[Packwerk::Offense]) }
@@ -71,6 +70,23 @@ module Packwerk
71
70
 
72
71
  private
73
72
 
73
+ sig { params(package_set: Packwerk::PackageSet).void }
74
+ def cleanup_extra_deprecated_references_files(package_set)
75
+ packages_without_todos = (package_set.packages.values - @deprecated_references.keys)
76
+
77
+ packages_without_todos.each do |package|
78
+ Packwerk::DeprecatedReferences.new(
79
+ package,
80
+ deprecated_references_file_for(package),
81
+ ).delete_if_exists
82
+ end
83
+ end
84
+
85
+ sig { void }
86
+ def dump_deprecated_references_files
87
+ @deprecated_references.each_value(&:dump)
88
+ end
89
+
74
90
  sig { params(package: Packwerk::Package).returns(Packwerk::DeprecatedReferences) }
75
91
  def deprecated_references_for(package)
76
92
  @deprecated_references[package] ||= Packwerk::DeprecatedReferences.new(
@@ -34,7 +34,13 @@ module Packwerk
34
34
 
35
35
  sig { returns(Result) }
36
36
  def detect_stale_violations
37
- offense_collection = find_offenses
37
+ warn(<<~WARNING.squish)
38
+ DEPRECATION WARNING: `detect-stale-violation` is deprecated,
39
+ the output of `check` includes stale references.
40
+ WARNING
41
+
42
+ run_context = Packwerk::RunContext.from_configuration(@configuration)
43
+ offense_collection = find_offenses(run_context)
38
44
 
39
45
  result_status = !offense_collection.stale_violations?(@relative_file_set)
40
46
  message = @offenses_formatter.show_stale_violations(offense_collection, @relative_file_set)
@@ -44,8 +50,9 @@ module Packwerk
44
50
 
45
51
  sig { returns(Result) }
46
52
  def update_deprecations
47
- offense_collection = find_offenses
48
- offense_collection.dump_deprecated_references_files
53
+ run_context = Packwerk::RunContext.from_configuration(@configuration)
54
+ offense_collection = find_offenses(run_context)
55
+ offense_collection.persist_deprecated_references_files(run_context.package_set)
49
56
 
50
57
  message = <<~EOS
51
58
  #{@offenses_formatter.show_offenses(offense_collection.errors)}
@@ -57,7 +64,8 @@ module Packwerk
57
64
 
58
65
  sig { returns(Result) }
59
66
  def check
60
- offense_collection = find_offenses(show_errors: true)
67
+ run_context = Packwerk::RunContext.from_configuration(@configuration)
68
+ offense_collection = find_offenses(run_context, show_errors: true)
61
69
 
62
70
  messages = [
63
71
  @offenses_formatter.show_offenses(offense_collection.outstanding_offenses),
@@ -72,12 +80,11 @@ module Packwerk
72
80
 
73
81
  private
74
82
 
75
- sig { params(show_errors: T::Boolean).returns(OffenseCollection) }
76
- def find_offenses(show_errors: false)
83
+ sig { params(run_context: Packwerk::RunContext, show_errors: T::Boolean).returns(OffenseCollection) }
84
+ def find_offenses(run_context, show_errors: false)
77
85
  offense_collection = OffenseCollection.new(@configuration.root_path)
78
86
  @progress_formatter.started(@relative_file_set)
79
87
 
80
- run_context = Packwerk::RunContext.from_configuration(@configuration)
81
88
  all_offenses = T.let([], T::Array[Offense])
82
89
 
83
90
  process_file = T.let(->(relative_file) do
@@ -71,6 +71,7 @@ module Packwerk
71
71
 
72
72
  @file_processor = T.let(nil, T.nilable(FileProcessor))
73
73
  @context_provider = T.let(nil, T.nilable(ConstantDiscovery))
74
+ @package_set = T.let(nil, T.nilable(PackageSet))
74
75
  # We need to initialize this before we fork the process, see https://github.com/Shopify/packwerk/issues/182
75
76
  @cache = T.let(
76
77
  Cache.new(enable_cache: @cache_enabled, cache_directory: @cache_directory, config_path: @config_path), Cache
@@ -90,6 +91,11 @@ module Packwerk
90
91
  processed_file.offenses + references.flat_map { |reference| reference_checker.call(reference) }
91
92
  end
92
93
 
94
+ sig { returns(PackageSet) }
95
+ def package_set
96
+ @package_set ||= ::Packwerk::PackageSet.load_all_from(@root_path, package_pathspec: @package_paths)
97
+ end
98
+
93
99
  private
94
100
 
95
101
  sig { returns(FileProcessor) }
@@ -123,11 +129,6 @@ module Packwerk
123
129
  )
124
130
  end
125
131
 
126
- sig { returns(PackageSet) }
127
- def package_set
128
- ::Packwerk::PackageSet.load_all_from(@root_path, package_pathspec: @package_paths)
129
- end
130
-
131
132
  sig { returns(T::Array[ConstantNameInspector]) }
132
133
  def constant_name_inspectors
133
134
  [
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Packwerk
5
- VERSION = "2.2.1"
5
+ VERSION = "2.2.2"
6
6
  end
data/packwerk.gemspec CHANGED
@@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
45
45
  spec.add_dependency("constant_resolver", ">= 0.2.0")
46
46
  spec.add_dependency("parallel")
47
47
  spec.add_dependency("sorbet-runtime", ">= 0.5.9914")
48
+ spec.add_dependency("zeitwerk", ">= 2.6.1")
48
49
 
49
50
  # For Ruby parsing
50
51
  spec.add_dependency("ast")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2022-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.5.9914
83
+ - !ruby/object:Gem::Dependency
84
+ name: zeitwerk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.6.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.6.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: ast
85
99
  requirement: !ruby/object:Gem::Requirement