parse_packwerk 0.10.0 → 0.12.0

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/parse_packwerk.rb +23 -2
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00ce04288d8a8c4f46571bd181e8a3781d325116cd58e8078cdf142e9f74ffce
4
- data.tar.gz: 23c1e53eab84fc472d116bf025c6ddb499f509da25246f47ffbdb857ec922f3f
3
+ metadata.gz: 573bc6231b6506545fa220a99d6ed0abf08362a72e44cabae50a333c209bcbb9
4
+ data.tar.gz: df64a2831b7d4cebc67597cebcfc2b71ee8cd0d33b1d124f8b6d152eb5e8f6a2
5
5
  SHA512:
6
- metadata.gz: f24bf1e21e1800e35aa9c4fcdbf1c5e71efafd421d1ce7829461e620c30728a23dd78e099f91bd359fa69e0bca9cef71fabea4cc139598520520942afbcf9006
7
- data.tar.gz: 6bd309198e121db0066178ec0fcddbef4b0187110a600bc716fe72d1ebbedab713767b25700d679bd219cafabd93ce6c0896cc0cf9cfa51c279c205105c30003
6
+ metadata.gz: 6cc08b66c764699ee9110f800fd13dd41deeacefeba958f5769b4d15d6dd1ed186612d846813d3d69670127036d24de51ec4a7dd599a435187b686dcc3693e0d
7
+ data.tar.gz: 64aacb8e7b976545a5974db6e480e5b0f4e01c164517ac8434f8e8f66dc6bf966f2cdb60aff357fc0dbb96af49f7aaa787e46af8868816f4fcc775209081e1f6
data/README.md CHANGED
@@ -26,8 +26,8 @@ We generally recommend folks depend on `packwerk` rather than `parse_packwerk`.
26
26
 
27
27
  This gem exists for this toolchain for these reasons:
28
28
 
29
- (A) `packwerk` is lacking public APIs for the behavior we want. It's close with `PackageSet`, but we need to also be able to parse violations.
30
- (B) Certain critical, production runtime code-paths need to use this, and we want a simple, low-dependency, infrequently changing dependency for our production environment. One example of production usage is that `package.yml` files can store team ownership information, which is used when an error happens in production to route it to the right team.
31
- (C) `packwerk` has heavy duty dependencies like rails and lots of others, and it adds a degree of maintenance cost and complexity that isn’t necessary when all we want to do is read YML files
29
+ - `packwerk` is lacking public APIs for the behavior we want. It's close with `PackageSet`, but we need to also be able to parse violations.
30
+ - Certain critical, production runtime code-paths need to use this, and we want a simple, low-dependency, infrequently changing dependency for our production environment. One example of production usage is that `package.yml` files can store team ownership information, which is used when an error happens in production to route it to the right team.
31
+ - `packwerk` has heavy duty dependencies like rails and lots of others, and it adds a degree of maintenance cost and complexity that isn’t necessary when all we want to do is read YML files
32
32
 
33
33
  Long-term, it might make sense for these reasons to extract out some of the parsing from `packwerk` into a separate gem similar to this so that we can leverage the ecosystem of tools associated with the idea of a “pack” in ways that are simple and safe for both development and production environments.
@@ -26,7 +26,7 @@ module ParsePackwerk
26
26
  returns(T::Array[Package])
27
27
  end
28
28
  def self.all
29
- PackageSet.from(package_pathspec: yml.package_paths, exclude_pathspec: yml.exclude)
29
+ packages_by_name.values
30
30
  end
31
31
 
32
32
  sig { params(name: String).returns(T.nilable(Package)) }
@@ -39,6 +39,17 @@ module ParsePackwerk
39
39
  Configuration.fetch
40
40
  end
41
41
 
42
+ sig { params(file_path: T.any(Pathname, String)).returns(T.nilable(Package)) }
43
+ def self.package_from_path(file_path)
44
+ path_string = file_path.to_s
45
+ @package_from_path = T.let(@package_from_path, T.nilable(T::Hash[String, Package]))
46
+ @package_from_path ||= {}
47
+ @package_from_path[path_string] ||= T.must(begin
48
+ matching_package = all.find { |package| path_string.start_with?("#{package.name}/") || path_string == package.name }
49
+ matching_package || find(ROOT_PACKAGE_NAME)
50
+ end)
51
+ end
52
+
42
53
  sig { params(package: ParsePackwerk::Package).void }
43
54
  def self.write_package_yml!(package)
44
55
  FileUtils.mkdir_p(package.directory)
@@ -82,9 +93,19 @@ module ParsePackwerk
82
93
  def self.packages_by_name
83
94
  @packages_by_name = T.let(@packages_by_name, T.nilable(T::Hash[String, Package]))
84
95
  @packages_by_name ||= begin
85
- all.map{|p| [p.name, p]}.to_h
96
+ all_packages = PackageSet.from(package_pathspec: yml.package_paths, exclude_pathspec: yml.exclude)
97
+ # We want to match more specific paths first
98
+ # Packwerk does this too and is necessary for package_from_path to work correctly.
99
+ sorted_packages = all_packages.sort_by { |package| -package.name.length }
100
+ sorted_packages.map{|p| [p.name, p]}.to_h
86
101
  end
87
102
  end
88
103
 
104
+ sig { void }
105
+ def self.bust_cache!
106
+ @packages_by_name = nil
107
+ @package_from_path = nil
108
+ end
109
+
89
110
  private_class_method :packages_by_name
90
111
  end
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.10.0
4
+ version: 0.12.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: 2022-05-03 00:00:00.000000000 Z
11
+ date: 2022-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime
@@ -141,13 +141,13 @@ files:
141
141
  - sorbet/rbi/gems/hashdiff@1.0.1.rbi
142
142
  - sorbet/rbi/gems/rspec@3.10.0.rbi
143
143
  - sorbet/rbi/gems/rspec_override.rbi
144
- homepage: https://github.com/bigrails/parse_packwerk
144
+ homepage: https://github.com/rubyatscale/parse_packwerk
145
145
  licenses:
146
146
  - MIT
147
147
  metadata:
148
- homepage_uri: https://github.com/bigrails/parse_packwerk
149
- source_code_uri: https://github.com/bigrails/parse_packwerk
150
- changelog_uri: https://github.com/bigrails/parse_packwerk/releases
148
+ homepage_uri: https://github.com/rubyatscale/parse_packwerk
149
+ source_code_uri: https://github.com/rubyatscale/parse_packwerk
150
+ changelog_uri: https://github.com/rubyatscale/parse_packwerk/releases
151
151
  allowed_push_host: https://rubygems.org
152
152
  post_install_message:
153
153
  rdoc_options: []