22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/code_ownership/private/parse_js_packages.rb', line 22
def self.from(pathname)
package_loaded_json = JSON.parse(pathname.read)
package_name = if pathname.dirname == Pathname.new('.')
ROOT_PACKAGE_NAME
else
pathname.dirname.cleanpath.to_s
end
new(
name: package_name,
metadata: package_loaded_json[METADATA] || {}
)
rescue JSON::ParserError => e
error_message = <<~MESSAGE
#{e.inspect}
#{pathname} has invalid JSON, so code ownership cannot be determined.
Please either make the JSON in that file valid or specify `js_package_paths` in config/code_ownership.yml.
MESSAGE
raise InvalidCodeOwnershipConfigurationError, error_message
end
|