Commit afdceea7 authored by James Lopez's avatar James Lopez

Merge branch 'dz-npm-registry-yarn-support' into 'master'

Fix npm registry for yarn

Closes #9415

See merge request gitlab-org/gitlab-ee!9599
parents 0ebe5d7e e7bf164e
...@@ -25,15 +25,21 @@ class NpmPackagePresenter ...@@ -25,15 +25,21 @@ class NpmPackagePresenter
package_versions package_versions
end end
def dist_tags
{
latest: sorted_versions.last
}
end
private private
def build_package_version(package, package_file) def build_package_version(package, package_file)
{ {
"name": package.name, name: package.name,
"version": package.version, version: package.version,
"dist": { dist: {
"shasum": package_file.file_sha1, shasum: package_file.file_sha1,
"tarball": tarball_url(package, package_file) tarball: tarball_url(package, package_file)
} }
} }
end end
...@@ -43,4 +49,9 @@ class NpmPackagePresenter ...@@ -43,4 +49,9 @@ class NpmPackagePresenter
"/packages/npm/#{package.name}" \ "/packages/npm/#{package.name}" \
"/-/#{package_file.file_name}" "/-/#{package_file.file_name}"
end end
def sorted_versions
versions = packages.map(&:version).compact
VersionSorter.sort(versions)
end
end end
---
title: Fix npm registry for yarn
merge_request: 9599
author:
type: fixed
...@@ -630,6 +630,7 @@ module EE ...@@ -630,6 +630,7 @@ module EE
class NpmPackage < Grape::Entity class NpmPackage < Grape::Entity
expose :name expose :name
expose :versions expose :versions
expose :dist_tags, as: 'dist-tags'
end end
class Package < Grape::Entity 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