Class: Licensed::Sources::NPM::Dependency

Inherits:
Dependency
  • Object
show all
Defined in:
lib/licensed/sources/npm.rb

Constant Summary

Constants inherited from Dependency

Dependency::LEGAL_FILES_PATTERN

Instance Attribute Summary

Attributes inherited from Dependency

#additional_terms, #errors, #name, #path, #version

Instance Method Summary collapse

Methods inherited from Dependency

#errors?, #exist?, #initialize, #license_contents, #license_key, #metadata, #notice_contents, #project_files, #record

Constructor Details

This class inherits a constructor from Licensed::Dependency

Instance Method Details

#license_metadataObject

override license_metadata to pull homepage and summary information from a packages package.json file, if it exists this accounts for the lack of this information in npm 7’s ‘npm list` output



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/licensed/sources/npm.rb', line 11

def 
  data = super
  return data if !data["homepage"].to_s.empty? && !data["summary"].to_s.empty?

  package_json_path = File.join(path, "package.json")
  return data unless File.exist?(package_json_path)

  package_json = JSON.parse(File.read(package_json_path))
  data["homepage"] = package_json["homepage"]
  data["summary"] = package_json["description"]

  data
end