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