packwerk-extensions 0.0.6 → 0.0.8

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: 3f20892b9d7d67a2164c7c632ac760c66859cacd2fa7af97c71a220a1d317893
4
- data.tar.gz: a9a7f631ed8e6398a48e91fddc83fcff0e1d923aa16b75231e0a3296c5c4aa4a
3
+ metadata.gz: 661762b44e28e84ff3b70007bc039b6f767ddf638524f5a069a832e1f0d2fb34
4
+ data.tar.gz: a229b9432f95c10b211a411fee200e48721ff8d3c6b3fd1b745f8211cf58038a
5
5
  SHA512:
6
- metadata.gz: f66866b77e2727898fa951a05f716f8b959444553082f9c8999144013ee74d90820ee802a994b11887c3132799b47cbcc74a60cc6434a6172617ebb916748216
7
- data.tar.gz: b6deec3d175813666076ce5797d29cc62df65ec233c552114cdf3492c92dd74791b53412201a8b3e56758fdb4bb9a6c7bed804225c99c192d92f9566a60a4a85
6
+ metadata.gz: 32e5084af7d8e7cba4b743d0be13d29c1ea05b0c6e00ab7d0b9a38a229545093cf21f9e18da883987e487588f5bb7a47cc8728912332c9f295a42b03432bafc3
7
+ data.tar.gz: 01ff189cc3e645da3eeab3176351ebc0d23d274a9d20269f32733cdb2771169f365857bc946a66e5982c447887f81817fee047b82709e34115f18abaa53a0479
@@ -41,8 +41,8 @@ module Packwerk
41
41
  .returns(T::Boolean)
42
42
  end
43
43
  def invalid_reference?(reference)
44
- constant_package = Package.from(reference.constant.package)
45
- referencing_package = Package.from(reference.package)
44
+ constant_package = Package.from(reference.constant.package, layers)
45
+ referencing_package = Package.from(reference.package, layers)
46
46
  !referencing_package.can_depend_on?(constant_package, layers: layers)
47
47
  end
48
48
 
@@ -62,8 +62,8 @@ module Packwerk
62
62
  .returns(String)
63
63
  end
64
64
  def message(reference)
65
- constant_package = Package.from(reference.constant.package)
66
- referencing_package = Package.from(reference.package)
65
+ constant_package = Package.from(reference.constant.package, layers)
66
+ referencing_package = Package.from(reference.package, layers)
67
67
 
68
68
  message = <<~MESSAGE
69
69
  Architecture layer violation: '#{reference.constant.name}' belongs to '#{reference.constant.package}', whose architecture layer type is "#{constant_package.layer}."
@@ -8,12 +8,13 @@ module Packwerk
8
8
 
9
9
  sig { void }
10
10
  def initialize
11
- @names = T.let(@names, T.nilable(T::Array[String]))
11
+ @names = T.let(@names, T.nilable(T::Set[String]))
12
+ @names_list = T.let(@names_list, T.nilable(T::Array[String]))
12
13
  end
13
14
 
14
15
  sig { params(layer: String).returns(Integer) }
15
16
  def index_of(layer)
16
- index = names.reverse.find_index(layer)
17
+ index = names_list.reverse.find_index(layer)
17
18
  if index.nil?
18
19
  raise "Layer #{layer} not find, please run `bin/packwerk validate`"
19
20
  end
@@ -21,9 +22,16 @@ module Packwerk
21
22
  index
22
23
  end
23
24
 
24
- sig { returns(T::Array[String]) }
25
+ sig { returns(T::Set[String]) }
25
26
  def names
26
- @names ||= YAML.load_file('packwerk.yml')['architecture_layers'] || []
27
+ @names ||= Set.new(names_list)
28
+ end
29
+
30
+ private
31
+
32
+ sig { returns(T::Array[String]) }
33
+ def names_list
34
+ @names_list ||= YAML.load_file('packwerk.yml')['architecture_layers'] || []
27
35
  end
28
36
  end
29
37
  end
@@ -30,15 +30,20 @@ module Packwerk
30
30
  class << self
31
31
  extend T::Sig
32
32
 
33
- sig { params(package: ::Packwerk::Package).returns(Package) }
34
- def from(package)
35
- from_config(package.config)
36
- end
33
+ sig { params(package: ::Packwerk::Package, layers: Layers).returns(Package) }
34
+ def from(package, layers)
35
+ config = package.config
36
+
37
+ # This allows the layer to be inferred based on the package root
38
+ package_root = package.name.split('/').first
39
+ if package_root && layers.names.include?(package_root)
40
+ layer = package_root
41
+ else
42
+ layer = config['layer']
43
+ end
37
44
 
38
- sig { params(config: T::Hash[T.untyped, T.untyped]).returns(Package) }
39
- def from_config(config)
40
45
  Package.new(
41
- layer: config['layer'],
46
+ layer: layer,
42
47
  enforcement_setting: config['enforce_architecture'],
43
48
  config: config
44
49
  )
@@ -13,19 +13,21 @@ module Packwerk
13
13
  def call(package_set, configuration)
14
14
  results = T.let([], T::Array[Result])
15
15
 
16
- package_manifests(configuration).each do |f|
17
- config = YAML.load_file(File.join(f))
16
+ package_set.each do |package|
17
+ config = package.config
18
+ f = Pathname.new(package.name).join('package.yml').to_s
18
19
  next if !config
19
20
 
20
21
  result = check_enforce_architecture_setting(f, config['enforce_architecture'])
21
22
  results << result
22
23
  next if !result.ok?
23
24
 
24
- result = check_layer_setting(config, f, config['layer'])
25
+ package = Package.from(package, layers)
26
+
27
+ result = check_layer_setting(package, f)
25
28
  results << result
26
29
  next if !result.ok?
27
30
 
28
- package = Package.from_config(config)
29
31
  results += check_dependencies_setting(package_set, package, f)
30
32
  end
31
33
 
@@ -51,7 +53,7 @@ module Packwerk
51
53
  other_packwerk_package = package_set.fetch(dependency)
52
54
  next if other_packwerk_package.nil?
53
55
 
54
- other_package = Package.from(other_packwerk_package)
56
+ other_package = Package.from(other_packwerk_package, layers)
55
57
  next if package.can_depend_on?(other_package, layers: layers)
56
58
 
57
59
  results << Result.new(
@@ -64,24 +66,23 @@ module Packwerk
64
66
  end
65
67
 
66
68
  sig do
67
- params(config: T::Hash[T.untyped, T.untyped], config_file_path: String, layer: T.untyped).returns(Result)
69
+ params(package: Package, config_file_path: String).returns(Result)
68
70
  end
69
- def check_layer_setting(config, config_file_path, layer)
70
- enforce_architecture = config['enforce_architecture']
71
- enforce_architecture_enabled = !(enforce_architecture.nil? || enforce_architecture == false)
71
+ def check_layer_setting(package, config_file_path)
72
+ layer = package.layer
72
73
  valid_layer = layer.nil? || layers.names.include?(layer)
73
74
 
74
- if layer.nil? && enforce_architecture_enabled
75
+ if layer.nil? && package.enforces?
75
76
  Result.new(
76
77
  ok: false,
77
- error_value: "Invalid 'layer' option in #{config_file_path.inspect}: #{layer.inspect}. `layer` must be set if `enforce_architecture` is on."
78
+ error_value: "Invalid 'layer' option in #{config_file_path.inspect}: #{package.layer.inspect}. `layer` must be set if `enforce_architecture` is on."
78
79
  )
79
80
  elsif valid_layer
80
81
  Result.new(ok: true)
81
82
  else
82
83
  Result.new(
83
84
  ok: false,
84
- error_value: "Invalid 'layer' option in #{config_file_path.inspect}: #{layer.inspect}. Must be one of #{layers.names.inspect}"
85
+ error_value: "Invalid 'layer' option in #{config_file_path.inspect}: #{layer.inspect}. Must be one of #{layers.names.to_a.inspect}"
85
86
  )
86
87
  end
87
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packwerk-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
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-12-21 00:00:00.000000000 Z
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: packwerk