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

Merge branch 'master' into feature-user-info-for-notications

This commit is contained in:
Juan Picado @jotadeveloper 2018-06-12 12:47:22 +02:00 committed by GitHub
commit e5bf9a72df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 67 additions and 110 deletions

View file

@ -22,6 +22,8 @@ aliases:
<<: *node9_executor
- &repo_key
repo-{{ .Branch }}-{{ .Revision }}
- &coverage_key
coverage-{{ .Branch }}-{{ .Revision }}
- &base_config_key
base-config-{{ .Branch }}-{{ .Revision }}
- &yarn_cache_key
@ -108,6 +110,10 @@ jobs:
- run:
name: Test with Node 9
command: yarn run test
- save_cache:
key: *coverage_key
paths:
- coverage
test_node10:
<<: *defaults
@ -132,9 +138,19 @@ jobs:
<<: *default_executor
steps:
- *restore_repo
- restore_cache:
key: *coverage_key
- run:
name: Publish coverage
command: yarn run coverage:publish
- store_artifacts:
path: coverage/clover.xml
prefix: tests
- store_artifacts:
path: coverage
prefix: coverage
- store_test_results:
path: coverage/clover.xml
publish_gh_pages:
<<: *defaults
@ -189,7 +205,11 @@ workflows:
<<: *ignore_branches
- coverage:
requires:
- prepare
- test_node6
- test_node8
- test_node9
- test_node10
- test_e2e
<<: *ignore_branches
- publish_gh_pages:
requires:
@ -198,10 +218,10 @@ workflows:
- test_node9
- test_node10
- test_e2e
- coverage
<<: *ignore_branches
- deploy:
requires:
- coverage
- publish_gh_pages
filters:
branches:

View file

@ -40,6 +40,7 @@
"valid-jsdoc": 0,
"prefer-spread": 1,
"prefer-rest-params": 1,
"linebreak-style": 0,
"quote-props":["error", "as-needed"]
}
}

View file

