Commit e7bf164e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix npm registry for yarn

Expose dist-tags attribute in NPM registry API
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent b27ac68a
......@@ -25,15 +25,21 @@ class NpmPackagePresenter
package_versions
end
def dist_tags
{
latest: sorted_versions.last
}
end
private
def build_package_version(package, package_file)
{
"name": package.name,
"version": package.version,
"dist": {
"shasum": package_file.file_sha1,
"tarball": tarball_url(package, package_file)
name: package.name,
version: package.version,
dist: {
shasum: package_file.file_sha1,
tarball: tarball_url(package, package_file)
}
}
end
......@@ -43,4 +49,9 @@ class NpmPackagePresenter
"/packages/npm/#{package.name}" \
"/-/#{package_file.file_name}"
end
def sorted_versions
versions = packages.map(&:version).compact
VersionSorter.sort(versions)
end
end
---
title: Fix npm registry for yarn
merge_request: 9599
author:
type: fixed
......@@ -629,6 +629,7 @@ module EE
class NpmPackage < Grape::Entity
expose :name
expose :versions
expose :dist_tags, as: 'dist-tags'
end
class Package < Grape::Entity
......
# frozen_string_literal: true
require 'spec_helper'
describe NpmPackagePresenter do
set(:project) { create(:project) }
set(:package) { create(:npm_package, version: '1.0.4', project: project) }
set(:latest_package) { create(:npm_package, version: '1.0.11', project: project) }
let(:presenter) { described_class.new(project, package.name, project.packages.all) }
describe '#dist_tags' do
it { expect(presenter.dist_tags).to be_a(Hash) }
it { expect(presenter.dist_tags[:latest]).to eq(latest_package.version) }
end
describe '#versions' do
it { expect(presenter.versions).to be_a(Hash) }
it { expect(presenter.versions[package.version]).to match_schema('public_api/v4/packages/npm_package_version', dir: 'ee') }
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