2018-08-03 07:15:25 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-17 16:27:30 +00:00
|
|
|
module BlobViewer
|
|
|
|
class PackageJson < DependencyManager
|
|
|
|
include ServerSide
|
|
|
|
|
|
|
|
self.file_types = %i(package_json)
|
|
|
|
|
|
|
|
def manager_name
|
2021-11-12 12:10:27 +00:00
|
|
|
yarn? ? 'yarn' : 'npm'
|
|
|
|
end
|
|
|
|
|
|
|
|
def yarn?
|
|
|
|
json_data['engines'].present? && json_data['engines']['yarn'].present?
|
2017-05-17 16:27:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def manager_url
|
2021-11-12 12:10:27 +00:00
|
|
|
yarn? ? 'https://yarnpkg.com/' : 'https://www.npmjs.com/'
|
2017-05-17 16:27:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def package_name
|
|
|
|
@package_name ||= package_name_from_json('name')
|
|
|
|
end
|
|
|
|
|
2017-12-19 04:55:51 +00:00
|
|
|
def package_type
|
|
|
|
private? ? 'private package' : super
|
|
|
|
end
|
|
|
|
|
2017-05-17 16:27:30 +00:00
|
|
|
def package_url
|
2017-12-19 05:14:08 +00:00
|
|
|
private? ? homepage : npm_url
|
2017-05-17 16:27:30 +00:00
|
|
|
end
|
2017-12-19 04:55:51 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def private?
|
|
|
|
!!json_data['private']
|
|
|
|
end
|
2017-12-19 05:14:08 +00:00
|
|
|
|
|
|
|
def homepage
|
2018-09-12 06:34:55 +00:00
|
|
|
url = json_data['homepage']
|
|
|
|
url if Gitlab::UrlSanitizer.valid?(url)
|
2017-12-19 05:14:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def npm_url
|
2021-11-12 12:10:27 +00:00
|
|
|
if yarn?
|
|
|
|
"https://yarnpkg.com/package/#{package_name}"
|
|
|
|
else
|
|
|
|
"https://www.npmjs.com/package/#{package_name}"
|
|
|
|
end
|
2017-12-19 05:14:08 +00:00
|
|
|
end
|
2017-05-17 16:27:30 +00:00
|
|
|
end
|
|
|
|
end
|