mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
chore: cleanup code
This commit is contained in:
parent
514b4db227
commit
62483bc1d0
4 changed files with 1 additions and 121 deletions
|
@ -1,47 +0,0 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
import { PackageList } from '@verdaccio/types';
|
||||
import { getMatchedPackagesSpec } from '@verdaccio/utils';
|
||||
|
||||
import { LegacyPackageList, MatchedPackage } from '../types';
|
||||
import { ErrorCode } from './utils';
|
||||
|
||||
/**
|
||||
* Normalize user list.
|
||||
* @return {Array}
|
||||
*/
|
||||
export function normalizeUserList(oldFormat: any, newFormat: any): any {
|
||||
const result: any[][] = [];
|
||||
/* eslint prefer-rest-params: "off" */
|
||||
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
if (arguments[i] == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if it's a string, split it to array
|
||||
if (_.isString(arguments[i])) {
|
||||
result.push(arguments[i].split(/\s+/));
|
||||
} else if (Array.isArray(arguments[i])) {
|
||||
result.push(arguments[i]);
|
||||
} else {
|
||||
throw ErrorCode.getInternalError(
|
||||
'CONFIG: bad package acl (array or string expected): ' + JSON.stringify(arguments[i])
|
||||
);
|
||||
}
|
||||
}
|
||||
return _.flatten(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an uplink can proxy
|
||||
*/
|
||||
export function hasProxyTo(pkg: string, upLink: string, packages: PackageList): boolean {
|
||||
const matchedPkg: MatchedPackage = getMatchedPackagesSpec(pkg, packages);
|
||||
const proxyList = typeof matchedPkg !== 'undefined' ? matchedPkg.proxy : [];
|
||||
if (proxyList) {
|
||||
return proxyList.some((curr) => upLink === curr);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -4,6 +4,7 @@ import buildDebug from 'debug';
|
|||
import _ from 'lodash';
|
||||
import { PassThrough, pipeline as streamPipeline } from 'stream';
|
||||
|
||||
import { hasProxyTo } from '@verdaccio/config';
|
||||
import { errorUtils, pluginUtils, searchUtils, validatioUtils } from '@verdaccio/core';
|
||||
import { asyncLoadPlugin } from '@verdaccio/loaders';
|
||||
import { IProxy, ProxySearchParams, ProxyStorage } from '@verdaccio/proxy';
|
||||
|
@ -24,7 +25,6 @@ import { GenericBody, Token, TokenFilter } from '@verdaccio/types';
|
|||
|
||||
import { logger } from '../lib/logger';
|
||||
import { IPluginFilters, ISyncUplinks, StringValue } from '../types';
|
||||
import { hasProxyTo } from './config-utils';
|
||||
import { API_ERROR, DIST_TAGS, HTTP_STATUS } from './constants';
|
||||
import LocalStorage from './local-storage';
|
||||
import { mergeVersions } from './metadata-utils';
|
||||
|
|
|
@ -33,8 +33,6 @@ export type LegacyPackageAccess = PackageAccess & {
|
|||
unpublish?: string[];
|
||||
};
|
||||
|
||||
export type MatchedPackage = PackageAccess | void;
|
||||
|
||||
export type JWTPayload = RemoteUser & {
|
||||
password?: string;
|
||||
};
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
import _ from 'lodash';
|
||||
import path from 'path';
|
||||
|
||||
import { normalisePackageAccess } from '@verdaccio/config';
|
||||
|
||||
import { hasProxyTo } from '../../../../src/lib/config-utils';
|
||||
import { parseConfigFile } from '../../../../src/lib/utils';
|
||||
|
||||
describe('Config Utilities', () => {
|
||||
const parseConfigurationFile = (conf) => {
|
||||
const { name, ext } = path.parse(conf);
|
||||
const format = ext.startsWith('.') ? ext.substring(1) : 'yaml';
|
||||
|
||||
return path.join(__dirname, `../../partials/config/${format}/${name}.${format}`);
|
||||
};
|
||||
|
||||
describe('hasProxyTo', () => {
|
||||
test('should test basic config', () => {
|
||||
const packages = normalisePackageAccess(
|
||||
parseConfigFile(parseConfigurationFile('pkgs-basic')).packages
|
||||
);
|
||||
// react
|
||||
expect(hasProxyTo('react', 'facebook', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('react', 'google', packages)).toBeFalsy();
|
||||
// vue
|
||||
expect(hasProxyTo('vue', 'google', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('vue', 'fake', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('vue', 'npmjs', packages)).toBeTruthy();
|
||||
// angular
|
||||
expect(hasProxyTo('angular', 'google', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('angular', 'facebook', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('angular', 'npmjs', packages)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should test resolve based on custom package access', () => {
|
||||
const packages = normalisePackageAccess(
|
||||
parseConfigFile(parseConfigurationFile('pkgs-custom')).packages
|
||||
);
|
||||
// react
|
||||
expect(hasProxyTo('react', 'facebook', packages)).toBeTruthy();
|
||||
expect(hasProxyTo('react', 'google', packages)).toBeFalsy();
|
||||
// vue
|
||||
expect(hasProxyTo('vue', 'google', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('vue', 'fake', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('vue', 'npmjs', packages)).toBeTruthy();
|
||||
// angular
|
||||
expect(hasProxyTo('angular', 'google', packages)).toBeTruthy();
|
||||
expect(hasProxyTo('angular', 'facebook', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('angular', 'npmjs', packages)).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should not resolve any proxy', () => {
|
||||
const packages = normalisePackageAccess(
|
||||
parseConfigFile(parseConfigurationFile('pkgs-empty')).packages
|
||||
);
|
||||
// react
|
||||
expect(hasProxyTo('react', 'npmjs', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('react', 'npmjs', packages)).toBeFalsy();
|
||||
// vue
|
||||
expect(hasProxyTo('vue', 'npmjs', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('vue', 'npmjs', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('vue', 'npmjs', packages)).toBeFalsy();
|
||||
// angular
|
||||
expect(hasProxyTo('angular', 'npmjs', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('angular', 'npmjs', packages)).toBeFalsy();
|
||||
expect(hasProxyTo('angular', 'npmjs', packages)).toBeFalsy();
|
||||
// private
|
||||
expect(hasProxyTo('private', 'fake', packages)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue