packs 0.0.34 → 0.0.36

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: 6a04a13a8a29914ee596b13b56398210d5758feb1b6765e00209f5e4c45e9bfe
4
- data.tar.gz: 9d6bf62bb81a7787c0b100acb888496bbbf06f898fda036073e0e4d65bd01f15
3
+ metadata.gz: c0a49abad749c63c73c0bbb9cfa0ac4d75962af3c0f5b22cfb8173906f18310e
4
+ data.tar.gz: e9757c94ee7866e9ee7daaeec189166aa7a07b47baa18f93eff239552a5e94ab
5
5
  SHA512:
6
- metadata.gz: f899dc6e201f15c8f256ae5ae6686d1954bce35e72558da615428fe1a43c55bd1aca42071983cf81e45ad091492add405b3094e62f2c66c7333d004e08dabdc3
7
- data.tar.gz: 99c087232ca4f42199c55a2263daabcd8cc7f376e439ab8d258a0eb4b9a4b93d86150bb15d4498c53ac66c87a5226997a59b73a3d5cec5983f1d61f1f7010cb9
6
+ metadata.gz: a74621a2a3346a352256086cb534c1ef6038beac481af3559409682ce2198c4d90e16b4d276ebe271fc93d6a9d7a2260642bf0aa2b76de22cd8bd4d9f11054a1
7
+ data.tar.gz: 93dc9e6df47b7150fd1c2ef1ddd312931b154934d83ae8060307ef17a6a146858b98b33f6961863a3c23348b0aa398f0c188098e6bdf5dc5c6c70547b97fc843
data/README.md CHANGED
@@ -21,7 +21,7 @@ The rest of the [rubyatscale](https://github.com/rubyatscale) ecosystem is inten
21
21
  Here are some example integrations with `packs`:
22
22
  - [`packs-specification`](https://github.com/rubyatscale/packs-specification) is a low-dependency gem that allows your production environment to query simple information about packs
23
23
  - [`packs-rails`](https://github.com/rubyatscale/packs-rails) can be used to integrate `packs` into your `rails` application
24
- - [`rubocop-packs`](https://github.com/rubyatscale/rubocop-packs) contains cops to improve boundaries around `packs`
24
+ - [`rubocop-packs`](https://github.com/rubyatscale/rubocop-packs) contains cops to improve boundaries around `packs`
25
25
  - [`packwerk`](https://github.com/Shopify/packwerk) and [`packwerk-extensions`](https://github.com/rubyatscale/packwerk-extensions) help you describe and constrain your package graph in terms of dependencies between packs and pack public API
26
26
  - [`code_ownership`](https://github.com/rubyatscale/code_ownership) gives your application the capability to determine the owner of a pack
27
27
  - [`pack_stats`](https://github.com/rubyatscale/pack_stats) makes it easy to send metrics about pack adoption and modularization to your favorite metrics provider, such as DataDog (which has built-in support).
@@ -77,7 +77,7 @@ If no pack name is passed in, this will list out violations across all packs.
77
77
  ## Make files or directories public API
78
78
  `bin/packs make_public path/to/file.rb path/to/directory`
79
79
 
80
- This moves a file or directory to public API (that is -- the `app/public` folder).
80
+ This moves a file or directory to public API (either the `app/public` folder or the pack's specified public path).
81
81
 
82
82
  Make sure there are no spaces between the comma-separated list of paths of directories.
83
83
 
data/lib/packs/cli.rb CHANGED
@@ -68,7 +68,7 @@ module Packs
68
68
 
69
69
  desc 'make_public path/to/file.rb path/to/directory', 'Make files or directories public API'
70
70
  long_desc <<~LONG_DESC
71
- This moves a file or directory to public API (that is -- the `app/public` folder).
71
+ This moves a file or directory to public API (either the `#{ParsePackwerk::DEFAULT_PUBLIC_PATH}` folder or the pack's specified public path).
72
72
 
73
73
  Make sure there are no spaces between the comma-separated list of paths of directories.
74
74
  LONG_DESC
@@ -40,7 +40,7 @@ module Packs
40
40
  end
41
41
  end
42
42
 
43
- sig { params(file_move_operations: T::Array[Private::FileMoveOperation]).void }
43
+ sig { override.params(file_move_operations: T::Array[Private::FileMoveOperation]).void }
44
44
  def after_move_files!(file_move_operations)
45
45
  if @teams.any?
46
46
  Logging.section('Code Ownership') do
@@ -10,7 +10,7 @@ module Packs
10
10
  sig { abstract.params(file_move_operation: Private::FileMoveOperation).void }
11
11
  def before_move_file!(file_move_operation); end
12
12
 
13
- sig { params(file_move_operations: T::Array[Private::FileMoveOperation]).void }
13
+ sig { overridable.params(file_move_operations: T::Array[Private::FileMoveOperation]).void }
14
14
  def after_move_files!(file_move_operations)
15
15
  nil
16
16
  end
data/lib/packs/private.rb CHANGED
@@ -173,6 +173,7 @@ module Packs
173
173
  enforce_privacy: package.enforce_privacy,
174
174
  enforce_dependencies: package.enforce_dependencies,
175
175
  dependencies: package.dependencies,
176
+ violations: package.violations,
176
177
  metadata: package.metadata,
177
178
  config: package.config
178
179
  )
@@ -214,6 +215,7 @@ module Packs
214
215
  enforce_privacy: other_package.enforce_privacy,
215
216
  enforce_dependencies: other_package.enforce_dependencies,
216
217
  dependencies: new_dependencies.uniq.sort,
218
+ violations: other_package.violations,
217
219
  metadata: other_package.metadata,
218
220
  config: new_config
219
221
  )
@@ -304,6 +306,7 @@ module Packs
304
306
  dependencies: (package.dependencies + [dependency_name]).uniq.sort,
305
307
  enforce_privacy: package.enforce_privacy,
306
308
  enforce_dependencies: package.enforce_dependencies,
309
+ violations: package.violations,
307
310
  metadata: package.metadata,
308
311
  config: package.config
309
312
  )
@@ -345,7 +348,7 @@ module Packs
345
348
 
346
349
  sig { params(package: ParsePackwerk::Package).void }
347
350
  def self.add_public_directory(package)
348
- public_directory = package.directory.join('app/public')
351
+ public_directory = package.directory.join(package.public_path)
349
352
 
350
353
  if public_directory.glob('**/**.rb').none?
351
354
  FileUtils.mkdir_p(public_directory)
@@ -373,8 +376,9 @@ module Packs
373
376
  ).returns(ParsePackwerk::Package)
374
377
  end
375
378
  def self.create_pack_if_not_exists!(pack_name:, enforce_privacy:, enforce_dependencies:, team: nil)
376
- if PERMITTED_PACK_LOCATIONS.none? { |permitted_location| pack_name.start_with?(permitted_location) }
377
- raise StandardError, "Packs only supports packages in the the following directories: #{PERMITTED_PACK_LOCATIONS.inspect}. Please make sure to pass in the name of the pack including the full directory path, e.g. `packs/my_pack`."
379
+ allowed_locations = Packs::Specification.config.pack_paths
380
+ if allowed_locations.none? { |location| File.fnmatch(location, pack_name) }
381
+ raise StandardError, "Packs only supports packages in the the following directories: #{allowed_locations}. Please make sure to pass in the name of the pack including the full directory path, e.g. `packs/my_pack`."
378
382
  end
379
383
 
380
384
  existing_package = ParsePackwerk.all.find { |p| p.name == pack_name }
@@ -395,6 +399,7 @@ module Packs
395
399
  enforce_dependencies: should_enforce_dependencies || false,
396
400
  enforce_privacy: enforce_privacy,
397
401
  dependencies: [],
402
+ violations: [],
398
403
  metadata: {},
399
404
  name: pack_name,
400
405
  config: config
@@ -508,7 +513,10 @@ module Packs
508
513
  outbound: {}
509
514
  }
510
515
 
516
+ package_by_name = {}
517
+
511
518
  ParsePackwerk.all.each do |p|
519
+ package_by_name[p.name] = p
512
520
  p.violations.each do |violation|
513
521
  violations[:outbound][p.name] ||= []
514
522
  violations[:outbound][p.name] << violation
@@ -553,7 +561,7 @@ module Packs
553
561
  pack_name: pack.name,
554
562
  owner: owner.nil? ? 'No one' : owner.name,
555
563
  size: pack.relative_path.glob('**/*.rb').count,
556
- public_api: pack.relative_path.join('app/public')
564
+ public_api: pack.relative_path.join(package_by_name[pack.name].public_path)
557
565
  }
558
566
 
559
567
  row.delete(:date) unless include_date
@@ -0,0 +1,50 @@
1
+ # typed: strict
2
+
3
+ module Packs
4
+ class UpdateReferencesPostProcessor
5
+ include PerFileProcessorInterface
6
+
7
+ extend T::Sig
8
+
9
+ sig { override.params(file_move_operation: Private::FileMoveOperation).void }
10
+ def before_move_file!(file_move_operation)
11
+ nil
12
+ end
13
+
14
+ sig { override.params(file_move_operations: T::Array[Private::FileMoveOperation]).void }
15
+ def after_move_files!(file_move_operations)
16
+ return if file_move_operations.empty?
17
+
18
+ origin_pack = T.must(file_move_operations.first).origin_pack.name
19
+ destination_pack = T.must(file_move_operations.first).destination_pack.name
20
+
21
+ if self.class.ripgrep_enabled?
22
+ matching_files = `rg -l --hidden '#{origin_pack}' .`
23
+ matching_files.split("\n").each do |file_name|
24
+ substitute_references!(file_name, origin_pack, destination_pack)
25
+ end
26
+ else
27
+ Logging.print('For faster UpdateReferences install ripgrep: https://github.com/BurntSushi/ripgrep/tree/master')
28
+ Dir.glob('./**/*', File::FNM_DOTMATCH) do |file_name|
29
+ next if File.directory?(file_name)
30
+
31
+ substitute_references!(file_name, origin_pack, destination_pack)
32
+ end
33
+ end
34
+ end
35
+
36
+ sig { returns(T::Boolean) }
37
+ def self.ripgrep_enabled?
38
+ !!system('which', 'rg', out: File::NULL, err: :out)
39
+ end
40
+
41
+ private
42
+
43
+ sig { params(file_name: String, origin_pack: String, destination_pack: String).void }
44
+ def substitute_references!(file_name, origin_pack, destination_pack)
45
+ text = File.read(file_name)
46
+ replace = text.gsub(origin_pack, destination_pack)
47
+ File.open(file_name, 'w') { |file| file.puts replace }
48
+ end
49
+ end
50
+ end
@@ -23,7 +23,7 @@ module Packs
23
23
 
24
24
  2) Run `bin/packwerk update-todo` to update the violations. Make sure to run `spring stop` if you've added new load paths (new top-level directories) in your pack.
25
25
 
26
- 3) Expose public API in #{pack_name}/app/public. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
26
+ 3) Expose public API in #{pack_name}/#{ParsePackwerk::DEFAULT_PUBLIC_PATH}. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
27
27
 
28
28
  4) Update your readme at #{pack_name}/README.md
29
29
  MSG
@@ -45,7 +45,7 @@ module Packs
45
45
 
46
46
  2) Touch base with each team who owns files involved in this move
47
47
 
48
- 3) Expose public API in #{pack_name}/app/public. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
48
+ 3) Expose public API in #{pack_name}/#{ParsePackwerk::DEFAULT_PUBLIC_PATH}. Try `bin/packs make_public #{pack_name}/path/to/file.rb`
49
49
 
50
50
  4) Update your readme at #{pack_name}/README.md
51
51
  MSG
@@ -136,7 +136,7 @@ module Packs
136
136
  If you're the author, please consider replacing this file with a README.md, which may contain:
137
137
  - What your pack is and does
138
138
  - How you expect people to use your pack
139
- - Example usage of your pack's public API (which lives in `#{pack_name}/app/public`)
139
+ - Example usage of your pack's public API (which lives in `#{pack_name}/#{ParsePackwerk::DEFAULT_PUBLIC_PATH}`)
140
140
  - Limitations, risks, and important considerations of usage
141
141
  - How to get in touch with eng and other stakeholders for questions or issues pertaining to this pack (note: it is recommended to add ownership in `#{pack_name}/package.yml` under the `owner` metadata key)
142
142
  - What SLAs/SLOs (service level agreements/objectives), if any, your package provides
