Skip to content

Commit 515dc66

Browse files
schoblaskaashleywillardperryqhtstannard
authored
allow empty package.yml files (#42)
Co-authored-by: Ashley Willard <ashley.willard@gusto.com> Co-authored-by: Perry Hertler <perry.hertler@gusto.com> Co-authored-by: Teal Stannard <teal.stannard@gusto.com>
1 parent 83e4809 commit 515dc66

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
parse_packwerk (0.22.0)
4+
parse_packwerk (0.23.0)
55
bigdecimal
66
sorbet-runtime
77

lib/parse_packwerk/package.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ class Package < T::Struct
1616

1717
sig { params(pathname: Pathname).returns(Package) }
1818
def self.from(pathname)
19-
package_loaded_yml = YAML.load_file(pathname)
20-
if package_loaded_yml.nil? || package_loaded_yml == false
21-
message = "Failed to parse `#{pathname}`. Please fix any issues with this package.yml OR add its containing folder to packwerk.yml `exclude`"
22-
raise PackageParseError, message
23-
end
19+
package_loaded_yml = YAML.load_file(pathname) || {}
2420
package_name = pathname.dirname.cleanpath.to_s
2521

2622
new(

parse_packwerk.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'parse_packwerk'
3-
spec.version = '0.22.0'
3+
spec.version = '0.23.0'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['dev@gusto.com']
66
spec.summary = 'A low-dependency gem for parsing and writing packwerk YML files'

spec/parse_packwerk_spec.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,13 +677,29 @@
677677
it { is_expected.to have_matching_package expected_package, expected_package_todo }
678678
end
679679

680-
context 'in app with an invalid package.yml' do
680+
context 'in app with an empty package.yml' do
681+
let(:expected_package) do
682+
ParsePackwerk::Package.new(
683+
name: 'packs/my_pack',
684+
enforce_dependencies: nil,
685+
enforce_privacy: false,
686+
dependencies: [],
687+
metadata: {},
688+
config: {},
689+
violations: []
690+
)
691+
end
692+
693+
let(:expected_package_todo) do
694+
ParsePackwerk::PackageTodo.for(expected_package)
695+
end
696+
681697
before do
682698
write_file('packs/my_pack/package.yml', '')
683699
end
684700

685-
it 'outputs an error message with the pathname' do
686-
expect { subject }.to raise_error(ParsePackwerk::PackageParseError, %r{Failed to parse `packs/my_pack/package.yml`. Please fix any issues with this package.yml OR add its containing folder to packwerk.yml `exclude`})
701+
it 'parses the file and returns a package with empty values' do
702+
expect(subject).to have_matching_package(expected_package, expected_package_todo)
687703
end
688704
end
689705
end

0 commit comments

Comments
 (0)