use_packwerk 0.51.1 → 0.52.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 285e57f72e02b4ef6389a90efce2c9513028a72b9e5b1d9c9b0cbcf10c2c0c4b
4
- data.tar.gz: b3c901d0fbab3054bb30e1db668aca9833a4829d36d3e6ffc2555981d9d79fe0
3
+ metadata.gz: 546e7007cad88d3e42ed331cbb5aa054a880d4c11724786a394bc8fde8f7085a
4
+ data.tar.gz: ef02e6ce782b74c8537b838f9d2d7d61991b0197fd28f9e6e6fb6d9ff0a6247e
5
5
  SHA512:
6
- metadata.gz: 1a2fb745ee2c0f89e16f01d7793f86c4b8e2043a4fa7c3120c58d25651d6481d3b577f5208a75a8075de767796388f420bcabb78bd25a54cb30c3ece0858a68f
7
- data.tar.gz: cfa9a6db6615a488928182c1f0aec82a572a27f92b140580cb3656df404a0e9071e9f03ae7ad7e42d146de87641604281b4e4979d2601fa76fc67dc2ef4a671b
6
+ metadata.gz: db8a175fa8ddcf0e4fe54cb57d5215ea9786ed7a67a0318f2e3377ce06f959ed48bd07f7501c861f73881d1ee460aac7d053e954efc08792d502b320bbd6c990
7
+ data.tar.gz: f0817b39a8e600723ab17fe6d8caaae2d279c074608f861f971db2efcafc24cffaccbff6e2f5b9715c6db6e277e6c670c6fe8425a1bb0f312690323dc9ac42d5
@@ -16,37 +16,37 @@ module UsePackwerk
16
16
 
17
17
  sig { params(origin_pathname: Pathname, new_package_root: Pathname).returns(Pathname) }
18
18
  def self.destination_pathname_for_package_move(origin_pathname, new_package_root)
19
- parts = origin_pathname.to_s.split('/')
20
- toplevel_directory = parts[0]
19
+ origin_pack = T.must(ParsePackwerk.package_from_path(origin_pathname))
21
20
 
22
- case toplevel_directory.to_s
23
- # This allows us to move files from monolith to packs
24
- when 'app', 'spec', 'lib'
21
+ new_implementation = nil
22
+ if origin_pack.name == ParsePackwerk::ROOT_PACKAGE_NAME
25
23
  new_package_root.join(origin_pathname).cleanpath
26
- # This allows us to move files from packs to packs
27
- when *PERMITTED_PACK_LOCATIONS # parts looks like ['packs', 'organisms', 'app', 'services', 'bird_like', 'eagle.rb']
28
- new_package_root.join(T.must(parts[2..]).join('/')).cleanpath
29
24
  else
30
- raise StandardError.new("Don't know how to find destination path for #{origin_pathname.inspect}")
25
+ Pathname.new(origin_pathname.to_s.gsub(origin_pack.name, new_package_root.to_s)).cleanpath
31
26
  end
32
27
  end
33
28
 
34
29
  sig { params(origin_pathname: Pathname).returns(Pathname) }
35
30
  def self.destination_pathname_for_new_public_api(origin_pathname)
36
- parts = origin_pathname.to_s.split('/')
37
- toplevel_directory = Pathname.new(parts[0])
38
31
 
39
- case toplevel_directory.to_s
40
- # This allows us to make API in the monolith public
41
- when 'app', 'spec'
42
- toplevel_directory.join('public').join(T.must(parts[2..]).join('/')).cleanpath
43
- # This allows us to make API in existing packs public
44
- when *PERMITTED_PACK_LOCATIONS # parts looks like ['packs', 'organisms', 'app', 'services', 'bird_like', 'eagle.rb']
45
- pack_name = Pathname.new(parts[1])
46
- toplevel_directory.join(pack_name).join('app/public').join(T.must(parts[4..]).join('/')).cleanpath
32
+ origin_pack = T.must(ParsePackwerk.package_from_path(origin_pathname))
33
+ if origin_pack.name == ParsePackwerk::ROOT_PACKAGE_NAME
34
+ filepath_without_pack_name = origin_pathname.to_s
47
35
  else
48
- raise StandardError.new("Don't know how to find destination path for #{origin_pathname.inspect}")
36
+ filepath_without_pack_name = origin_pathname.to_s.gsub("#{origin_pack.name}/", '')
49
37
  end
38
+
39
+ # We join the pack name with the rest of the path...
40
+ path_parts = filepath_without_pack_name.split("/")
41
+ Pathname.new(origin_pack.name).join(
42
+ # ... keeping the "app" or "spec"
43
+ T.must(path_parts[0]),
44
+ # ... substituting "controllers," "services," etc. with "public"
45
+ 'public',
46
+ # ... then the rest is the same
47
+ T.must(path_parts[2..]).join("/")
48
+ # and we take the cleanpath so `./app/...` becomes `app/...`
49
+ ).cleanpath
50
50
  end
51
51
 
52
52
  sig { returns(FileMoveOperation) }
@@ -197,19 +197,7 @@ module UsePackwerk
197
197
 
198
198
 
199
199
  file_move_operations = file_paths.map do |path|
200
- parts = path.to_s.split('/')
201
- first_part_of_path = T.must(parts[0])
202
-
203
- if Pathname.new(first_part_of_path).dirname.join(ParsePackwerk::PACKAGE_YML_NAME).exist?
204
- package_location = Pathname.new('.')
205
- elsif PERMITTED_PACK_LOCATIONS.include?(first_part_of_path)
206
- package_location = Pathname.new(first_part_of_path).join(T.must(parts[1]))
207
- else
208
- raise StandardError.new('Can only make files in the monolith or in existing packs public')
209
- end
210
-
211
- package = ParsePackwerk::Package.from(package_location.join(ParsePackwerk::PACKAGE_YML_NAME))
212
-
200
+ package = T.must(ParsePackwerk.package_from_path(path))
213
201
  origin_pathname = Pathname.new(path).cleanpath
214
202
 
215
203
  FileMoveOperation.new(
@@ -427,6 +415,7 @@ module UsePackwerk
427
415
 
428
416
  sig { params(original_package: ParsePackwerk::Package).returns(ParsePackwerk::Package) }
429
417
  def self.rewrite_package_with_original_packwerk_values(original_package)
418
+ ParsePackwerk.bust_cache!
430
419
  package_with_protection_defaults = T.must(ParsePackwerk.all.find { |package| package.name == original_package.name })
431
420
  # PackageProtections also sets `enforce_privacy` and `enforce_dependency` to be true, so we set these back down to their original values
432
421
  package = ParsePackwerk::Package.new(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: use_packwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.1
4
+ version: 0.52.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-08-04 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize