1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00

refactor: typo fixes (#1030)

* refactor: increasese use of constants

* refactor: fixes after rebase

* refactor: improves variable names
This commit is contained in:
Ayush Sharma 2018-10-02 07:47:46 +02:00 committed by Juan Picado @jotadeveloper
parent d504d28dc4
commit d913145fe2
31 changed files with 98 additions and 184 deletions

@ -6,10 +6,9 @@
import mime from 'mime';
import _ from 'lodash';
import { media, allow } from '../../middleware';
import { DIST_TAGS } from '../../../lib/utils';
import type { Router } from 'express';
import type { IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler } from '../../../../types';
import { API_MESSAGE, HTTP_STATUS } from '../../../lib/constants';
import { API_MESSAGE, HTTP_STATUS, DIST_TAGS } from '../../../lib/constants';
export default function(route: Router, auth: IAuth, storage: IStorageHandler) {
const can = allow(auth);

@ -5,8 +5,8 @@
import _ from 'lodash';
import { allow } from '../../middleware';
import { DIST_TAGS, convertDistRemoteToLocalTarballUrls, getVersion, ErrorCode } from '../../../lib/utils';
import { HEADERS } from '../../../lib/constants';
import { convertDistRemoteToLocalTarballUrls, getVersion, ErrorCode } from '../../../lib/utils';
import { HEADERS, DIST_TAGS } from '../../../lib/constants';
import type { Router } from 'express';
import type { Config } from '@verdaccio/types';
import type { IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler } from '../../../../types';

@ -7,8 +7,8 @@ import _ from 'lodash';
import Path from 'path';
import mime from 'mime';
import { API_MESSAGE, HEADERS } from '../../../lib/constants';
import { DIST_TAGS, validateMetadata, isObject, ErrorCode } from '../../../lib/utils';
import { API_MESSAGE, HEADERS, DIST_TAGS } from '../../../lib/constants';
import { validateMetadata, isObject, ErrorCode } from '../../../lib/utils';
import { media, expectJson, allow } from '../../middleware';
import { notify } from '../../../lib/notify';

@ -24,7 +24,6 @@ import type { Config as IConfig, IPluginMiddleware } from '@verdaccio/types';
const LoggerApp = require('../lib/logger');
const Middleware = require('./middleware');
const Cats = require('../lib/status-cats');
const defineAPI = function(config: IConfig, storage: IStorageHandler) {
const auth: IAuth = new Auth(config);
@ -41,7 +40,7 @@ const defineAPI = function(config: IConfig, storage: IStorageHandler) {
res.setHeader('X-Powered-By', config.user_agent);
next();
});
app.use(Cats.middleware);
app.use(compression());
app.get('/favicon.ico', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {

@ -4,8 +4,9 @@
*/
import _ from 'lodash';
import { addScope, addGravatarSupport, deleteProperties, sortByName, DIST_TAGS, parseReadme } from '../../../lib/utils';
import { addScope, addGravatarSupport, deleteProperties, sortByName, parseReadme } from '../../../lib/utils';
import { allow } from '../../middleware';
import { DIST_TAGS } from '../../../lib/constants';
import type { Router } from 'express';
import type { IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler, $SidebarPackage } from '../../../../types';

@ -4,7 +4,7 @@
*/
import Search from '../../../lib/search';
import { DIST_TAGS } from '../../../lib/utils';
import { DIST_TAGS } from '../../../lib/constants';
import type { Router } from 'express';
import type { IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler } from '../../../../types';

@ -47,7 +47,7 @@ commander
.parse(process.argv);
if (commander.args.length == 1 && !commander.config) {
// handling "verdaccio [config]" case if "-c" is missing in commandline
// handling "verdaccio [config]" case if "-c" is missing in command line
commander.config = commander.args.pop();
}
@ -56,7 +56,7 @@ if (commander.args.length !== 0) {
}
let verdaccioConfiguration;
let configPathLocation;
const cliListner = commander.listen;
const cliListener = commander.listen;
try {
configPathLocation = findConfigFile(commander.config);
@ -72,7 +72,7 @@ try {
logger.logger.warn({file: configPathLocation}, 'config file - @{file}');
startVerdaccio(verdaccioConfiguration, cliListner, configPathLocation, pkgVersion, pkgName, listenDefaultCallback);
startVerdaccio(verdaccioConfiguration, cliListener, configPathLocation, pkgVersion, pkgName, listenDefaultCallback);
} catch (err) {
logger.logger.fatal({file: configPathLocation, err: err}, 'cannot open config file @{file}: @{!err.message}');
process.exit(1);

@ -30,7 +30,7 @@ function findConfigFile(configPath: any) {
const configPaths = getConfigPaths();
if (_.isEmpty(configPaths)) {
throw new Error('no configuration files can be proccesed');
throw new Error('no configuration files can be processed');
}
const primaryConf: any = _.find(configPaths, (configLocation: any) => fileExists(configLocation.path));

@ -21,10 +21,10 @@ const BLACKLIST = {
};
/**
* Normalise user list.
* Normalize user list.
* @return {Array}
*/
export function normalizeUserlist(oldFormat: any, newFormat: any) {
export function normalizeUserList(oldFormat: any, newFormat: any) {
const result = [];
/* eslint prefer-rest-params: "off" */
@ -117,11 +117,11 @@ export function normalisePackageAccess(packages: PackageList): PackageList {
for (let pkg in packages) {
if (Object.prototype.hasOwnProperty.call(packages, pkg)) {
assert(_.isObject(packages[pkg]) && _.isArray(packages[pkg]) === false, `CONFIG: bad "'${pkg}'" package description (object expected)`);
normalizedPkgs[pkg].access = normalizeUserlist(packages[pkg].allow_access, packages[pkg].access);
normalizedPkgs[pkg].access = normalizeUserList(packages[pkg].allow_access, packages[pkg].access);
delete normalizedPkgs[pkg].allow_access;
normalizedPkgs[pkg].publish = normalizeUserlist(packages[pkg].allow_publish, packages[pkg].publish);
normalizedPkgs[pkg].publish = normalizeUserList(packages[pkg].allow_publish, packages[pkg].publish);
delete normalizedPkgs[pkg].allow_publish;
normalizedPkgs[pkg].proxy = normalizeUserlist(packages[pkg].proxy_access, packages[pkg].proxy);
normalizedPkgs[pkg].proxy = normalizeUserList(packages[pkg].proxy_access, packages[pkg].proxy);
delete normalizedPkgs[pkg].proxy_access;
}
}

@ -96,7 +96,7 @@ class Config implements AppConfig {
}
/**
* Store or create whether recieve a secret key
* Store or create whether receive a secret key
*/
checkSecretKey(secret: string): string {
if (_.isString(secret) && _.isEmpty(secret) === false) {
@ -104,7 +104,7 @@ class Config implements AppConfig {
return secret;
}
// it generates a secret key
// FUTURE: this might be an external secret key, perhaps whitin config file?
// FUTURE: this might be an external secret key, perhaps within config file?
this.secret = generateRandomHexString(32);
return this.secret;
}

@ -129,3 +129,10 @@ export const PACKAGE_ACCESS = {
export const UPDATE_BANNER = {
CHANGELOG_URL: 'https://github.com/verdaccio/verdaccio/releases/tag/',
};
export const STORAGE = {
PACKAGE_FILE_NAME: 'package.json',
FILE_EXIST_ERROR: 'EEXISTS',
NO_SUCH_FILE_ERROR: 'ENOENT',
DEFAULT_REVISION: '0-0000000000000000',
};

@ -38,7 +38,7 @@ export function createTarballHash() {
}
/**
* Express doesn't do etags with requests <= 1024b
* Express doesn't do ETAGS with requests <= 1024b
* we use md5 here, it works well on 1k+ bytes, but sucks with fewer data
* could improve performance using crc32 after benchmarks.
* @param {Object} data

@ -3,25 +3,13 @@
* @flow
*/
/* eslint prefer-rest-params: 0 */
import assert from 'assert';
import UrlNode from 'url';
import _ from 'lodash';
// $FlowFixMe
import { ErrorCode, isObject, getLatestVersion, tagVersion, validateName, DIST_TAGS } from './utils';
import {
generatePackageTemplate,
normalizePackage,
generateRevision,
getLatestReadme,
cleanUpReadme,
normalizeContributors,
fileExist,
noSuchFile,
DEFAULT_REVISION,
pkgFileName,
} from './storage-utils';
import { ErrorCode, isObject, getLatestVersion, tagVersion, validateName } from './utils';
import { generatePackageTemplate, normalizePackage, generateRevision, getLatestReadme, cleanUpReadme, normalizeContributors } from './storage-utils';
import { API_ERROR, DIST_TAGS, STORAGE } from './constants';
import { createTarballHash } from './crypto-utils';
import { prepareSearchPackage } from './storage-utils';
import loadPlugin from '../lib/plugin-loader';
@ -31,7 +19,6 @@ import type { Package, Config, MergeTags, Version, DistFile, Callback, Logger }
import type { ILocalData, IPackageStorage } from '@verdaccio/local-storage';
import type { IUploadTarball, IReadTarball } from '@verdaccio/streams';
import type { IStorage, StringValue } from '../../types';
import { API_ERROR } from './constants';
/**
* Implements Storage interface (same for storage.js, local-storage.js, up-storage.js).
@ -55,7 +42,7 @@ class LocalStorage implements IStorage {
}
storage.createPackage(name, generatePackageTemplate(name), err => {
if (_.isNull(err) === false && err.code === fileExist) {
if (_.isNull(err) === false && err.code === STORAGE.FILE_EXIST_ERROR) {
return callback(ErrorCode.getConflict());
}
@ -83,7 +70,7 @@ class LocalStorage implements IStorage {
storage.readPackage(name, (err, data) => {
if (_.isNil(err) === false) {
if (err.code === noSuchFile) {
if (err.code === STORAGE.NO_SUCH_FILE_ERROR) {
return callback(ErrorCode.getNotFound());
} else {
return callback(err);
@ -98,7 +85,7 @@ class LocalStorage implements IStorage {
return callback(ErrorCode.getBadData(removeFailed.message));
}
storage.deletePackage(pkgFileName, err => {
storage.deletePackage(STORAGE.PACKAGE_FILE_NAME, err => {
if (err) {
return callback(err);
}
@ -132,7 +119,7 @@ class LocalStorage implements IStorage {
if (_.isNil(packageLocalJson.versions[versionId])) {
let version = packageInfo.versions[versionId];
// we don't keep readmes for package versions,
// we don't keep readme for package versions,
// only one readme per package
version = cleanUpReadme(version);
version.contributors = normalizeContributors(version.contributors);
@ -416,7 +403,7 @@ class LocalStorage implements IStorage {
_transform.apply(uploadStream, arguments);
};
if (name === pkgFileName || name === '__proto__') {
if (name === STORAGE.PACKAGE_FILE_NAME || name === '__proto__') {
process.nextTick(() => {
uploadStream.emit('error', ErrorCode.getForbidden());
});
@ -433,10 +420,10 @@ class LocalStorage implements IStorage {
const writeStream: IUploadTarball = storage.writeTarball(filename);
writeStream.on('error', err => {
if (err.code === fileExist) {
if (err.code === STORAGE.FILE_EXIST_ERROR) {
uploadStream.emit('error', ErrorCode.getConflict());
uploadStream.abort();
} else if (err.code === noSuchFile) {
} else if (err.code === STORAGE.NO_SUCH_FILE_ERROR) {
// check if package exists to throw an appropriate message
this.getPackageMetadata(name, function(_err, res) {
if (_err) {
@ -543,7 +530,7 @@ class LocalStorage implements IStorage {
};
readTarballStream.on('error', function(err) {
if (err && err.code === noSuchFile) {
if (err && err.code === STORAGE.NO_SUCH_FILE_ERROR) {
stream.emit('error', e404('no such file available'));
} else {
stream.emit('error', err);
@ -633,10 +620,10 @@ class LocalStorage implements IStorage {
_readPackage(name: string, storage: any, callback: Callback) {
storage.readPackage(name, (err, result) => {
if (err) {
if (err.code === noSuchFile) {
if (err.code === STORAGE.NO_SUCH_FILE_ERROR) {
return callback(ErrorCode.getNotFound());
} else {
return callback(this._internalError(err, pkgFileName, 'error reading'));
return callback(this._internalError(err, STORAGE.PACKAGE_FILE_NAME, 'error reading'));
}
}
@ -697,10 +684,10 @@ class LocalStorage implements IStorage {
storage.readPackage(pkgName, (err, data) => {
// TODO: race condition
if (_.isNil(err) === false) {
if (err.code === noSuchFile) {
if (err.code === STORAGE.NO_SUCH_FILE_ERROR) {
data = generatePackageTemplate(pkgName);
} else {
return callback(this._internalError(err, pkgFileName, 'error reading'));
return callback(this._internalError(err, STORAGE.PACKAGE_FILE_NAME, 'error reading'));
}
}
@ -757,9 +744,9 @@ class LocalStorage implements IStorage {
}
_setDefaultRevision(json: Package) {
// calculate revision a la couchdb
// calculate revision from couch db
if (_.isString(json._rev) === false) {
json._rev = DEFAULT_REVISION;
json._rev = STORAGE.DEFAULT_REVISION;
}
// this is intended in debug mode we do not want modify the store revision

@ -17,7 +17,7 @@ const { format } = require('date-fns');
* @param {*} x severity level
* @return {String} security level
*/
function getlvl(x) {
function calculateLevel(x) {
switch (true) {
case x < 15:
return 'trace';
@ -107,12 +107,12 @@ function setup(logs) {
}
if (target.format === 'pretty') {
// making fake stream for prettypritting
// making fake stream for pretty printing
stream.write = obj => {
destination.write(`${print(obj.level, obj.msg, obj, destinationIsTTY)}\n`);
};
} else if (target.format === 'pretty-timestamped') {
// making fake stream for pretty pritting
// making fake stream for pretty printing
stream.write = obj => {
destination.write(`[${format(obj.time, 'YYYY-MM-DD HH:mm:ss')}] ${print(obj.level, obj.msg, obj, destinationIsTTY)}\n`);
};
@ -226,9 +226,9 @@ function fillInMsgTemplate(msg, obj, colors) {
*/
function print(type, msg, obj, colors) {
if (typeof type === 'number') {
type = getlvl(type);
type = calculateLevel(type);
}
const finalmsg = fillInMsgTemplate(msg, obj, colors);
const finalMessage = fillInMsgTemplate(msg, obj, colors);
const subsystems = [
{
@ -247,9 +247,9 @@ function print(type, msg, obj, colors) {
const sub = subsystems[colors ? 0 : 1][obj.sub] || subsystems[+!colors].default;
if (colors) {
return ` ${levels[type](pad(type))}${chalk.white(`${sub} ${finalmsg}`)}`;
return ` ${levels[type](pad(type))}${chalk.white(`${sub} ${finalMessage}`)}`;
} else {
return ` ${pad(type)}${sub} ${finalmsg}`;
return ` ${pad(type)}${sub} ${finalMessage}`;
}
}

@ -5,7 +5,7 @@
import semver from 'semver';
import _ from 'lodash';
import { DIST_TAGS } from './utils';
import { DIST_TAGS } from './constants';
import type { Package } from '@verdaccio/types';

@ -45,7 +45,7 @@ function isES6(plugin) {
* and sinopia-ldap. All verdaccio prefix will have preferences.
* @param {*} config a reference of the configuration settings
* @param {*} pluginConfigs
* @param {*} params a set of params to initialise the plugin
* @param {*} params a set of params to initialize the plugin
* @param {*} sanityCheck callback that check the shape that should fulfill the plugin
* @return {Array} list of plugins
*/
@ -91,12 +91,15 @@ export default function loadPlugin<T>(config: Config, pluginConfigs: any = {}, p
if (plugin === null) {
logger.logger.error({ content: pluginId }, 'plugin not found. try npm install verdaccio-@{content}');
throw Error('"' + pluginId + '" plugin not found\ntry "npm install verdaccio-' + pluginId + '"');
throw Error(`
${pluginId} plugin not found.
try "npm install verdaccio-'${pluginId}
`);
}
if (!isValid(plugin)) {
logger.logger.error({ content: pluginId }, "@{content} doesn't look like a valid plugin");
throw Error('"' + pluginId + '" doesn\'t look like a valid plugin');
throw Error(`"${pluginId}" is not a valid plugin`);
}
/* eslint new-cap:off */
plugin = isES6(plugin) ? new plugin.default(mergeConfig(config, pluginConfigs[pluginId]), params) : plugin(pluginConfigs[pluginId], params);
@ -104,8 +107,9 @@ export default function loadPlugin<T>(config: Config, pluginConfigs: any = {}, p
if (plugin === null || !sanityCheck(plugin)) {
logger.logger.error({ content: pluginId }, "@{content} doesn't look like a valid plugin");
throw Error('"' + pluginId + '" doesn\'t look like a valid plugin');
throw Error(`"${pluginId}" is not a valid plugin`);
}
logger.logger.warn({ content: pluginId }, 'Plugin successfully loaded: @{content}');
return plugin;
});

@ -69,12 +69,15 @@ class Search implements IWebSearch {
}
/**
* Force a reindex.
* Force a re-index.
*/
reindex() {
let self = this;
this.storage.getLocalDatabase(function(err, packages) {
if (err) throw err; // that function shouldn't produce any
this.storage.getLocalDatabase(function(error, packages) {
if (error) {
// that function shouldn't produce any
throw error;
}
let i = packages.length;
while (i--) {
self.add(packages[i]);

@ -1,74 +0,0 @@
// see https://secure.flickr.com/photos/girliemac/sets/72157628409467125
const images = {
100: 'aVvDhR', // '6512768893', // 100 - Continue
101: 'aXXExP', // '6540479029', // 101 - Switching Protocols
200: 'aVuVsF', // '6512628175', // 200 - OK
201: 'aXWm1Z', // '6540221577', // 201 - Created
202: 'aXXEyF', // '6540479079', // 202 - Accepted
204: 'aYyJ7B', // '6547319943', // 204 - No Content
206: 'aVEnUP', // '6514473163', // 206 - Partial Content
207: 'aVEnRD', // '6514472979', // 207 - Multi-Status
300: 'aW7mac', // '6519540181', // 300 - Multiple Choices
301: 'aW7mb4', // '6519540231', // 301 - Moved Permanently
302: 'aV6jKp', // '6508023829', // 302 - Found
303: 'aVxtaK', // '6513125065', // 303 - See Other
304: 'aXY3dH', // '6540551929', // 304 - Not Modified
305: 'aXX5LK', // '6540365403', // 305 - Use Proxy
307: 'aVwQnk', // '6513001269', // 307 - Temporary Redirect
400: 'aXYDeT', // '6540669737', // 400 - Bad Request
401: 'aV6jwe', // '6508023065', // 401 - Unauthorized
402: 'aVwQoe', // '6513001321', // 402 - Payment Required
403: 'aV6jFK', // '6508023617', // 403 - Forbidden
404: 'aV6juR', // '6508022985', // 404 - Not Found
405: 'aV6jE8', // '6508023523', // 405 - Method Not Allowed
406: 'aV6jxa', // '6508023119', // 406 - Not Acceptable
408: 'aV6jyc', // '6508023179', // 408 - Request Timeout
409: 'aV6jzz', // '6508023259', // 409 - Conflict
410: 'aVES2H', // '6514567755', // 410 - Gone
411: 'aXYVpT', // '6540724141', // 411 - Length Required
413: 'aV6jHZ', // '6508023747', // 413 - Request Entity Too Large
414: 'aV6jBa', // '6508023351', // 414 - Request-URI Too Long
416: 'aVxQvr', // '6513196851', // 416 - Requested Range Not Satisfiable
417: 'aV6jGP', // '6508023679', // 417 - Expectation Failed
418: 'aV6J7c', // '6508102407', // 418 - I'm a teapot
422: 'aVEnTt', // '6514473085', // 422 - Unprocessable Entity
423: 'aVEyVZ', // '6514510235', // 423 - Locked
424: 'aVEWZ6', // '6514584423', // 424 - Failed Dependency
425: 'aXYdzH', // '6540586787', // 425 - Unordered Collection
426: 'aVdo4M', // '6509400771', // 426 - Upgrade Required
429: 'aVdo8F', // '6509400997', // 429 - Too Many Requests
431: 'aVdo3n', // '6509400689', // 431 - Request Header Fields Too Large
444: 'aVdo1P', // '6509400599', // 444 - No Response
450: 'aVxtbK', // '6513125123', // 450 - Blocked by Windows Parental Controls
451: 'eTiGQd', // '9113233540', // 451 - Unavailable for Legal Reasons
500: 'aVdo6e', // '6509400855', // 500 - Internal Server Error
502: 'aV6jCv', // '6508023429', // 502 - Bad Gateway
503: 'aXYvop', // '6540643319', // 503 - Service Unavailable
506: 'aXYvnH', // '6540643279', // 506 - Variant Also Negotiates
507: 'aVdnZa', // '6509400503', // 507 - Insufficient Storage
508: 'aVdnYa', // '6509400445', // 508 - Loop Detected
509: 'aXXg1V', // '6540399865', // 509 - Bandwidth Limit Exceeded
599: 'aVdo7v', // '6509400929', // 599 - Network connect timeout error
};
module.exports.get_image = function(status) {
if (status in images) {
return 'http://flic.kr/p/' + images[status];
// return 'https://secure.flickr.com/photos/girliemac/'+images[status]+'/in/set-72157628409467125/lightbox/'
}
};
module.exports.middleware = function(req, res, next) {
let _writeHead = res.writeHead;
res.writeHead = function(status) {
if (status in images) {
res.setHeader('X-Status-Cat', module.exports.get_image(status));
}
/* eslint prefer-rest-params: "off" */
_writeHead.apply(res, arguments);
};
next();
};

@ -4,20 +4,15 @@
*/
import _ from 'lodash';
import { ErrorCode, isObject, normalizeDistTags, DIST_TAGS, semverSort } from './utils';
import { ErrorCode, isObject, normalizeDistTags, semverSort } from './utils';
import Search from './search';
import { generateRandomHexString } from '../lib/crypto-utils';
import type { Package, Version, Author } from '@verdaccio/types';
import type { IStorage } from '../../types';
import { API_ERROR, HTTP_STATUS } from './constants';
import { API_ERROR, HTTP_STATUS, DIST_TAGS, STORAGE } from './constants';
const pkgFileName = 'package.json';
const fileExist: string = 'EEXISTS';
const noSuchFile: string = 'ENOENT';
export const DEFAULT_REVISION: string = `0-0000000000000000`;
const generatePackageTemplate = function(name: string): Package {
export function generatePackageTemplate(name: string): Package {
return {
// standard things
name,
@ -29,13 +24,13 @@ const generatePackageTemplate = function(name: string): Package {
_attachments: {},
_rev: '',
};
};
}
/**
* Normalise package properties, tags, revision id.
* Normalize package properties, tags, revision id.
* @param {Object} pkg package reference.
*/
function normalizePackage(pkg: Package) {
export function normalizePackage(pkg: Package) {
const pkgProperties = ['versions', 'dist-tags', '_distfiles', '_attachments', '_uplinks', 'time'];
pkgProperties.forEach(key => {
@ -47,7 +42,7 @@ function normalizePackage(pkg: Package) {
});
if (_.isString(pkg._rev) === false) {
pkg._rev = DEFAULT_REVISION;
pkg._rev = STORAGE.DEFAULT_REVISION;
}
// normalize dist-tags
@ -56,13 +51,13 @@ function normalizePackage(pkg: Package) {
return pkg;
}
function generateRevision(rev: string): string {
export function generateRevision(rev: string): string {
const _rev = rev.split('-');
return (+_rev[0] || 0) + 1 + '-' + generateRandomHexString();
}
function getLatestReadme(pkg: Package): string {
export function getLatestReadme(pkg: Package): string {
const versions = pkg['versions'] || {};
const distTags = pkg['dist-tags'] || {};
const latestVersion = distTags['latest'] ? versions[distTags['latest']] || {} : {};
@ -82,7 +77,7 @@ function getLatestReadme(pkg: Package): string {
return readme;
}
function cleanUpReadme(version: Version): Version {
export function cleanUpReadme(version: Version): Version {
if (_.isNil(version) === false) {
delete version.readme;
}
@ -217,5 +212,3 @@ export function prepareSearchPackage(data: Package, time: mixed) {
return pkg;
}
}
export { generatePackageTemplate, normalizePackage, generateRevision, getLatestReadme, cleanUpReadme, fileExist, noSuchFile, pkgFileName };

@ -9,13 +9,13 @@ import async from 'async';
import Stream from 'stream';
import ProxyStorage from './up-storage';
import Search from './search';
import { API_ERROR, HTTP_STATUS } from './constants';
import { API_ERROR, HTTP_STATUS, DIST_TAGS } from './constants';
import LocalStorage from './local-storage';
import { ReadTarball } from '@verdaccio/streams';
import { checkPackageLocal, publishPackage, checkPackageRemote, cleanUpLinksRef, mergeUplinkTimeIntoLocal, generatePackageTemplate } from './storage-utils';
import { setupUpLinks, updateVersionsHiddenUpLink } from './uplink-util';
import { mergeVersions } from './metadata-utils';
import { ErrorCode, normalizeDistTags, validateMetadata, isObject, DIST_TAGS } from './utils';
import { ErrorCode, normalizeDistTags, validateMetadata, isObject } from './utils';
import type { IStorage, IProxy, IStorageHandler, ProxyList, StringValue } from '../../types';
import type { Versions, Package, Config, MergeTags, Version, DistFile, Callback, Logger } from '@verdaccio/types';
import type { IReadTarball, IUploadTarball } from '@verdaccio/streams';
@ -111,7 +111,7 @@ class Storage implements IStorageHandler {
/**
* Upload a tarball for {name} package
Function is syncronous and returns a WritableStream
Function is synchronous and returns a WritableStream
Used storages: local (write)
*/
addTarball(name: string, filename: string): IUploadTarball {
@ -120,7 +120,7 @@ class Storage implements IStorageHandler {
/**
Get a tarball from a storage for {name} package
Function is syncronous and returns a ReadableStream
Function is synchronous and returns a ReadableStream
Function tries to read tarball locally, if it fails then it reads package
information in order to figure out where we can get this tarball from
Used storages: local || uplink (just one)

@ -20,7 +20,7 @@ const encode = function(thing) {
return encodeURIComponent(thing).replace(/^%40/, '@');
};
const jsonContentType = HEADERS.JSON;
const contenTypeAccept = `${jsonContentType};`;
const contentTypeAccept = `${jsonContentType};`;
/**
* Just a helper (`config[key] || default` doesn't work because of zeroes)
@ -262,7 +262,7 @@ class ProxyStorage implements IProxy {
const acceptEncoding = 'Accept-Encoding';
const userAgent = 'User-Agent';
headers[accept] = headers[accept] || contenTypeAccept;
headers[accept] = headers[accept] || contentTypeAccept;
headers[acceptEncoding] = headers[acceptEncoding] || 'gzip';
// registry.npmjs.org will only return search result if user-agent include string 'npm'
headers[userAgent] = headers[userAgent] || `npm (${this.userAgent})`;
@ -408,7 +408,7 @@ class ProxyStorage implements IProxy {
const headers = {};
if (_.isNil(options.etag) === false) {
headers['If-None-Match'] = options.etag;
headers['Accept'] = contenTypeAccept;
headers['Accept'] = contentTypeAccept;
}
this.request(
@ -451,7 +451,7 @@ class ProxyStorage implements IProxy {
uri_full: url,
encoding: null,
headers: {
Accept: contenTypeAccept,
Accept: contentTypeAccept,
},
});

@ -12,7 +12,7 @@ import URL from 'url';
import createError from 'http-errors';
import marked from 'marked';
import { HTTP_STATUS, API_ERROR, DEFAULT_PORT, DEFAULT_DOMAIN, DEFAULT_PROTOCOL, CHARACTER_ENCODING, HEADERS } from './constants';
import { HTTP_STATUS, API_ERROR, DEFAULT_PORT, DEFAULT_DOMAIN, DEFAULT_PROTOCOL, CHARACTER_ENCODING, HEADERS, DIST_TAGS } from './constants';
import { generateGravatarUrl, GRAVATAR_DEFAULT } from '../utils/user';
import type { Package } from '@verdaccio/types';
@ -25,8 +25,6 @@ const pkginfo = require('pkginfo')(module); // eslint-disable-line no-unused-var
const pkgVersion = module.exports.version;
const pkgName = module.exports.name;
export const DIST_TAGS = 'dist-tags';
export function getUserAgent(): string {
assert(_.isString(pkgName));
assert(_.isString(pkgVersion));

@ -3,11 +3,10 @@
import fs from 'fs';
import path from 'path';
import {createTarballHash} from "../../../src/lib/crypto-utils";
import {HTTP_STATUS} from "../../../src/lib/constants";
import { HTTP_STATUS, DIST_TAGS} from "../../../src/lib/constants";
import {CREDENTIALS, DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, TARBALL} from "../config.functional";
import whoIam from './whoIam';
import ping from './ping';
import {DIST_TAGS} from '../../../src/lib/utils';
function readfile(folderPath) {
return fs.readFileSync(path.join(__dirname, '/', folderPath));

@ -1,7 +1,7 @@
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2} from '../config.functional';
import {generateSha} from '../lib/test.utils';
import {DIST_TAGS} from "../../../src/lib/utils";
import {DIST_TAGS} from "../../../src/lib/constants";
export default function(server, server2) {
const SCOPE = '@test/scoped';

@ -3,7 +3,7 @@ import {createTarballHash} from "../../../src/lib/crypto-utils";
import {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.functional';
import generatePkg from '../fixtures/package';
import {DIST_TAGS} from '../../../src/lib/utils';
import {DIST_TAGS} from '../../../src/lib/constants';
function getBinary() {
return readFile('../fixtures/binary');

@ -1,7 +1,7 @@
import {generateSha} from '../lib/test.utils';
import {API_MESSAGE, HTTP_STATUS} from '../../../src/lib/constants';
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.functional';
import {DIST_TAGS} from '../../../src/lib/utils';
import {DIST_TAGS} from '../../../src/lib/constants';
const pkgExample = require('./dist-tags-merge.json');

@ -9,10 +9,9 @@ import forbiddenPlace from '../partials/forbidden-place';
import Config from '../../../src/lib/config';
import endPointAPI from '../../../src/api/index';
import {HEADERS, API_ERROR, HTTP_STATUS, HEADER_TYPE, API_MESSAGE} from '../../../src/lib/constants';
import { HEADERS, API_ERROR, HTTP_STATUS, HEADER_TYPE, API_MESSAGE, DIST_TAGS} from '../../../src/lib/constants';
import {mockServer} from './mock';
import {DOMAIN_SERVERS} from '../../functional/config.functional';
import {DIST_TAGS} from '../../../src/lib/utils';
require('../../../src/lib/logger').setup([]);
const credentials = { name: 'Jota', password: 'secretPass' };

@ -15,8 +15,7 @@ const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/par
import type {Config, MergeTags} from '@verdaccio/types';
import type {IStorage} from '../../../types/index';
import {API_ERROR, HTTP_STATUS} from '../../../src/lib/constants';
import {DIST_TAGS} from '../../../src/lib/utils';
import { API_ERROR, HTTP_STATUS, DIST_TAGS} from '../../../src/lib/constants';
setup([]);

@ -43,7 +43,7 @@ describe('plugin loader', () => {
return p.authenticate || p.allow_access || p.allow_publish;
});
} catch(e) {
expect(e.message).toEqual(`"${relativePath}/invalid-plugin" doesn\'t look like a valid plugin`);
expect(e.message).toEqual(`"${relativePath}/invalid-plugin" is not a valid plugin`);
}
});
@ -54,7 +54,7 @@ describe('plugin loader', () => {
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
});
} catch(err) {
expect(err.message).toEqual(`"${relativePath}/invalid-plugin-sanity" doesn\'t look like a valid plugin`);
expect(err.message).toEqual(`"${relativePath}/invalid-plugin-sanity" is not a valid plugin`);
}
});

@ -1,7 +1,7 @@
// @flow
import {DEFAULT_REVISION, normalizePackage, mergeUplinkTimeIntoLocal} from "../../../src/lib/storage-utils";
import {DIST_TAGS} from "../../../src/lib/utils";
import {normalizePackage, mergeUplinkTimeIntoLocal} from "../../../src/lib/storage-utils";
import { STORAGE, DIST_TAGS } from '../../../src/lib/constants';
import {readFile} from "../../functional/lib/test.utils";
import type {Package} from '@verdaccio/types';
@ -44,7 +44,7 @@ describe('Storage Utils', () => {
const pkg = normalizePackage(readMetadata('metadata'));
expect(pkg).toBeDefined();
expect(pkg._rev).toBeDefined();
expect(pkg._rev).toBe(DEFAULT_REVISION);
expect(pkg._rev).toBe(STORAGE.DEFAULT_REVISION);
});
});

@ -10,12 +10,12 @@ import {
addGravatarSupport,
validatePackage,
validateMetadata,
DIST_TAGS,
combineBaseUrl,
getVersion,
normalizeDistTags,
getWebProtocol
} from '../../../src/lib/utils';
import { DIST_TAGS } from '../../../src/lib/constants';
import Logger, { setup } from '../../../src/lib/logger';
import { readFile } from '../../functional/lib/test.utils';