2018-11-05 23:45:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-16 16:27:50 -04:00
|
|
|
module Gitlab
|
|
|
|
module DependencyLinker
|
|
|
|
class PackageJsonLinker < JsonLinker
|
|
|
|
self.file_type = :package_json
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def link_dependencies
|
|
|
|
link_json('license', &method(:license_url))
|
|
|
|
link_json(%w[homepage url], URL_REGEX, &:itself)
|
|
|
|
|
|
|
|
link_packages
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_packages
|
2019-02-15 14:11:16 -05:00
|
|
|
link_packages_at_key("dependencies")
|
|
|
|
link_packages_at_key("devDependencies")
|
2017-05-16 16:27:50 -04:00
|
|
|
end
|
|
|
|
|
2019-02-15 14:11:16 -05:00
|
|
|
def link_packages_at_key(key)
|
2017-05-16 16:27:50 -04:00
|
|
|
dependencies = json[key]
|
|
|
|
return unless dependencies
|
|
|
|
|
|
|
|
dependencies.each do |name, version|
|
2019-02-15 14:11:16 -05:00
|
|
|
external_url = external_url(name, version)
|
|
|
|
|
|
|
|
link_json(name, version, link: :key) { external_url }
|
|
|
|
link_json(name) { external_url }
|
2017-05-16 16:27:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_url(name)
|
|
|
|
"https://npmjs.com/package/#{name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|