0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

Merge remote-tracking branch 'origin/master' into 4.x

# Conflicts:
#	package.json
#	yarn.lock
This commit is contained in:
Juan Picado @jotadeveloper 2018-09-27 18:01:57 +02:00
commit 9117673bed
No known key found for this signature in database
GPG key ID: 18AC54485952D158
7 changed files with 115 additions and 37 deletions

View file

@ -2,6 +2,16 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="3.8.2"></a>
## [3.8.2](https://github.com/verdaccio/verdaccio/compare/v3.8.1...v3.8.2) (2018-09-27)
### Bug Fixes
* normalize contributors field [#1022](https://github.com/verdaccio/verdaccio/issues/1022) ([#1024](https://github.com/verdaccio/verdaccio/issues/1024)) ([4deefe7](https://github.com/verdaccio/verdaccio/commit/4deefe7))
<a name="3.8.1"></a>
## [3.8.1](https://github.com/verdaccio/verdaccio/compare/v3.8.0...v3.8.1) (2018-09-10)

View file

@ -1,6 +1,6 @@
{
"name": "verdaccio",
"version": "3.8.1",
"version": "3.8.2",
"description": "Private npm repository server",
"author": {
"name": "Alex Kocharin",
@ -56,7 +56,7 @@
"@commitlint/config-conventional": "7.1.2",
"@material-ui/core": "3.1.0",
"@material-ui/icons": "3.0.1",
"@verdaccio/types": "3.7.1",
"@verdaccio/types": "3.7.2",
"babel-cli": "6.26.0",
"babel-core": "6.26.3",
"babel-eslint": "10.0.0",

View file

@ -8,7 +8,7 @@ import _ from 'lodash';
// $FlowFixMe
import {ErrorCode, isObject, getLatestVersion, tagVersion, validateName, DIST_TAGS} from './utils';
import {
generatePackageTemplate, normalizePackage, generateRevision, getLatestReadme, cleanUpReadme,
generatePackageTemplate, normalizePackage, generateRevision, getLatestReadme, cleanUpReadme, normalizeContributors,
fileExist, noSuchFile, DEFAULT_REVISION, pkgFileName,
} from './storage-utils';
import {createTarballHash} from './crypto-utils';
@ -138,6 +138,7 @@ class LocalStorage implements IStorage {
// we don't keep readmes for package versions,
// only one readme per package
version = cleanUpReadme(version);
version.contributors = normalizeContributors(version.contributors);
change = true;
packageLocalJson.versions[versionId] = version;
@ -219,6 +220,7 @@ class LocalStorage implements IStorage {
// TODO: lodash remove
metadata = cleanUpReadme(metadata);
metadata.contributors = normalizeContributors(metadata.contributors);
if (data.versions[version] != null) {
return cb( ErrorCode.getConflict() );

View file

@ -5,7 +5,7 @@ import {ErrorCode, isObject, normalizeDistTags, DIST_TAGS, semverSort} from './u
import Search from './search';
import {generateRandomHexString} from '../lib/crypto-utils';
import type {Package, Version} from '@verdaccio/types';
import type {Package, Version, Author} from '@verdaccio/types';
import type {IStorage} from '../../types';
import {API_ERROR, HTTP_STATUS} from './constants';
@ -99,7 +99,15 @@ function cleanUpReadme(version: Version): Version {
return version;
}
export const WHITELIST = ['_rev', 'name', 'versions', DIST_TAGS, 'readme', 'time'];
export function normalizeContributors(contributors: Array<Author>): Array<Author> {
if (isObject(contributors) || _.isString(contributors)) {
return [((contributors): any)];
}
return contributors;
}
export const WHITELIST = ['_rev', 'name', 'versions', 'dist-tags', 'readme', 'time'];
export function cleanUpLinksRef(keepUpLinkData: boolean, result: Package): Package {
const propertyToKeep = [...WHITELIST];

View file

@ -17,11 +17,12 @@ import {
DEFAULT_PROTOCOL,
CHARACTER_ENCODING, HEADERS
} from './constants';
import {generateGravatarUrl} from '../utils/user';
import {generateGravatarUrl, GRAVATAR_DEFAULT} from '../utils/user';
import type {Package} from '@verdaccio/types';
import type {$Request} from 'express';
import type {StringValue} from '../../types';
import {normalizeContributors} from './storage-utils';
const Logger = require('./logger');
const pkginfo = require('pkginfo')(module); // eslint-disable-line no-unused-vars
@ -482,7 +483,7 @@ export function deleteProperties(propertiesToDelete: Array<string>, objectItem:
export function addGravatarSupport(pkgInfo: Object): Object {
const pkgInfoCopy = {...pkgInfo};
const author = _.get(pkgInfo, 'latest.author', null);
const contributors = _.get(pkgInfo, 'latest.contributors', []);
const contributors = normalizeContributors(_.get(pkgInfo, 'latest.contributors', []));
const maintainers = _.get(pkgInfo, 'latest.maintainers', []);
// for author.
@ -501,7 +502,17 @@ export function addGravatarSupport(pkgInfo: Object): Object {
// for contributors
if (_.isEmpty(contributors) === false) {
pkgInfoCopy.latest.contributors = contributors.map((contributor) => {
contributor.avatar = generateGravatarUrl(contributor.email);
if (isObject(contributor)) {
// $FlowFixMe
contributor.avatar = generateGravatarUrl(contributor.email);
} else if (_.isString(contributor)) {
contributor = {
avatar: GRAVATAR_DEFAULT,
email: contributor,
name: contributor,
};
}
return contributor;
});
}

View file

@ -396,35 +396,82 @@ describe('Utilities', () => {
expect(addGravatarSupport(packageInfo)).toEqual(packageInfo);
});
test('contributors field has contributors', () => {
const packageInfo = {
latest: {
contributors: [
{ name: 'user', email: 'user@verdccio.org' },
{ name: 'user1', email: 'user1@verdccio.org' }
]
}
};
describe("contributors", () => {
test('contributors field has contributors', () => {
const packageInfo = {
latest: {
contributors: [
{ name: 'user', email: 'user@verdccio.org' },
{ name: 'user1', email: 'user1@verdccio.org' }
]
}
};
const result = {
latest: {
contributors: [
{
avatar:
'https://www.gravatar.com/avatar/794d7f6ef93d0689437de3c3e48fadc7',
email: 'user@verdccio.org',
name: 'user'
},
{
avatar:
'https://www.gravatar.com/avatar/51105a49ce4a9c2bfabf0f6a2cba3762',
email: 'user1@verdccio.org',
name: 'user1'
}
]
}
};
expect(addGravatarSupport(packageInfo)).toEqual(result);
const result = {
latest: {
contributors: [
{
avatar:
'https://www.gravatar.com/avatar/794d7f6ef93d0689437de3c3e48fadc7',
email: 'user@verdccio.org',
name: 'user'
},
{
avatar:
'https://www.gravatar.com/avatar/51105a49ce4a9c2bfabf0f6a2cba3762',
email: 'user1@verdccio.org',
name: 'user1'
}
]
}
};
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
test('contributors field is an object', () => {
const packageInfo = {
latest: {
contributors: { name: 'user', email: 'user@verdccio.org' }
}
};
const result = {
latest: {
contributors: [
{
avatar: 'https://www.gravatar.com/avatar/794d7f6ef93d0689437de3c3e48fadc7',
email: 'user@verdccio.org',
name: 'user'
}
]
}
};
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
test('contributors field is a string', () => {
const contributor: string = 'Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)';
const packageInfo = {
latest: {
contributors: contributor
}
};
const result = {
latest: {
contributors: [
{
avatar: GRAVATAR_DEFAULT,
email: contributor,
name: contributor
}
]
}
};
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
});
test('maintainers field is a blank array', () => {

View file

@ -56,7 +56,7 @@ const users = [
const siteConfig = {
title: 'Verdaccio' /* title for your website */,
tagline: 'Verdaccio · A lightweight private npm proxy registry',
tagline: 'A lightweight private npm proxy registry',
url: 'https://verdaccio.org' /* your website url */,
organizationName: 'verdaccio',
cname: 'verdaccio.org',