@ -2,6 +2,17 @@
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.1.2"></a>
## [3.1.2](https://github.com/verdaccio/verdaccio/compare/v3.1.1...v3.1.2) (2018-06-11)
### Bug Fixes
* configure fetch to send cookies ([98ac855](https://github.com/verdaccio/verdaccio/commit/98ac855))
* search implementation depends now of each plugin ([8f0508f](https://github.com/verdaccio/verdaccio/commit/8f0508f))
<a name="3.1.1"></a>
## [3.1.1](https://github.com/verdaccio/verdaccio/compare/v3.1.0...v3.1.1) (2018-06-07)

View file

@ -1,4 +1,4 @@
FROM node:10.1-alpine
FROM node:10.3-alpine
LABEL maintainer="https://github.com/verdaccio/verdaccio"
RUN apk --no-cache add openssl && \

View file

@ -1,6 +1,6 @@
{
"name": "verdaccio",
"version": "3.1.1",
"version": "3.1.2",
"description": "Private npm repository server",
"author": {
"name": "Alex Kocharin",

View file

@ -86,12 +86,11 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth)
req,
callback: function(err: Error, info: $SidebarPackage) {
if (_.isNil(err)) {
const sideBarInfo: any = _.clone(info);
let sideBarInfo: any = _.clone(info);
sideBarInfo.latest = info.versions[info[DIST_TAGS].latest];
info = deleteProperties(['readme', 'versions'], sideBarInfo);
info = addGravatarSupport(sideBarInfo);
next(info);
sideBarInfo = deleteProperties(['readme', '_attachments', '_rev', 'name'], sideBarInfo);
sideBarInfo = addGravatarSupport(sideBarInfo);
next(sideBarInfo);
} else {
res.status(404);
res.end();

View file

@ -11,7 +11,6 @@ import type {IStorage} from '../../types';
const pkgFileName = 'package.json';
const fileExist: string = 'EEXISTS';
const noSuchFile: string = 'ENOENT';
const resourceNotAvailable: string = 'EAGAIN';
const DEFAULT_REVISION: string = `0-0000000000000000`;
const generatePackageTemplate = function(name: string): Package {
@ -19,11 +18,11 @@ const generatePackageTemplate = function(name: string): Package {
// standard things
name,
versions: {},
'dist-tags': {},
time: {},
[DIST_TAGS]: {},
_uplinks: {},
_distfiles: {},
_attachments: {},
_uplinks: {},
_rev: '',
};
};
@ -179,6 +178,14 @@ export function checkPackageRemote(name: string, isAllowPublishOffline: boolean,
});
}
export function mergeTime(localMetadata: Package, remoteMetadata: Package) {
if ('time' in remoteMetadata) {
return Object.assign({}, localMetadata.time, remoteMetadata.time);
}
return localMetadata.time;
}
export function prepareSearchPackage(data: Package, time: mixed) {
const listVersions: Array<string> = Object.keys(data.versions);
const versions: Array<string> = semverSort(listVersions);
@ -189,7 +196,7 @@ export function prepareSearchPackage(data: Package, time: mixed) {
const pkg: any = {
name: version.name,
description: version.description,
'dist-tags': {latest},
[DIST_TAGS]: {latest},
maintainers: version.maintainers || [version.author].filter(Boolean),
author: version.author,
repository: version.repository,
@ -218,6 +225,5 @@ export {
fileExist,
noSuchFile,
pkgFileName,
resourceNotAvailable,
};

View file

@ -8,7 +8,8 @@ import ProxyStorage from './up-storage';
import Search from './search';
import LocalStorage from './local-storage';
import {ReadTarball} from '@verdaccio/streams';
import {checkPackageLocal, publishPackage, checkPackageRemote, cleanUpLinksRef} from './storage-utils';
import {checkPackageLocal, publishPackage, checkPackageRemote, cleanUpLinksRef,
mergeTime, generatePackageTemplate} from './storage-utils';
import {setupUpLinks, updateVersionsHiddenUpLink} from './uplink-util';
import {mergeVersions} from './metadata-utils';
import {ErrorCode, normalizeDistTags, validate_metadata, isObject, DIST_TAGS} from './utils';
@ -26,19 +27,6 @@ import type {
import type {IReadTarball, IUploadTarball} from '@verdaccio/streams';
const LoggerApi = require('../lib/logger');
const getDefaultMetadata = function(name): Package {
const pkgMetadata: Package = {
name,
versions: {},
'dist-tags': {},
_uplinks: {},
_distfiles: {},
_attachments: {},
_rev: '',
};
return pkgMetadata;
};
class Storage implements IStorageHandler {
localStorage: IStorage;
@ -417,9 +405,10 @@ class Storage implements IStorageHandler {
let exists = true;
const self = this;
const upLinks = [];
if (!packageInfo || packageInfo === null) {
exists = false;
packageInfo = getDefaultMetadata(name);
packageInfo = generatePackageTemplate(name);
}
for (let up in this.uplinks) {
@ -467,10 +456,7 @@ class Storage implements IStorageHandler {
fetched: Date.now(),
};
// added to fix verdaccio#73
if ('time' in upLinkResponse) {
packageInfo.time = upLinkResponse.time;
}
packageInfo.time = mergeTime(packageInfo, upLinkResponse);
updateVersionsHiddenUpLink(upLinkResponse.versions, upLink);

View file

@ -2,7 +2,6 @@
import zlib from 'zlib';
import JSONStream from 'JSONStream';
import createError from 'http-errors';
import _ from 'lodash';
import request from 'request';
import Stream from 'stream';
@ -114,7 +113,7 @@ class ProxyStorage implements IProxy {
cb(ErrorCode.get500('uplink is offline'));
}
// $FlowFixMe
streamRead.emit('error', createError('uplink is offline'));
streamRead.emit('error', ErrorCode.get500('uplink is offline'));
});
// $FlowFixMe
streamRead._read = function() {};
@ -415,7 +414,7 @@ class ProxyStorage implements IProxy {
return callback( ErrorCode.get404('package doesn\'t exist on uplink'));
}
if (!(res.statusCode >= 200 && res.statusCode < 300)) {
const error = createError(500, `bad status code: ${res.statusCode}`);
const error = ErrorCode.get500(`bad status code: ${res.statusCode}`);
// $FlowFixMe
error.remoteStatus = res.statusCode;
return callback(error);
@ -448,7 +447,7 @@ class ProxyStorage implements IProxy {
return stream.emit('error', ErrorCode.get404('file doesn\'t exist on uplink'));
}
if (!(res.statusCode >= 200 && res.statusCode < 300)) {
return stream.emit('error', createError(500, 'bad uplink status code: ' + res.statusCode));
return stream.emit('error', ErrorCode.get500(`bad uplink status code: ${res.statusCode}`));
}
if (res.headers['content-length']) {
expected_length = res.headers['content-length'];
@ -469,7 +468,7 @@ class ProxyStorage implements IProxy {
current_length += data.length;
}
if (expected_length && current_length != expected_length) {
stream.emit('error', createError(500, 'content length mismatch'));
stream.emit('error', ErrorCode.get500('content length mismatch'));
}
});
return stream;
@ -498,7 +497,7 @@ class ProxyStorage implements IProxy {
requestStream.on('response', (res) => {
if (!String(res.statusCode).match(/^2\d\d$/)) {
return transformStream.emit('error', createError(500, `bad status code ${res.statusCode} from uplink`));
return transformStream.emit('error', ErrorCode.get500(`bad status code ${res.statusCode} from uplink`));
}
// See https://github.com/request/request#requestoptions-callback

View file

@ -1,10 +1,7 @@
// @flow
import {ErrorCode, isObject, validate_metadata} from './utils';
import ProxyStorage from './up-storage';
import {mergeVersions} from './metadata-utils';
import type {Package, Versions, Config, Logger} from '@verdaccio/types';
import type {Versions, Config} from '@verdaccio/types';
import type {IProxy, ProxyList} from '../../types';
/**
@ -37,69 +34,3 @@ export function updateVersionsHiddenUpLink(versions: Versions, upLink: IProxy) {
}
}
}
export function fetchUplinkMetadata(name: string, packageInfo: Package,
options: any, upLink: any, logger: Logger): Promise<any> {
return new Promise(function(resolve, reject) {
const _options = Object.assign({}, options);
const upLinkMeta = packageInfo._uplinks[upLink.upname];
if (isObject(upLinkMeta)) {
const fetched = upLinkMeta.fetched;
// check whether is too soon to ask for metadata
if (fetched && (Date.now() - fetched) < upLink.maxage) {
return resolve(false);
}
_options.etag = upLinkMeta.etag;
}
upLink.getRemoteMetadata(name, _options, function handleUplinkMetadataResponse(err, upLinkResponse, eTag) {
if (err && err.remoteStatus === 304) {
upLinkMeta.fetched = Date.now();
}
if (err || !upLinkResponse) {
// $FlowFixMe
return reject(err || ErrorCode.get500('no data'));
}
try {
validate_metadata(upLinkResponse, name);
} catch (err) {
logger.error({
sub: 'out',
err: err,
}, 'package.json validating error @{!err.message}\n@{err.stack}');
return reject(err);
}
packageInfo._uplinks[upLink.upname] = {
etag: eTag,
fetched: Date.now(),
};
// added to fix verdaccio#73
if ('time' in upLinkResponse) {
packageInfo.time = upLinkResponse.time;
}
updateVersionsHiddenUpLink(upLinkResponse.versions, upLink);
try {
mergeVersions(packageInfo, upLinkResponse);
} catch (err) {
logger.error({
sub: 'out',
err: err,
}, 'package.json parsing error @{!err.message}\n@{err.stack}');
return reject(err);
}
// if we got to this point, assume that the correct package exists
// on the uplink
resolve(true);
});
});
}

View file

@ -81,6 +81,10 @@ function validate_metadata(object: Package, name: string) {
object['versions'] = {};
}
if (!isObject(object['time'])) {
object['time'] = {};
}
return object;
}

View file

@ -26,6 +26,7 @@ class API {
return fetch(url, {
method,
credentials: 'same-origin',
...options
}).then(handleErrors);
}

View file

@ -609,7 +609,6 @@ describe('endpoint unit test', () => {
const sideBarInfo = res.body;
const latestVersion = publishMetadata.versions[publishMetadata['dist-tags'].latest];
expect(sideBarInfo.name).toBe(latestVersion.name);
expect(sideBarInfo.latest.author).toBeDefined();
expect(sideBarInfo.latest.author.avatar).toMatch(/www.gravatar.com/);
expect(sideBarInfo.latest.author.name).toBe(latestVersion.author.name);