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

update middleware, storage

This commit is contained in:
Marc Bernard 2024-11-29 12:12:15 -05:00
parent 3f96f5a5d4
commit e512839341
5 changed files with 19 additions and 13 deletions

View file

@ -2,6 +2,8 @@
'@verdaccio/tarball': patch
'@verdaccio/core': patch
'@verdaccio/utils': patch
'@verdaccio/middleware': patch
'@verdaccio/store': patch
---
chore: move tarball utils to core

View file

@ -2,11 +2,13 @@ import { URL } from 'url';
/**
* Return package version from tarball name
* @param {String} name
*
* test-1.2.4.tgz -> 1.2.4
* @param {String} fileName
* @returns {String}
*/
export function getVersionFromTarball(name: string): string | void {
const groups = name.match(/.+-(\d.+)\.tgz/);
export function getVersionFromTarball(fileName: string): string | void {
const groups = fileName.match(/.+-(\d+\.\d+\.\d+.+)\.tgz$/);
return groups !== null ? groups[1] : undefined;
}
@ -25,6 +27,9 @@ export function extractTarballFromUrl(url: string): string {
/**
* Build the tarball filename from paackage name and version
*
* test, 1.2.4 -> test-1.2.4.tgz
* @scope/name, 1.2.4 -> name-1.2.4.tgz
* @param name package name
* @param version package version
* @returns tarball filename

View file

@ -17,8 +17,9 @@ describe('Utilities', () => {
expect(getVersionFromTarball(otherComplexName)).toEqual('3.5.0-6');
});
test("should don'n fall at incorrect tarball name", () => {
test('should fail at incorrect tarball name', () => {
expect(getVersionFromTarball('incorrectName')).toBeUndefined();
expect(getVersionFromTarball('test-1.2.tgz')).toBeUndefined();
});
});
});
@ -65,11 +66,11 @@ describe('extractTarballFromUrl', () => {
);
});
test('extractTarballName with no tarball should not fails', () => {
test('without tarball should not fails', () => {
expect(extractTarballFromUrl('https://registry.npmjs.org/')).toBe('');
});
test('extractTarballName fails', () => {
test('fails with incomplete URL', () => {
expect(() => extractTarballFromUrl('xxxxregistry.npmjs.org/test/-/test-0.0.2.tgz')).toThrow();
});
});

View file

@ -1,7 +1,6 @@
import buildDebug from 'debug';
import { API_ERROR, errorUtils } from '@verdaccio/core';
import { getVersionFromTarball } from '@verdaccio/utils';
import { API_ERROR, errorUtils, tarballUtils } from '@verdaccio/core';
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
@ -24,7 +23,7 @@ export function allow<T>(
? `@${req.params.scope}/${req.params.package}`
: req.params.package;
const packageVersion = req.params.filename
? getVersionFromTarball(req.params.filename)
? tarballUtils.getVersionFromTarball(req.params.filename)
: req.params.version
? req.params.version
: undefined;

View file

@ -19,9 +19,9 @@ import {
SUPPORT_ERRORS,
USERS,
errorUtils,
pkgUtils,
pluginUtils,
searchUtils,
tarballUtils,
validatioUtils,
} from '@verdaccio/core';
import { asyncLoadPlugin } from '@verdaccio/loaders';
@ -39,7 +39,6 @@ import {
TarballDetails,
convertDistRemoteToLocalTarballUrls,
convertDistVersionToLocalTarballsUrl,
extractTarballFromUrl,
getTarballDetails,
} from '@verdaccio/tarball';
import {
@ -1424,7 +1423,7 @@ class Storage {
// if uploaded tarball has a different shasum, it's very likely that we
// have some kind of error
if (validatioUtils.isObject(metadata.dist) && _.isString(metadata.dist.tarball)) {
const tarball = extractTarballFromUrl(metadata.dist.tarball);
const tarball = tarballUtils.extractTarballFromUrl(metadata.dist.tarball);
if (validatioUtils.isObject(data._attachments[tarball])) {
if (
_.isNil(data._attachments[tarball].shasum) === false &&
@ -1979,7 +1978,7 @@ class Storage {
cacheManifest.versions[versionId] = version;
if (version?.dist?.tarball) {
const filename = pkgUtils.extractTarballName(version.dist.tarball);
const filename = tarballUtils.extractTarballFromUrl(version.dist.tarball);
// store a fast access to the dist file by tarball name
// it does NOT overwrite any existing records
if (_.isNil(cacheManifest?._distfiles[filename])) {