2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
module BlobViewer
|
|
|
|
class PackageJson < DependencyManager
|
|
|
|
include ServerSide
|
|
|
|
|
|
|
|
self.file_types = %i(package_json)
|
|
|
|
|
|
|
|
def manager_name
|
2021-12-11 22:18:48 +05:30
|
|
|
yarn? ? 'yarn' : 'npm'
|
|
|
|
end
|
|
|
|
|
|
|
|
def yarn?
|
2023-06-20 00:43:36 +05:30
|
|
|
fetch_from_json('engines', 'yarn').present?
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def manager_url
|
2021-12-11 22:18:48 +05:30
|
|
|
yarn? ? 'https://yarnpkg.com/' : 'https://www.npmjs.com/'
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def package_name
|
2023-06-20 00:43:36 +05:30
|
|
|
@package_name ||= fetch_from_json('name')
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def package_type
|
|
|
|
private? ? 'private package' : super
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def package_url
|
2018-03-17 18:26:18 +05:30
|
|
|
private? ? homepage : npm_url
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def private?
|
2023-06-20 00:43:36 +05:30
|
|
|
!!fetch_from_json('private')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def homepage
|
2023-06-20 00:43:36 +05:30
|
|
|
url = fetch_from_json('homepage')
|
2018-11-08 19:23:39 +05:30
|
|
|
url if Gitlab::UrlSanitizer.valid?(url)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def npm_url
|
2021-12-11 22:18:48 +05:30
|
|
|
if yarn?
|
|
|
|
"https://yarnpkg.com/package/#{package_name}"
|
|
|
|
else
|
|
|
|
"https://www.npmjs.com/package/#{package_name}"
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|