parse_packwerk 0.19.2 → 0.20.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: 83b58f930302d8a8c665a0308ab701ead4df9c44746dd5beda267e1c3ee7f8f8
4
- data.tar.gz: 2151555e3ff73a42c1945cfcb08528ce312479129b4d19602d2e8c90523f58c6
3
+ metadata.gz: 54e72896efeae11785e34d5c4445255a7418499095d6f8f10443047437e49ad4
4
+ data.tar.gz: e722da109f4ef007f2b017d2fdbc4aba4cc6b09d94d8efb031cb7f4f7a1dae40
5
5
  SHA512:
6
- metadata.gz: 6c1750166fa4c3e6676b295a3e31de05bcac13647b3cbcdfd90501124db728047723d9eb6fe44c65a1a338503d5219129fc6c2c849a24bbe6538821baaecdcc4
7
- data.tar.gz: 2935097a35a353f7a57e4a7e09c27f337967a28cf6d9b06d4c5a21abdd5b7e8274724370a1e79ce965d9626d73104067a8f585aa0892874f88e9ac1ad66c8646
6
+ metadata.gz: 993a09365ac56439efba8c66c0892275a184969be156e9b33cd7e8d218ab00222f55f7488d888348bb73805b91b7b3a223d46e58236695c567628a175fbe4508
7
+ data.tar.gz: 7d7b919458f16a8c53038405a3e777552a92e1660a23312a288d4b0653ba59648314fd861be63b4c27f89b50975cb4bf24756538e40cadfbe803e5160c72f5d2
@@ -7,6 +7,7 @@ module ParsePackwerk
7
7
  const :exclude, T::Array[String]
8
8
  const :package_paths, T::Array[String]
9
9
  const :requires, T::Array[String]
10
+ const :raw, T::Hash[String, T.untyped]
10
11
 
11
12
  sig { returns(Configuration) }
12
13
  def self.fetch
@@ -22,7 +23,8 @@ module ParsePackwerk
22
23
  Configuration.new(
23
24
  exclude: excludes(raw_packwerk_config),
24
25
  package_paths: package_paths(raw_packwerk_config),
25
- requires: raw_packwerk_config['require'] || []
26
+ requires: raw_packwerk_config['require'] || [],
27
+ raw: raw_packwerk_config
26
28
  )
27
29
  end
28
30
 
@@ -11,6 +11,7 @@ module ParsePackwerk
11
11
  const :metadata, MetadataYmlType
12
12
  const :dependencies, T::Array[String]
13
13
  const :config, T::Hash[T.untyped, T.untyped]
14
+ const :violations, T.nilable(T::Array[Violation])
14
15
 
15
16
  sig { params(pathname: Pathname).returns(Package) }
16
17
  def self.from(pathname)
@@ -29,9 +30,15 @@ module ParsePackwerk
29
30
  metadata: package_loaded_yml[METADATA] || {},
30
31
  dependencies: package_loaded_yml[DEPENDENCIES] || [],
31
32
  config: package_loaded_yml,
33
+ violations: PackageTodo.from(PackageTodo.yml(directory(package_name))).violations
32
34
  )
33
35
  end
34
36
 
37
+ sig { params(package_name: String).returns(::Pathname) }
38
+ def self.directory(package_name)
39
+ Pathname.new(package_name).cleanpath
40
+ end
41
+
35
42
  sig { returns(Pathname) }
36
43
  def yml
37
44
  Pathname.new(name).join(PACKAGE_YML_NAME).cleanpath
@@ -39,7 +46,7 @@ module ParsePackwerk
39
46
 
40
47
  sig { returns(Pathname) }
41
48
  def directory
42
- Pathname.new(name).cleanpath
49
+ self.class.directory(self.name)
43
50
  end
44
51
 
45
52
  sig { returns(Pathname) }
@@ -56,10 +63,5 @@ module ParsePackwerk
56
63
  def enforces_privacy?
57
64
  enforce_privacy
58
65
  end
59
-
60
- sig { returns(T::Array[Violation]) }
61
- def violations
62
- PackageTodo.for(self).violations
63
- end
64
66
  end
65
67
  end
@@ -9,8 +9,7 @@ module ParsePackwerk
9
9
 
10
10
  sig { params(package: Package).returns(PackageTodo) }
11
11
  def self.for(package)
12
- package_todo_yml_pathname = package.directory.join(PACKAGE_TODO_YML_NAME)
13
- PackageTodo.from(package_todo_yml_pathname)
12
+ PackageTodo.from(self.yml(package.directory))
14
13
  end
15
14
 
16
15
  sig { params(pathname: Pathname).returns(PackageTodo) }
@@ -42,5 +41,10 @@ module ParsePackwerk
42
41
  )
43
42
  end
44
43
  end
44
+
45
+ sig { params(dirname: Pathname).returns(Pathname) }
46
+ def self.yml(dirname)
47
+ dirname.join(PACKAGE_TODO_YML_NAME).cleanpath
48
+ end
45
49
  end
46
50
  end
@@ -72,17 +72,6 @@ module ParsePackwerk
72
72
  merged_config.merge!('enforce_privacy' => package.enforce_privacy)
73
73
  end
74
74
 
75
- # We want checkers of the form `enforce_xyz` to be at the top
76
- merged_config_arr = merged_config.sort_by do |k, v|
77
- if k.include?('enforce')
78
- 0
79
- else
80
- 1
81
- end
82
- end
83
-
84
- merged_config = merged_config_arr.to_h
85
-
86
75
  unless package.public_path == DEFAULT_PUBLIC_PATH
87
76
  merged_config.merge!('public_path' => package.public_path)
88
77
  end
@@ -96,6 +85,10 @@ module ParsePackwerk
96
85
  if package.metadata.any?
97
86
  merged_config.merge!('metadata' => package.metadata)
98
87
  end
88
+
89
+ sorted_keys = key_sort_order
90
+ merged_config = merged_config.to_a.sort_by{|key, value| T.unsafe(sorted_keys).index(key) || 1000 }.to_h
91
+
99
92
  raw_yaml = YAML.dump(merged_config)
100
93
  # Add indentation for dependencies
101
94
  raw_yaml.gsub!(/^- /," - ")
@@ -104,6 +97,23 @@ module ParsePackwerk
104
97
  end
105
98
  end
106
99
 
100
+ sig { returns(T::Array[String]) }
101
+ def self.key_sort_order
102
+ %w(
103
+ enforce_dependencies
104
+ enforce_privacy
105
+ enforce_visibility
106
+ enforce_architecture
107
+ public_path
108
+ owner
109
+ layer
110
+ dependencies
111
+ ignored_dependencies
112
+ visible_to
113
+ metadata
114
+ )
115
+ end
116
+
107
117
  # We memoize packages_by_name for fast lookup.
108
118
  # Since Graph is an immutable value object, we can create indexes and general caching mechanisms safely.
109
119
  sig { returns(T::Hash[String, Package]) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse_packwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.2
4
+ version: 0.20.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: 2023-05-16 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.2.16
33
+ version: '2.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.2.16
40
+ version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement