diff --git a/src/lib/config-utils.ts b/src/lib/config-utils.ts deleted file mode 100644 index d31e3827e..000000000 --- a/src/lib/config-utils.ts +++ /dev/null @@ -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; -} diff --git a/src/lib/storage.ts b/src/lib/storage.ts index 563edbcc7..76fc442c7 100644 --- a/src/lib/storage.ts +++ b/src/lib/storage.ts @@ -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'; diff --git a/src/types/index.ts b/src/types/index.ts index 1d1516864..3bc424e64 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -33,8 +33,6 @@ export type LegacyPackageAccess = PackageAccess & { unpublish?: string[]; }; -export type MatchedPackage = PackageAccess | void; - export type JWTPayload = RemoteUser & { password?: string; }; diff --git a/test/unit/modules/utils/config-utils.spec.ts b/test/unit/modules/utils/config-utils.spec.ts deleted file mode 100644 index dabdc37a9..000000000 --- a/test/unit/modules/utils/config-utils.spec.ts +++ /dev/null @@ -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(); - }); - }); -});