parse_packwerk 0.17.0 → 0.18.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: 15bfbc3e8c8f9231a7e0c82ede3394bb05386abc71daa19febb3c86250597476
4
- data.tar.gz: 2a976526390b78391b76130958e41729c6a8e0122be5f97c8322ae9642a2a753
3
+ metadata.gz: 7a09aa689cc7e62ae6f1dab57eea2705b3a658954bd12fbd89084d3542d673b2
4
+ data.tar.gz: d7a76cc5ee374ea98541b8f4663256647389d08357d230479a99d5f85a003a72
5
5
  SHA512:
6
- metadata.gz: d697a84ba9180443e4dd19a0bdfb7ff30970434fb4754a0648bbdaa3e7fa0c54a244e4bd16d13b43f437855e2f439ca1d7b1a072514f3fcb0882c64e85aabf7a
7
- data.tar.gz: 56dad6bdaab9066b5bc9b0d8396212ab6befc66438ce5aec5d7475c271b3e86fe0f911efba815980afd3c5ea6d5187ad0712b6e36cbdfe0a033c940db38481f8
6
+ metadata.gz: 5597c6896e8421524404bd79b8ae8d7b2b17bc7b44761e5675361b34ccd589f0b6b5ef019f1fcd388766436bae4365146d47d621bf2adf843c28911db52db778
7
+ data.tar.gz: e9e0f9052c5c778537d73dbdb0317e85c50adf3346933a7eb4d9d14cf46f869fa702f5fca349cfc6fae99b6f9a45a2ab1127034ce55fffec860a8262e9332a34
@@ -10,6 +10,7 @@ module ParsePackwerk
10
10
  const :public_path, String, default: DEFAULT_PUBLIC_PATH
11
11
  const :metadata, MetadataYmlType
12
12
  const :dependencies, T::Array[String]
13
+ const :config, T::Hash[T.untyped, T.untyped]
13
14
 
14
15
  sig { params(pathname: Pathname).returns(Package) }
15
16
  def self.from(pathname)
@@ -18,11 +19,12 @@ module ParsePackwerk
18
19
 
19
20
  new(
20
21
  name: package_name,
21
- enforce_dependencies: package_loaded_yml[ENFORCE_DEPENDENCIES] ? true : false,
22
- enforce_privacy: package_loaded_yml[ENFORCE_PRIVACY] ? true : false,
22
+ enforce_dependencies: package_loaded_yml[ENFORCE_DEPENDENCIES],
23
+ enforce_privacy: package_loaded_yml[ENFORCE_PRIVACY],
23
24
  public_path: package_loaded_yml[PUBLIC_PATH] || DEFAULT_PUBLIC_PATH,
24
25
  metadata: package_loaded_yml[METADATA] || {},
25
- dependencies: package_loaded_yml[DEPENDENCIES] || []
26
+ dependencies: package_loaded_yml[DEPENDENCIES] || [],
27
+ config: package_loaded_yml,
26
28
  )
27
29
  end
28
30
 
@@ -53,44 +53,42 @@ module ParsePackwerk
53
53
  sig { params(package: ParsePackwerk::Package).void }
54
54
  def self.write_package_yml!(package)
55
55
  FileUtils.mkdir_p(package.directory)
56
+
56
57
  File.open(package.yml, 'w') do |file|
57
- # We do not use `YAML.dump` or `contents.to_yaml` because it seems like packwerk writes a variation of the default YAML spec.
58
- # If you'd like to see the difference, change this to `package_yaml = YAML.dump(contents)` to and run tests to see the difference.
59
- package_yml = <<~PACKAGEYML
60
- enforce_dependencies: #{package.enforces_dependencies?}
61
- enforce_privacy: #{package.enforces_privacy?}
62
- PACKAGEYML
58
+ merged_config = package.config
59
+
60
+ merged_config.merge!(
61
+ 'enforce_dependencies' => package.enforce_dependencies,
62
+ 'enforce_privacy' => package.enforce_privacy
63
+ )
64
+
65
+ # We want checkers of the form `enforce_xyz` to be at the top
66
+ merged_config_arr = merged_config.sort_by do |k, v|
67
+ if k.include?('enforce')
68
+ 0
69
+ else
70
+ 1
71
+ end
72
+ end
73
+
74
+ merged_config = merged_config_arr.to_h
63
75
 
64
76
  unless package.public_path == DEFAULT_PUBLIC_PATH
65
- public_path = <<~PUBLICPATH
66
- public_path: #{package.public_path}
67
- PUBLICPATH
68
- package_yml += public_path
77
+ merged_config.merge!('public_path' => package.public_path)
69
78
  end
70
79
 
71
80
  if package.dependencies.any?
72
- dependencies = <<~STATEDDEPS
73
- dependencies:
74
- #{package.dependencies.map { |dep| " - #{dep}" }.join("\n")}
75
- STATEDDEPS
76
-
77
- package_yml += dependencies
81
+ merged_config.merge!('dependencies' => package.dependencies)
78
82
  end
79
83
 
80
- if package.metadata.keys.any?
81
- raw_yaml = YAML.dump(package.metadata)
82
- stylized_yaml = raw_yaml.gsub("---\n", '')
83
- indented_yaml = stylized_yaml.split("\n").map { |line| " #{line}" }.join("\n")
84
-
85
- metadata = <<~METADATA
86
- metadata:
87
- #{indented_yaml}
88
- METADATA
89
-
90
- package_yml += metadata
84
+ if package.metadata.any?
85
+ merged_config.merge!('metadata' => package.metadata)
91
86
  end
92
-
93
- file.write(package_yml)
87
+ raw_yaml = YAML.dump(merged_config)
88
+ # Add indentation for dependencies
89
+ raw_yaml.gsub!(/^- /," - ")
90
+ stylized_yaml = raw_yaml.gsub("---\n", '')
91
+ file.write(stylized_yaml)
94
92
  end
95
93
  end
96
94
 
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.17.0
4
+ version: 0.18.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-12-15 00:00:00.000000000 Z
11
+ date: 2022-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime