packwerk 3.2.1 → 3.2.2

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: f8766d43b92fcc7bedad92604cde48e11433afdf474b21515f363b595c7fae23
4
- data.tar.gz: 0d386a1d690b6c07d41a6d63b0907f38d57fffd87d2ab370ee580cbcd0826a17
3
+ metadata.gz: 9172cfed0b1190af4ece801d73138cdaba7cd9aaad8fdb90537b2d6a03d597bb
4
+ data.tar.gz: 946267b723dff18a00a2948d4f9d5c8766018ae815b50fa542ba450bdc29c718
5
5
  SHA512:
6
- metadata.gz: a64ccf65829b48691341b0abc09013213bd266ca9d2ec7a37fa1735856ae6b707d904ad75012c91bcd5a6d3ec4991ed6d7f1545140232d34f6d27452f5ac5a27
7
- data.tar.gz: f231695cf34fc0fb109d70efcff6874d5268b70c4af80688813734448f5c3d1ee3a705dbe3ece0bbb156733585f581f941917ed43f1666bb58f9617932858e18
6
+ metadata.gz: a7ec7b0f03a55f713b24d9aec7e6cadfb7138087685ee698f7a35c64209638168d91ee7de44a174543271b4252173007d64a16b0bd5f00348dd0554a76c34bb1
7
+ data.tar.gz: ccc7785fcef8f061923c72f122dbf7f7c9ebab1e7c4cc9d2e6c2a8a643ac0da8f7594c17c2823b2bcc7845dd255d886a6b85eabe0ce68176a8b1ff57097c7278
@@ -19,19 +19,27 @@ module Packwerk
19
19
  CustomAssociations
20
20
  )
21
21
 
22
- sig { params(inflector: T.class_of(ActiveSupport::Inflector), custom_associations: CustomAssociations).void }
23
- def initialize(inflector:, custom_associations: Set.new)
22
+ sig do
23
+ params(
24
+ inflector: T.class_of(ActiveSupport::Inflector),
25
+ custom_associations: CustomAssociations,
26
+ excluded_files: T::Set[String]
27
+ ).void
28
+ end
29
+ def initialize(inflector:, custom_associations: Set.new, excluded_files: Set.new)
24
30
  @inflector = inflector
25
31
  @associations = T.let(RAILS_ASSOCIATIONS + custom_associations, CustomAssociations)
32
+ @excluded_files = T.let(excluded_files, T::Set[String])
26
33
  end
27
34
 
28
35
  sig do
29
36
  override
30
- .params(node: AST::Node, ancestors: T::Array[AST::Node])
37
+ .params(node: AST::Node, ancestors: T::Array[AST::Node], relative_file: String)
31
38
  .returns(T.nilable(String))
32
39
  end
33
- def constant_name_from_node(node, ancestors:)
40
+ def constant_name_from_node(node, ancestors:, relative_file:)
34
41
  return unless NodeHelpers.method_call?(node)
42
+ return if excluded?(relative_file)
35
43
  return unless association?(node)
36
44
 
37
45
  arguments = NodeHelpers.method_arguments(node)
@@ -48,6 +56,11 @@ module Packwerk
48
56
 
49
57
  private
50
58
 
59
+ sig { params(relative_file: String).returns(T::Boolean) }
60
+ def excluded?(relative_file)
61
+ @excluded_files.include?(relative_file)
62
+ end
63
+
51
64
  sig { params(node: AST::Node).returns(T::Boolean) }
52
65
  def association?(node)
53
66
  method_name = NodeHelpers.method_name(node)
@@ -54,6 +54,9 @@ module Packwerk
54
54
  sig { returns(T::Array[Symbol]) }
55
55
  attr_reader(:custom_associations)
56
56
 
57
+ sig { returns(T::Array[String]) }
58
+ attr_reader(:associations_exclude)
59
+
57
60
  sig { returns(T.nilable(String)) }
58
61
  attr_reader(:config_path)
59
62
 
@@ -76,6 +79,7 @@ module Packwerk
76
79
  @root_path = T.let(File.expand_path(root), String)
77
80
  @package_paths = T.let(configs["package_paths"] || "**/", T.any(String, T::Array[String]))
78
81
  @custom_associations = T.let((configs["custom_associations"] || []).map(&:to_sym), T::Array[Symbol])
82
+ @associations_exclude = T.let(configs["associations_exclude"] || [], T::Array[String])
79
83
  @parallel = T.let(configs.key?("parallel") ? configs["parallel"] : true, T::Boolean)
80
84
  @cache_enabled = T.let(configs.key?("cache") ? configs["cache"] : false, T::Boolean)
81
85
  @cache_directory = T.let(Pathname.new(configs["cache_directory"] || "tmp/cache/packwerk"), Pathname)
@@ -9,10 +9,10 @@ module Packwerk
9
9
 
10
10
  sig do
11
11
  override
12
- .params(node: AST::Node, ancestors: T::Array[AST::Node])
12
+ .params(node: AST::Node, ancestors: T::Array[AST::Node], relative_file: String)
13
13
  .returns(T.nilable(String))
14
14
  end
15
- def constant_name_from_node(node, ancestors:)
15
+ def constant_name_from_node(node, ancestors:, relative_file:)
16
16
  return nil unless NodeHelpers.constant?(node)
17
17
 
18
18
  parent = ancestors.first
@@ -13,10 +13,10 @@ module Packwerk
13
13
 
14
14
  sig do
15
15
  abstract
16
- .params(node: ::AST::Node, ancestors: T::Array[::AST::Node])
16
+ .params(node: ::AST::Node, ancestors: T::Array[::AST::Node], relative_file: String)
17
17
  .returns(T.nilable(String))
18
18
  end
19
- def constant_name_from_node(node, ancestors:); end
19
+ def constant_name_from_node(node, ancestors:, relative_file:); end
20
20
  end
21
21
 
22
22
  private_constant :ConstantNameInspector
@@ -42,7 +42,7 @@ module Packwerk
42
42
  def package_path?(path)
43
43
  return true if root?
44
44
 
45
- path.start_with?(@name)
45
+ path.start_with?(@name + "/")
46
46
  end
47
47
 
48
48
  sig { params(other: T.untyped).returns(T.nilable(Integer)) }
@@ -80,7 +80,12 @@ module Packwerk
80
80
  constant_name = T.let(nil, T.nilable(String))
81
81
 
82
82
  @constant_name_inspectors.each do |inspector|
83
- constant_name = inspector.constant_name_from_node(node, ancestors: ancestors)
83
+ constant_name = inspect_node(
84
+ inspector,
85
+ node: node,
86
+ ancestors: ancestors,
87
+ relative_file: relative_file
88
+ )
84
89
 
85
90
  break if constant_name
86
91
  end
@@ -97,6 +102,29 @@ module Packwerk
97
102
 
98
103
  private
99
104
 
105
+ sig do
106
+ params(
107
+ inspector: ConstantNameInspector,
108
+ node: Parser::AST::Node,
109
+ ancestors: T::Array[Parser::AST::Node],
110
+ relative_file: String
111
+ ).returns(T.nilable(String))
112
+ end
113
+ def inspect_node(inspector, node:, ancestors:, relative_file:)
114
+ inspector.constant_name_from_node(node, ancestors: ancestors, relative_file: relative_file)
115
+ rescue ArgumentError => error
116
+ if error.message == "unknown keyword: :relative_file"
117
+ T.unsafe(inspector).constant_name_from_node(node, ancestors: ancestors).tap do
118
+ warn(<<~MSG.squish)
119
+ #{T.cast(inspector, Object).class}#reference_from_node without a relative_file: keyword
120
+ argument is deprecated and will be required in Packwerk 3.1.1.
121
+ MSG
122
+ end
123
+ else
124
+ raise
125
+ end
126
+ end
127
+
100
128
  sig do