@@ -157,7 +157,7 @@ module Packs
157
157
  Pass in a limit to display more or less, e.g. `bin/packs list_top_violations #{type} #{pack_name} -l 1000`
158
158
 
159
159
  This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
160
- Anything not in pack_name/app/public is considered private API.
160
+ Anything not in pack_name/#{ParsePackwerk::DEFAULT_PUBLIC_PATH} is considered private API.
161
161
  PACK_CONTENT
162
162
  else
163
163
  <<~PACK_CONTENT
@@ -165,7 +165,7 @@ module Packs
165
165
  Pass in a limit to display more or less, e.g. `bin/packs list_top_violations #{type} #{pack_name} -l 1000`
166
166
 
167
167
  This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
168
- Anything not in #{pack_name}/app/public is considered private API.
168
+ Anything not in #{pack_name}/#{ParsePackwerk::DEFAULT_PUBLIC_PATH} is considered private API.
169
169
  PACK_CONTENT
170
170
  end
171
171
  end
data/lib/packs.rb CHANGED
@@ -16,6 +16,7 @@ require 'code_ownership'
16
16
  require 'packs/private'
17
17
  require 'packs/per_file_processor_interface'
18
18
  require 'packs/rubocop_post_processor'
19
+ require 'packs/update_references_post_processor'
19
20
  require 'packs/code_ownership_post_processor'
20
21
  require 'packs/logging'
21
22
  require 'packs/configuration'
@@ -24,12 +25,6 @@ require 'packs/cli'
24
25
  module Packs
25
26
  extend T::Sig
26
27
 
27
- PERMITTED_PACK_LOCATIONS = T.let(%w[
28
- gems
29
- components
30
- packs
31
- ], T::Array[String])
32
-
33
28
  sig { void }
34
29
  def self.start_interactive_mode!
35
30
  Private::InteractiveCli.start!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.34
4
+ version: 0.0.36
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-11-16 00:00:00.000000000 Z
11
+ date: 2023-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_ownership
@@ -304,6 +304,7 @@ files:
304
304
  - lib/packs/private/pack_relationship_analyzer.rb
305
305
  - lib/packs/private/packwerk_wrapper/offenses_aggregator_formatter.rb
306
306
  - lib/packs/rubocop_post_processor.rb
307
+ - lib/packs/update_references_post_processor.rb
307
308
  - lib/packs/user_event_logger.rb
308
309
  homepage: https://github.com/rubyatscale/packs
309
310
  licenses: