packwerk 1.1.2 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +17 -8
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +129 -111
- data/README.md +9 -2
- data/TROUBLESHOOT.md +2 -2
- data/USAGE.md +30 -30
- data/bin/m +29 -0
- data/bin/rake +29 -0
- data/bin/rubocop +29 -0
- data/bin/srb +29 -0
- data/bin/tapioca +29 -0
- data/dev.yml +7 -7
- data/gemfiles/Gemfile-rails-6-0 +22 -0
- data/lib/packwerk.rb +72 -36
- data/lib/packwerk/application_load_paths.rb +18 -8
- data/lib/packwerk/application_validator.rb +26 -27
- data/lib/packwerk/association_inspector.rb +0 -3
- data/lib/packwerk/checker.rb +2 -8
- data/lib/packwerk/cli.rb +29 -109
- data/lib/packwerk/configuration.rb +5 -0
- data/lib/packwerk/const_node_inspector.rb +0 -2
- data/lib/packwerk/constant_discovery.rb +2 -0
- data/lib/packwerk/constant_name_inspector.rb +0 -1
- data/lib/packwerk/dependency_checker.rb +2 -15
- data/lib/packwerk/deprecated_references.rb +5 -11
- data/lib/packwerk/file_processor.rb +0 -4
- data/lib/packwerk/formatters/offenses_formatter.rb +13 -9
- data/lib/packwerk/formatters/progress_formatter.rb +5 -4
- data/lib/packwerk/generators/configuration_file.rb +0 -1
- data/lib/packwerk/inflector.rb +0 -2
- data/lib/packwerk/node.rb +1 -0
- data/lib/packwerk/node_processor.rb +15 -32
- data/lib/packwerk/node_processor_factory.rb +0 -5
- data/lib/packwerk/node_visitor.rb +1 -4
- data/lib/packwerk/offense.rb +0 -4
- data/lib/packwerk/offense_collection.rb +84 -0
- data/lib/packwerk/offenses_formatter.rb +19 -0
- data/lib/packwerk/package.rb +17 -1
- data/lib/packwerk/package_set.rb +0 -2
- data/lib/packwerk/parse_run.rb +106 -0
- data/lib/packwerk/parsed_constant_definitions.rb +0 -2
- data/lib/packwerk/parsers.rb +0 -2
- data/lib/packwerk/parsers/erb.rb +0 -2
- data/lib/packwerk/parsers/factory.rb +0 -2
- data/lib/packwerk/privacy_checker.rb +2 -15
- data/lib/packwerk/reference_extractor.rb +0 -8
- data/lib/packwerk/reference_offense.rb +49 -0
- data/lib/packwerk/result.rb +9 -0
- data/lib/packwerk/run_context.rb +4 -21
- data/lib/packwerk/sanity_checker.rb +0 -2
- data/lib/packwerk/version.rb +1 -1
- data/lib/packwerk/violation_type.rb +0 -2
- data/library.yml +1 -1
- data/packwerk.gemspec +1 -0
- data/service.yml +1 -4
- data/shipit.rubygems.yml +5 -1
- data/sorbet/rbi/gems/{actioncable@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → actioncable@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +56 -36
- data/sorbet/rbi/gems/{actionmailbox@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → actionmailbox@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +25 -28
- data/sorbet/rbi/gems/{actionmailer@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → actionmailer@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +43 -24
- data/sorbet/rbi/gems/{actionpack@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → actionpack@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +382 -284
- data/sorbet/rbi/gems/{actiontext@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → actiontext@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +76 -40
- data/sorbet/rbi/gems/{actionview@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → actionview@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +206 -195
- data/sorbet/rbi/gems/{activejob@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → activejob@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +64 -75
- data/sorbet/rbi/gems/{activemodel@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → activemodel@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +103 -56
- data/sorbet/rbi/gems/{activerecord@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → activerecord@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +1250 -898
- data/sorbet/rbi/gems/{activestorage@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → activestorage@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +92 -120
- data/sorbet/rbi/gems/{activesupport@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → activesupport@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +292 -193
- data/sorbet/rbi/gems/{ast@2.4.1.rbi → ast@2.4.2.rbi} +2 -1
- data/sorbet/rbi/gems/{better_html@1.0.15.rbi → better_html@1.0.16.rbi} +2 -2
- data/sorbet/rbi/gems/{concurrent-ruby@1.1.6.rbi → concurrent-ruby@1.1.8.rbi} +12 -9
- data/sorbet/rbi/gems/{erubi@1.9.0.rbi → erubi@1.10.0.rbi} +3 -1
- data/sorbet/rbi/gems/{i18n@1.8.2.rbi → i18n@1.8.10.rbi} +19 -52
- data/sorbet/rbi/gems/{loofah@2.5.0.rbi → loofah@2.9.0.rbi} +3 -1
- data/sorbet/rbi/gems/marcel@1.0.0.rbi +70 -0
- data/sorbet/rbi/gems/{mini_mime@1.0.2.rbi → mini_mime@1.0.3.rbi} +6 -6
- data/sorbet/rbi/gems/{mini_portile2@2.4.0.rbi → minitest-focus@1.2.1.rbi} +2 -2
- data/sorbet/rbi/gems/{minitest@5.14.0.rbi → minitest@5.14.4.rbi} +31 -29
- data/sorbet/rbi/gems/{mocha@1.11.2.rbi → mocha@1.12.0.rbi} +25 -36
- data/sorbet/rbi/gems/{nio4r@2.5.2.rbi → nio4r@2.5.7.rbi} +21 -20
- data/sorbet/rbi/gems/{nokogiri@1.10.9.rbi → nokogiri@1.11.2.rbi} +193 -154
- data/sorbet/rbi/gems/parallel@1.20.1.rbi +117 -0
- data/sorbet/rbi/gems/parlour@6.0.0.rbi +1272 -0
- data/sorbet/rbi/gems/{parser@2.7.1.4.rbi → parser@3.0.0.0.rbi} +287 -174
- data/sorbet/rbi/gems/{pry@0.13.1.rbi → pry@0.14.0.rbi} +1 -1
- data/sorbet/rbi/gems/racc@1.5.2.rbi +57 -0
- data/sorbet/rbi/gems/{rack@2.2.2.rbi → rack@2.2.3.rbi} +23 -35
- data/sorbet/rbi/gems/{rails@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → rails@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +1 -1
- data/sorbet/rbi/gems/{railties@6.1.0.alpha-d80c18a391e33552ae2d943e68af56946f883f65.rbi → railties@7.0.0.alpha-d612542336d9a61381311c95a27d801bb4094779.rbi} +132 -121
- data/sorbet/rbi/gems/{rake@13.0.1.rbi → rake@13.0.3.rbi} +16 -20
- data/sorbet/rbi/gems/{parallel@1.19.1.rbi → regexp_parser@2.1.1.rbi} +2 -2
- data/sorbet/rbi/gems/rubocop-ast@1.4.1.rbi +8 -0
- data/sorbet/rbi/gems/{rubocop-performance@1.5.2.rbi → rubocop-performance@1.10.2.rbi} +1 -1
- data/sorbet/rbi/gems/{rubocop-shopify@1.0.2.rbi → rubocop-shopify@2.0.1.rbi} +1 -1
- data/sorbet/rbi/gems/{rubocop-sorbet@0.3.7.rbi → rubocop-sorbet@0.6.1.rbi} +1 -1
- data/sorbet/rbi/gems/{rubocop@0.82.0.rbi → rubocop@1.12.0.rbi} +1 -1
- data/sorbet/rbi/gems/{ruby-progressbar@1.10.1.rbi → ruby-progressbar@1.11.0.rbi} +1 -1
- data/sorbet/rbi/gems/spoom@1.1.0.rbi +1061 -0
- data/sorbet/rbi/gems/{spring@2.1.0.rbi → spring@2.1.1.rbi} +7 -7
- data/sorbet/rbi/gems/{sprockets-rails@3.2.1.rbi → sprockets-rails@3.2.2.rbi} +88 -68
- data/sorbet/rbi/gems/{sprockets@4.0.0.rbi → sprockets@4.0.2.rbi} +8 -7
- data/sorbet/rbi/gems/{tapioca@0.4.5.rbi → tapioca@0.4.19.rbi} +109 -24
- data/sorbet/rbi/gems/{thor@1.0.1.rbi → thor@1.1.0.rbi} +16 -15
- data/sorbet/rbi/gems/{tzinfo@2.0.2.rbi → tzinfo@2.0.4.rbi} +21 -2
- data/sorbet/rbi/gems/{unicode-display_width@1.7.0.rbi → unicode-display_width@2.0.0.rbi} +1 -1
- data/sorbet/rbi/gems/{websocket-driver@0.7.1.rbi → websocket-driver@0.7.3.rbi} +29 -29
- data/sorbet/rbi/gems/{websocket-extensions@0.1.4.rbi → websocket-extensions@0.1.5.rbi} +2 -2
- data/sorbet/rbi/gems/zeitwerk@2.4.2.rbi +177 -0
- data/sorbet/tapioca/require.rb +1 -0
- metadata +79 -66
- data/lib/packwerk/cache_deprecated_references.rb +0 -55
- data/lib/packwerk/checking_deprecated_references.rb +0 -43
- data/lib/packwerk/commands/detect_stale_violations_command.rb +0 -60
- data/lib/packwerk/commands/offense_progress_marker.rb +0 -24
- data/lib/packwerk/commands/result.rb +0 -13
- data/lib/packwerk/commands/update_deprecations_command.rb +0 -81
- data/lib/packwerk/detect_stale_deprecated_references.rb +0 -14
- data/lib/packwerk/generators/application_validation.rb +0 -62
- data/lib/packwerk/generators/templates/packwerk +0 -23
- data/lib/packwerk/generators/templates/packwerk_validator_test.rb +0 -11
- data/lib/packwerk/reference_lister.rb +0 -23
- data/lib/packwerk/spring_command.rb +0 -28
- data/lib/packwerk/updating_deprecated_references.rb +0 -14
- data/sorbet/rbi/gems/jaro_winkler@1.5.4.rbi +0 -8
- data/sorbet/rbi/gems/marcel@0.3.3.rbi +0 -30
- data/sorbet/rbi/gems/mimemagic@0.3.5.rbi +0 -47
- data/sorbet/rbi/gems/parlour@4.0.1.rbi +0 -561
- data/sorbet/rbi/gems/spoom@1.0.4.rbi +0 -418
- data/sorbet/rbi/gems/zeitwerk@2.3.0.rbi +0 -8
@@ -8,20 +8,15 @@ module Packwerk
|
|
8
8
|
class << self
|
9
9
|
extend T::Sig
|
10
10
|
|
11
|
-
sig { returns(T::Array[String]) }
|
12
|
-
def extract_relevant_paths
|
13
|
-
|
11
|
+
sig { params(root: String, environment: String).returns(T::Array[String]) }
|
12
|
+
def extract_relevant_paths(root, environment)
|
13
|
+
require_application(root, environment)
|
14
14
|
all_paths = extract_application_autoload_paths
|
15
15
|
relevant_paths = filter_relevant_paths(all_paths)
|
16
16
|
assert_load_paths_present(relevant_paths)
|
17
17
|
relative_path_strings(relevant_paths)
|
18
18
|
end
|
19
19
|
|
20
|
-
sig { void }
|
21
|
-
def assert_application_booted
|
22
|
-
raise "The application needs to be booted to extract load paths" unless defined?(::Rails)
|
23
|
-
end
|
24
|
-
|
25
20
|
sig { returns(T::Array[String]) }
|
26
21
|
def extract_application_autoload_paths
|
27
22
|
Rails.application.railties
|
@@ -54,6 +49,21 @@ module Packwerk
|
|
54
49
|
.uniq
|
55
50
|
end
|
56
51
|
|
52
|
+
private
|
53
|
+
|
54
|
+
sig { params(root: String, environment: String).void }
|
55
|
+
def require_application(root, environment)
|
56
|
+
environment_file = "#{root}/config/environment"
|
57
|
+
|
58
|
+
if File.file?("#{environment_file}.rb")
|
59
|
+
ENV["RAILS_ENV"] ||= environment
|
60
|
+
|
61
|
+
require environment_file
|
62
|
+
else
|
63
|
+
raise "A Rails application could not be found in #{root}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
57
67
|
sig { params(paths: T::Array[T.untyped]).void }
|
58
68
|
def assert_load_paths_present(paths)
|
59
69
|
if paths.empty?
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "active_support/inflector/inflections"
|
@@ -6,18 +6,14 @@ require "constant_resolver"
|
|
6
6
|
require "pathname"
|
7
7
|
require "yaml"
|
8
8
|
|
9
|
-
require "packwerk/package_set"
|
10
|
-
require "packwerk/graph"
|
11
|
-
require "packwerk/inflector"
|
12
|
-
require "packwerk/application_load_paths"
|
13
|
-
|
14
9
|
module Packwerk
|
15
10
|
class ApplicationValidator
|
16
|
-
def initialize(config_file_path:, configuration:)
|
11
|
+
def initialize(config_file_path:, configuration:, environment:)
|
17
12
|
@config_file_path = config_file_path
|
18
13
|
@configuration = configuration
|
14
|
+
@environment = environment
|
19
15
|
|
20
|
-
@application_load_paths = ApplicationLoadPaths.extract_relevant_paths
|
16
|
+
@application_load_paths = ApplicationLoadPaths.extract_relevant_paths(configuration.root_path, environment)
|
21
17
|
end
|
22
18
|
|
23
19
|
Result = Struct.new(:ok?, :error_value)
|
@@ -101,26 +97,26 @@ module Packwerk
|
|
101
97
|
|
102
98
|
if hash.key?("enforce_privacy")
|
103
99
|
unless [TrueClass, FalseClass, Array].include?(hash["enforce_privacy"].class)
|
104
|
-
errors << "Invalid 'enforce_privacy' option in #{f.inspect}: #{hash[
|
100
|
+
errors << "Invalid 'enforce_privacy' option in #{f.inspect}: #{hash["enforce_privacy"].inspect}"
|
105
101
|
end
|
106
102
|
end
|
107
103
|
|
108
104
|
if hash.key?("enforce_dependencies")
|
109
105
|
unless [TrueClass, FalseClass].include?(hash["enforce_dependencies"].class)
|
110
|
-
errors << "Invalid 'enforce_dependencies' option in #{f.inspect}: #{hash[
|
106
|
+
errors << "Invalid 'enforce_dependencies' option in #{f.inspect}: #{hash["enforce_dependencies"].inspect}"
|
111
107
|
end
|
112
108
|
end
|
113
109
|
|
114
110
|
if hash.key?("public_path")
|
115
111
|
unless hash["public_path"].is_a?(String)
|
116
|
-
errors << "'public_path' option must be a string in #{f.inspect}: #{hash[
|
112
|
+
errors << "'public_path' option must be a string in #{f.inspect}: #{hash["public_path"].inspect}"
|
117
113
|
end
|
118
114
|
end
|
119
115
|
|
120
116
|
next unless hash.key?("dependencies")
|
121
117
|
next if hash["dependencies"].is_a?(Array)
|
122
118
|
|
123
|
-
errors << "Invalid 'dependencies' option in #{f.inspect}: #{hash[
|
119
|
+
errors << "Invalid 'dependencies' option in #{f.inspect}: #{hash["dependencies"].inspect}"
|
124
120
|
end
|
125
121
|
|
126
122
|
if errors.empty?
|
@@ -181,21 +177,9 @@ module Packwerk
|
|
181
177
|
edges = package_set.flat_map do |package|
|
182
178
|
package.dependencies.map { |dependency| [package, package_set.fetch(dependency)] }
|
183
179
|
end
|
184
|
-
dependency_graph = Packwerk::Graph.new(*edges)
|
185
|
-
|
186
|
-
|
187
|
-
#
|
188
|
-
# [a, b, c]
|
189
|
-
#
|
190
|
-
# to the string
|
191
|
-
#
|
192
|
-
# a -> b -> c -> a
|
193
|
-
#
|
194
|
-
cycle_strings = dependency_graph.cycles.map do |cycle|
|
195
|
-
cycle_strings = cycle.map(&:to_s)
|
196
|
-
cycle_strings << cycle.first.to_s
|
197
|
-
"\t- #{cycle_strings.join(' → ')}"
|
198
|
-
end
|
180
|
+
dependency_graph = Packwerk::Graph.new(*T.unsafe(edges))
|
181
|
+
|
182
|
+
cycle_strings = build_cycle_strings(dependency_graph.cycles)
|
199
183
|
|
200
184
|
if dependency_graph.acyclic?
|
201
185
|
Result.new(true)
|
@@ -284,6 +268,21 @@ module Packwerk
|
|
284
268
|
|
285
269
|
private
|
286
270
|
|
271
|
+
# Convert the cycles:
|
272
|
+
#
|
273
|
+
# [[a, b, c], [b, c]]
|
274
|
+
#
|
275
|
+
# to the string:
|
276
|
+
#
|
277
|
+
# ["a -> b -> c -> a", "b -> c -> b"]
|
278
|
+
def build_cycle_strings(cycles)
|
279
|
+
cycles.map do |cycle|
|
280
|
+
cycle_strings = cycle.map(&:to_s)
|
281
|
+
cycle_strings << cycle.first.to_s
|
282
|
+
"\t- #{cycle_strings.join(" → ")}"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
287
286
|
def package_manifests_settings_for(setting)
|
288
287
|
package_manifests.map { |f| [f, (YAML.load_file(File.join(f)) || {})[setting]] }
|
289
288
|
end
|
data/lib/packwerk/checker.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "sorbet-runtime"
|
5
|
-
require "packwerk/reference_lister"
|
6
|
-
|
7
4
|
module Packwerk
|
8
5
|
module Checker
|
9
6
|
extend T::Sig
|
@@ -14,10 +11,7 @@ module Packwerk
|
|
14
11
|
sig { returns(ViolationType).abstract }
|
15
12
|
def violation_type; end
|
16
13
|
|
17
|
-
sig { params(reference: Reference
|
18
|
-
def invalid_reference?(reference
|
19
|
-
|
20
|
-
sig { params(reference: Reference).returns(String).abstract }
|
21
|
-
def message_for(reference); end
|
14
|
+
sig { params(reference: Reference).returns(T::Boolean).abstract }
|
15
|
+
def invalid_reference?(reference); end
|
22
16
|
end
|
23
17
|
end
|
data/lib/packwerk/cli.rb
CHANGED
@@ -1,48 +1,35 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
|
-
require "benchmark"
|
4
|
-
require "sorbet-runtime"
|
5
|
-
|
6
|
-
require "packwerk/application_load_paths"
|
7
|
-
require "packwerk/application_validator"
|
8
|
-
require "packwerk/configuration"
|
9
|
-
require "packwerk/files_for_processing"
|
10
|
-
require "packwerk/formatters/offenses_formatter"
|
11
|
-
require "packwerk/formatters/progress_formatter"
|
12
|
-
require "packwerk/inflector"
|
13
|
-
require "packwerk/output_style"
|
14
|
-
require "packwerk/output_styles/plain"
|
15
|
-
require "packwerk/run_context"
|
16
|
-
require "packwerk/updating_deprecated_references"
|
17
|
-
require "packwerk/checking_deprecated_references"
|
18
|
-
require "packwerk/commands/detect_stale_violations_command"
|
19
|
-
require "packwerk/commands/update_deprecations_command"
|
20
|
-
require "packwerk/commands/offense_progress_marker"
|
21
3
|
|
22
4
|
module Packwerk
|
23
5
|
class Cli
|
24
6
|
extend T::Sig
|
25
|
-
include OffenseProgressMarker
|
26
7
|
|
27
8
|
sig do
|
28
9
|
params(
|
29
|
-
run_context: T.nilable(Packwerk::RunContext),
|
30
10
|
configuration: T.nilable(Configuration),
|
31
11
|
out: T.any(StringIO, IO),
|
32
12
|
err_out: T.any(StringIO, IO),
|
33
|
-
|
13
|
+
environment: String,
|
14
|
+
style: Packwerk::OutputStyle,
|
15
|
+
offenses_formatter: T.nilable(Packwerk::OffensesFormatter)
|
34
16
|
).void
|
35
17
|
end
|
36
|
-
def initialize(
|
18
|
+
def initialize(
|
19
|
+
configuration: nil,
|
20
|
+
out: $stdout,
|
21
|
+
err_out: $stderr,
|
22
|
+
environment: "test",
|
23
|
+
style: OutputStyles::Plain.new,
|
24
|
+
offenses_formatter: nil
|
25
|
+
)
|
37
26
|
@out = out
|
38
27
|
@err_out = err_out
|
28
|
+
@environment = environment
|
39
29
|
@style = style
|
40
30
|
@configuration = configuration || Configuration.from_path
|
41
|
-
@run_context = run_context || Packwerk::RunContext.from_configuration(
|
42
|
-
@configuration,
|
43
|
-
reference_lister: ::Packwerk::CheckingDeprecatedReferences.new(@configuration.root_path),
|
44
|
-
)
|
45
31
|
@progress_formatter = Formatters::ProgressFormatter.new(@out, style: style)
|
32
|
+
@offenses_formatter = offenses_formatter || Formatters::OffensesFormatter.new(style: @style)
|
46
33
|
end
|
47
34
|
|
48
35
|
sig { params(args: T::Array[String]).returns(T.noreturn) }
|
@@ -60,13 +47,13 @@ module Packwerk
|
|
60
47
|
when "generate_configs"
|
61
48
|
generate_configs
|
62
49
|
when "check"
|
63
|
-
|
50
|
+
output_result(parse_run(args).check)
|
64
51
|
when "detect-stale-violations"
|
65
|
-
|
52
|
+
output_result(parse_run(args).detect_stale_violations)
|
66
53
|
when "update"
|
67
54
|
update(args)
|
68
55
|
when "update-deprecations"
|
69
|
-
|
56
|
+
output_result(parse_run(args).update_deprecations)
|
70
57
|
when "validate"
|
71
58
|
validate(args)
|
72
59
|
when nil, "help"
|
@@ -93,28 +80,12 @@ module Packwerk
|
|
93
80
|
def init
|
94
81
|
@out.puts("📦 Initializing Packwerk...")
|
95
82
|
|
96
|
-
|
97
|
-
for_rails_app: rails_app?,
|
98
|
-
root: @configuration.root_path,
|
99
|
-
out: @out
|
100
|
-
)
|
101
|
-
|
102
|
-
if application_validation
|
103
|
-
if rails_app?
|
104
|
-
# To run in the same space as the Rails process,
|
105
|
-
# in order to fetch load paths for the configuration generator
|
106
|
-
exec("bin/packwerk", "generate_configs")
|
107
|
-
else
|
108
|
-
generate_configurations = generate_configs
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
application_validation && generate_configurations
|
83
|
+
generate_configs
|
113
84
|
end
|
114
85
|
|
115
86
|
def generate_configs
|
116
87
|
configuration_file = Packwerk::Generators::ConfigurationFile.generate(
|
117
|
-
load_paths: Packwerk::ApplicationLoadPaths.extract_relevant_paths,
|
88
|
+
load_paths: Packwerk::ApplicationLoadPaths.extract_relevant_paths(@configuration.root_path, @environment),
|
118
89
|
root: @configuration.root_path,
|
119
90
|
out: @out
|
120
91
|
)
|
@@ -143,54 +114,10 @@ module Packwerk
|
|
143
114
|
|
144
115
|
def update(paths)
|
145
116
|
warn("`packwerk update` is deprecated in favor of `packwerk update-deprecations`.")
|
146
|
-
|
117
|
+
output_result(parse_run(paths).update_deprecations)
|
147
118
|
end
|
148
119
|
|
149
|
-
def
|
150
|
-
update_deprecations = Commands::UpdateDeprecationsCommand.new(
|
151
|
-
files: fetch_files_to_process(paths),
|
152
|
-
configuration: @configuration,
|
153
|
-
offenses_formatter: offenses_formatter,
|
154
|
-
progress_formatter: @progress_formatter
|
155
|
-
)
|
156
|
-
result = update_deprecations.run
|
157
|
-
@out.puts
|
158
|
-
@out.puts(result.message)
|
159
|
-
result.status
|
160
|
-
end
|
161
|
-
|
162
|
-
def check(paths)
|
163
|
-
files = fetch_files_to_process(paths)
|
164
|
-
|
165
|
-
@progress_formatter.started(files)
|
166
|
-
|
167
|
-
all_offenses = T.let([], T.untyped)
|
168
|
-
execution_time = Benchmark.realtime do
|
169
|
-
files.each do |path|
|
170
|
-
@run_context.process_file(file: path).tap do |offenses|
|
171
|
-
mark_progress(offenses: offenses, progress_formatter: @progress_formatter)
|
172
|
-
all_offenses.concat(offenses)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
rescue Interrupt
|
176
|
-
@out.puts
|
177
|
-
@out.puts("Manually interrupted. Violations caught so far are listed below:")
|
178
|
-
end
|
179
|
-
|
180
|
-
@progress_formatter.finished(execution_time)
|
181
|
-
@out.puts
|
182
|
-
@out.puts(offenses_formatter.show_offenses(all_offenses))
|
183
|
-
|
184
|
-
all_offenses.empty?
|
185
|
-
end
|
186
|
-
|
187
|
-
def detect_stale_violations(paths)
|
188
|
-
detect_stale_violations = Commands::DetectStaleViolationsCommand.new(
|
189
|
-
files: fetch_files_to_process(paths),
|
190
|
-
configuration: @configuration,
|
191
|
-
progress_formatter: @progress_formatter
|
192
|
-
)
|
193
|
-
result = detect_stale_violations.run
|
120
|
+
def output_result(result)
|
194
121
|
@out.puts
|
195
122
|
@out.puts(result.message)
|
196
123
|
result.status
|
@@ -204,14 +131,11 @@ module Packwerk
|
|
204
131
|
end
|
205
132
|
|
206
133
|
def validate(_paths)
|
207
|
-
warn("`packwerk validate` should be run within the application. "\
|
208
|
-
"Generate the bin script using `packwerk init` and"\
|
209
|
-
" use `bin/packwerk validate` instead.") unless defined?(::Rails)
|
210
|
-
|
211
134
|
@progress_formatter.started_validation do
|
212
135
|
checker = Packwerk::ApplicationValidator.new(
|
213
136
|
config_file_path: @configuration.config_path,
|
214
|
-
configuration: @configuration
|
137
|
+
configuration: @configuration,
|
138
|
+
environment: @environment,
|
215
139
|
)
|
216
140
|
result = checker.check_all
|
217
141
|
|
@@ -231,17 +155,13 @@ module Packwerk
|
|
231
155
|
end
|
232
156
|
end
|
233
157
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
def offenses_formatter
|
244
|
-
@offenses_formatter ||= Formatters::OffensesFormatter.new(style: @style)
|
158
|
+
def parse_run(paths)
|
159
|
+
ParseRun.new(
|
160
|
+
files: fetch_files_to_process(paths),
|
161
|
+
configuration: @configuration,
|
162
|
+
progress_formatter: @progress_formatter,
|
163
|
+
offenses_formatter: @offenses_formatter
|
164
|
+
)
|
245
165
|
end
|
246
166
|
end
|
247
167
|
end
|
@@ -47,8 +47,13 @@ module Packwerk
|
|
47
47
|
@custom_associations = configs["custom_associations"] || []
|
48
48
|
@load_paths = configs["load_paths"] || []
|
49
49
|
@inflections_file = File.expand_path(configs["inflections_file"] || "config/inflections.yml", @root_path)
|
50
|
+
@parallel = configs.key?("parallel") ? configs["parallel"] : true
|
50
51
|
|
51
52
|
@config_path = config_path
|
52
53
|
end
|
54
|
+
|
55
|
+
def parallel?
|
56
|
+
@parallel
|
57
|
+
end
|
53
58
|
end
|
54
59
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require "constant_resolver"
|
5
|
+
|
4
6
|
module Packwerk
|
5
7
|
# Get information about (partially qualified) constants without loading the application code.
|
6
8
|
# Information gathered: Fully qualified name, path to file containing the definition, package,
|
@@ -1,9 +1,6 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "packwerk/violation_type"
|
5
|
-
require "packwerk/checker"
|
6
|
-
|
7
4
|
module Packwerk
|
8
5
|
class DependencyChecker
|
9
6
|
extend T::Sig
|
@@ -16,24 +13,14 @@ module Packwerk
|
|
16
13
|
|
17
14
|
sig do
|
18
15
|
override
|
19
|
-
.params(reference: Packwerk::Reference
|
16
|
+
.params(reference: Packwerk::Reference)
|
20
17
|
.returns(T::Boolean)
|
21
18
|
end
|
22
|
-
def invalid_reference?(reference
|
19
|
+
def invalid_reference?(reference)
|
23
20
|
return false unless reference.source_package
|
24
21
|
return false unless reference.source_package.enforce_dependencies?
|
25
22
|
return false if reference.source_package.dependency?(reference.constant.package)
|
26
|
-
return false if reference_lister.listed?(reference, violation_type: violation_type)
|
27
23
|
true
|
28
24
|
end
|
29
|
-
|
30
|
-
sig { override.params(reference: Packwerk::Reference).returns(String) }
|
31
|
-
def message_for(reference)
|
32
|
-
"Dependency violation: #{reference.constant.name} belongs to '#{reference.constant.package}', but " \
|
33
|
-
"'#{reference.source_package}' does not specify a dependency on " \
|
34
|
-
"'#{reference.constant.package}'.\n" \
|
35
|
-
"Are we missing an abstraction?\n" \
|
36
|
-
"Is the code making the reference, and the referenced constant, in the right packages?\n"
|
37
|
-
end
|
38
25
|
end
|
39
26
|
end
|