101
129
  params(
102
130
  constant_name: String,
@@ -15,14 +15,13 @@ module Packwerk
15
15
  params(configuration: Configuration).returns(RunContext)
16
16
  end
17
17
  def from_configuration(configuration)
18
- inflector = ActiveSupport::Inflector
19
-
20
18
  new(
21
19
  root_path: configuration.root_path,
22
20
  load_paths: configuration.load_paths,
23
21
  package_paths: configuration.package_paths,
24
- inflector: inflector,
22
+ inflector: ActiveSupport::Inflector,
25
23
  custom_associations: configuration.custom_associations,
24
+ associations_exclude: configuration.associations_exclude,
26
25
  cache_enabled: configuration.cache_enabled?,
27
26
  cache_directory: configuration.cache_directory,
28
27
  config_path: configuration.config_path,
@@ -39,6 +38,7 @@ module Packwerk
39
38
  config_path: T.nilable(String),
40
39
  package_paths: T.nilable(T.any(T::Array[String], String)),
41
40
  custom_associations: AssociationInspector::CustomAssociations,
41
+ associations_exclude: T::Array[String],
42
42
  checkers: T::Array[Checker],
43
43
  cache_enabled: T::Boolean,
44
44
  ).void
@@ -51,6 +51,7 @@ module Packwerk
51
51
  config_path: nil,
52
52
  package_paths: nil,
53
53
  custom_associations: [],
54
+ associations_exclude: [],
54
55
  checkers: Checker.all,
55
56
  cache_enabled: false
56
57
  )
@@ -59,6 +60,7 @@ module Packwerk
59
60
  @package_paths = package_paths
60
61
  @inflector = inflector
61
62
  @custom_associations = custom_associations
63
+ @associations_exclude = associations_exclude
62
64
  @checkers = checkers
63
65
  @cache_enabled = cache_enabled
64
66
  @cache_directory = cache_directory
@@ -128,9 +130,18 @@ module Packwerk
128
130
  def constant_name_inspectors
129
131
  [
130
132
  ConstNodeInspector.new,
131
- AssociationInspector.new(inflector: @inflector, custom_associations: @custom_associations),
133
+ AssociationInspector.new(
134
+ inflector: @inflector,
135
+ custom_associations: @custom_associations,
136
+ excluded_files: relative_files_for_globs(@associations_exclude),
137
+ ),
132
138
  ]
133
139
  end
140
+
141
+ sig { params(relative_globs: T::Array[String]).returns(FilesForProcessing::RelativeFileSet) }
142
+ def relative_files_for_globs(relative_globs)
143
+ Set.new(relative_globs.flat_map { |glob| Dir[glob] })
144
+ end
134
145
  end
135
146
 
136
147
  private_constant :RunContext
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Packwerk
5
- VERSION = "3.2.1"
5
+ VERSION = "3.2.2"
6
6
  end
data/lib/packwerk.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  require "sorbet-runtime"
5
5
  require "active_support"
6
6
  require "fileutils"
7
+ require "stringio"
7
8
 
8
9
  # Provides String#pluralize
9
10
  require "active_support/core_ext/string"
data/sorbet/config CHANGED
@@ -1,3 +1,4 @@
1
1
  --dir
2
2
  .
3
3
  --enable-experimental-requires-ancestor
4
+ --ignore=/vendor/bundle
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: 3.2.1
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-02 00:00:00.000000000 Z
11
+ date: 2024-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: railties
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
153
  description: |
168
154
  Sets package level boundaries between a specified set of ruby
169
155
  constants to minimize cross-boundary referencing and dependency.
@@ -314,7 +300,7 @@ metadata:
314
300
  source_code_uri: https://github.com/Shopify/packwerk
315
301
  changelog_uri: https://github.com/Shopify/packwerk/releases
316
302
  allowed_push_host: https://rubygems.org
317
- post_install_message:
303
+ post_install_message:
318
304
  rdoc_options: []
319
305
  require_paths:
320
306
  - lib
@@ -322,15 +308,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
322
308
  requirements:
323
309
  - - ">="
324
310
  - !ruby/object:Gem::Version
325
- version: '2.7'
311
+ version: '3.1'
326
312
  required_rubygems_version: !ruby/object:Gem::Requirement
327
313
  requirements:
328
314
  - - ">="
329
315
  - !ruby/object:Gem::Version
330
316
  version: '0'
331
317
  requirements: []
332
- rubygems_version: 3.5.9
333
- signing_key:
318
+ rubygems_version: 3.5.23
319
+ signing_key:
334
320
  specification_version: 4
335
321
  summary: Packages for applications based on the zeitwerk autoloader
336
322
  test_files: []