Commit 260c01e1 authored by Kev's avatar Kev Committed by Vasilii Iakliushin

Add yarn as option for package.json dependency manager detection

parent d8274187
......@@ -7,11 +7,15 @@ module BlobViewer
self.file_types = %i(package_json)
def manager_name
'npm'
yarn? ? 'yarn' : 'npm'
end
def yarn?
json_data['engines'].present? && json_data['engines']['yarn'].present?
end
def manager_url
'https://www.npmjs.com/'
yarn? ? 'https://yarnpkg.com/' : 'https://www.npmjs.com/'
end
def package_name
......@@ -38,7 +42,11 @@ module BlobViewer
end
def npm_url
"https://www.npmjs.com/package/#{package_name}"
if yarn?
"https://yarnpkg.com/package/#{package_name}"
else
"https://www.npmjs.com/package/#{package_name}"
end
end
end
end
......@@ -27,11 +27,55 @@ RSpec.describe BlobViewer::PackageJson do
end
end
describe '#package_url' do
it 'returns the package URL' do
expect(subject).to receive(:prepare!)
context 'yarn' do
let(:data) do
<<-SPEC.strip_heredoc
{
"name": "module-name",
"version": "10.3.1",
"engines": {
"yarn": "^2.4.0"
}
}
SPEC
end
let(:blob) { fake_blob(path: 'package.json', data: data) }
subject { described_class.new(blob) }
describe '#package_url' do
it 'returns the package URL', :aggregate_failures do
expect(subject).to receive(:prepare!)
expect(subject.package_url).to eq("https://yarnpkg.com/package/#{subject.package_name}")
end
end
expect(subject.package_url).to eq("https://www.npmjs.com/package/#{subject.package_name}")
describe '#manager_url' do
it 'returns the manager URL', :aggregate_failures do
expect(subject).to receive(:prepare!)
expect(subject.manager_url).to eq("https://yarnpkg.com/")
end
end
end
context 'npm' do
describe '#package_url' do
it 'returns the package URL', :aggregate_failures do
expect(subject).to receive(:prepare!)
expect(subject.package_url).to eq("https://www.npmjs.com/package/#{subject.package_name}")
end
end
describe '#manager_url' do
it 'returns the manager URL', :aggregate_failures do
expect(subject).to receive(:prepare!)
expect(subject.manager_url).to eq("https://www.npmjs.com/")
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment