0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00
This commit is contained in:
Juan Picado 2024-08-05 07:27:21 +02:00
parent 9790875741
commit f775e05772
7 changed files with 47 additions and 47 deletions

View file

@ -14,7 +14,7 @@ class Search {
public readonly uplinks: ProxyInstanceList; public readonly uplinks: ProxyInstanceList;
public readonly logger: Logger; public readonly logger: Logger;
constructor(config: Config, logger: Logger) { constructor(config: Config, logger: Logger) {
this.logger = logger.child({ module: 'proxy' }); this.logger = logger;
this.uplinks = setupUpLinks(config, this.logger); this.uplinks = setupUpLinks(config, this.logger);
} }

View file

@ -23,7 +23,7 @@ class LocalStorage {
public constructor(config: Config, logger: Logger) { public constructor(config: Config, logger: Logger) {
debug('local storage created'); debug('local storage created');
this.logger = logger.child({ sub: 'fs' }); this.logger = logger;
this.config = config; this.config = config;
// @ts-expect-error // @ts-expect-error
this.storagePlugin = null; this.storagePlugin = null;

View file

@ -104,7 +104,7 @@ class Storage {
private searchService: Search; private searchService: Search;
public constructor(config: Config, logger: Logger) { public constructor(config: Config, logger: Logger) {
this.config = config; this.config = config;
this.logger = logger.child({ module: 'storage' }); this.logger = logger;
this.uplinks = setupUpLinks(config, this.logger); this.uplinks = setupUpLinks(config, this.logger);
this.searchService = new Search(config, this.logger); this.searchService = new Search(config, this.logger);
this.filters = null; this.filters = null;

View file

@ -17,7 +17,7 @@ import {
getConfig, getConfig,
} from './helpers'; } from './helpers';
setup({ type: 'stdout', format: 'pretty', level: 'trace' }); const logger = setup({ type: 'stdout', format: 'pretty', level: 'trace' });
const fakeHost = 'localhost:4873'; const fakeHost = 'localhost:4873';
@ -74,7 +74,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {
@ -119,7 +119,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const ac = new AbortController(); const ac = new AbortController();
setTimeout(() => { setTimeout(() => {
@ -164,7 +164,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
// create a package // create a package
const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0');
@ -253,7 +253,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0');
const bodyNewManifest2 = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest2 = generatePackageMetadata(pkgName, '1.0.0');
@ -290,7 +290,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
@ -320,7 +320,7 @@ describe('storage', () => {
const mockDate = '2018-01-14T11:17:40.712Z'; const mockDate = '2018-01-14T11:17:40.712Z';
MockDate.set(mockDate); MockDate.set(mockDate);
const config = getConfig('deprecate.yaml'); const config = getConfig('deprecate.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {
@ -367,7 +367,7 @@ describe('storage', () => {
const mockDate = '2018-01-14T11:17:40.712Z'; const mockDate = '2018-01-14T11:17:40.712Z';
MockDate.set(mockDate); MockDate.set(mockDate);
const config = getConfig('deprecate.yaml'); const config = getConfig('deprecate.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
// publish new package // publish new package
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
@ -441,7 +441,7 @@ describe('storage', () => {
describe('star', () => { describe('star', () => {
test.each([['foo']])('star package %s', async (pkgName) => { test.each([['foo']])('star package %s', async (pkgName) => {
const config = getConfig('deprecate.yaml'); const config = getConfig('deprecate.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {
@ -474,7 +474,7 @@ describe('storage', () => {
const mockDate = '2018-01-14T11:17:40.712Z'; const mockDate = '2018-01-14T11:17:40.712Z';
MockDate.set(mockDate); MockDate.set(mockDate);
const config = getConfig('deprecate.yaml'); const config = getConfig('deprecate.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {
@ -516,7 +516,7 @@ describe('storage', () => {
const mockDate = '2018-01-14T11:17:40.712Z'; const mockDate = '2018-01-14T11:17:40.712Z';
MockDate.set(mockDate); MockDate.set(mockDate);
const config = getConfig('deprecate.yaml'); const config = getConfig('deprecate.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {
@ -555,7 +555,7 @@ describe('storage', () => {
test.each([['foo']])('should unstar a package %s', async (pkgName) => { test.each([['foo']])('should unstar a package %s', async (pkgName) => {
const config = getConfig('deprecate.yaml'); const config = getConfig('deprecate.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {
@ -592,7 +592,7 @@ describe('storage', () => {
test.each([['foo']])('should handle missing username %s', async (pkgName) => { test.each([['foo']])('should handle missing username %s', async (pkgName) => {
const config = getConfig('deprecate.yaml'); const config = getConfig('deprecate.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {
@ -621,7 +621,7 @@ describe('storage', () => {
['foo', 'publishWithOwnerAndCheck.yaml'], ['foo', 'publishWithOwnerAndCheck.yaml'],
])('new package %s, %s (anonymous)', async (pkgName, configFile) => { ])('new package %s, %s (anonymous)', async (pkgName, configFile) => {
const config = getConfig(configFile); const config = getConfig(configFile);
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {
@ -643,7 +643,7 @@ describe('storage', () => {
['foo', 'publishWithOwnerAndCheck.yaml'], ['foo', 'publishWithOwnerAndCheck.yaml'],
])('new package %s, %s (logged in)', async (pkgName, configFile) => { ])('new package %s, %s (logged in)', async (pkgName, configFile) => {
const config = getConfig(configFile); const config = getConfig(configFile);
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const owner = { name: 'fooUser', email: '' }; const owner = { name: 'fooUser', email: '' };
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
@ -668,7 +668,7 @@ describe('storage', () => {
['foo', 'publishWithOwnerAndCheck.yaml'], ['foo', 'publishWithOwnerAndCheck.yaml'],
])('add/remove owner %s, %s', async (pkgName, configFile) => { ])('add/remove owner %s, %s', async (pkgName, configFile) => {
const config = getConfig(configFile); const config = getConfig(configFile);
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const firstOwner = { name: 'fooUser', email: '' }; const firstOwner = { name: 'fooUser', email: '' };
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
@ -728,7 +728,7 @@ describe('storage', () => {
['foo', 'publishWithOwnerAndCheck.yaml'], ['foo', 'publishWithOwnerAndCheck.yaml'],
])('should fail removing last owner %s, %s', async (pkgName, configFile) => { ])('should fail removing last owner %s, %s', async (pkgName, configFile) => {
const config = getConfig(configFile); const config = getConfig(configFile);
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
const owner = 'fooUser'; const owner = 'fooUser';
@ -756,7 +756,7 @@ describe('storage', () => {
'ok to publish as non-owner without check %s, %s', 'ok to publish as non-owner without check %s, %s',
async (pkgName, configFile) => { async (pkgName, configFile) => {
const config = getConfig(configFile); const config = getConfig(configFile);
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
const owner = 'fooUser'; const owner = 'fooUser';
@ -786,7 +786,7 @@ describe('storage', () => {
'should fail publishing as non-owner with check %s, %s', 'should fail publishing as non-owner with check %s, %s',
async (pkgName, configFile) => { async (pkgName, configFile) => {
const config = getConfig(configFile); const config = getConfig(configFile);
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
const owner = 'fooUser'; const owner = 'fooUser';
@ -823,7 +823,7 @@ describe('storage', () => {
storage: generateRandomStorage(), storage: generateRandomStorage(),
}) })
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
await expect(storage.getLocalDatabase()).resolves.toHaveLength(0); await expect(storage.getLocalDatabase()).resolves.toHaveLength(0);
}); });
@ -843,7 +843,7 @@ describe('storage', () => {
}, },
url: '/', url: '/',
}); });
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const manifest = generatePackageMetadata('foo'); const manifest = generatePackageMetadata('foo');
const ac = new AbortController(); const ac = new AbortController();
@ -881,7 +881,7 @@ describe('storage', () => {
}, },
url: '/', url: '/',
}); });
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const manifest = generatePackageMetadata('foo'); const manifest = generatePackageMetadata('foo');
@ -930,7 +930,7 @@ describe('storage', () => {
test('ok to remove package as non-owner without check', async () => { test('ok to remove package as non-owner without check', async () => {
const config = getConfig('publishWithOwnerDefault.yaml'); const config = getConfig('publishWithOwnerDefault.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const owner = 'fooUser'; const owner = 'fooUser';
const options = { ...defaultRequestOptions, username: owner }; const options = { ...defaultRequestOptions, username: owner };
@ -969,7 +969,7 @@ describe('storage', () => {
test('should fail as non-owner with check', async () => { test('should fail as non-owner with check', async () => {
const config = getConfig('publishWithOwnerAndCheck.yaml'); const config = getConfig('publishWithOwnerAndCheck.yaml');
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const owner = 'fooUser'; const owner = 'fooUser';
const options = { ...defaultRequestOptions, username: owner }; const options = { ...defaultRequestOptions, username: owner };

View file

@ -11,7 +11,7 @@ import { Manifest } from '@verdaccio/types';
import { Storage } from '../src'; import { Storage } from '../src';
import { configExample, generateRandomStorage, getConfig } from './helpers'; import { configExample, generateRandomStorage, getConfig } from './helpers';
setup({ type: 'stdout', format: 'pretty', level: 'trace' }); const logger = setup({ type: 'stdout', format: 'pretty', level: 'trace' });
const pluginsPartialsFolder = path.join(__dirname, './fixtures/plugins'); const pluginsPartialsFolder = path.join(__dirname, './fixtures/plugins');
@ -33,7 +33,7 @@ describe('storage plugin', () => {
}) })
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
await expect(storage.getLocalDatabase()).resolves.toHaveLength(1); await expect(storage.getLocalDatabase()).resolves.toHaveLength(1);
}); });
@ -55,7 +55,7 @@ describe('storage plugin', () => {
storage: generateRandomStorage(), storage: generateRandomStorage(),
}) })
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
await storage.updateManifest(bodyNewManifest, { await storage.updateManifest(bodyNewManifest, {

View file

@ -14,7 +14,7 @@ import { Storage } from '../src';
import manifestFooRemoteNpmjs from './fixtures/manifests/foo-npmjs.json'; import manifestFooRemoteNpmjs from './fixtures/manifests/foo-npmjs.json';
import { configExample, generateRandomStorage } from './helpers'; import { configExample, generateRandomStorage } from './helpers';
setup({ type: 'stdout', format: 'pretty', level: 'trace' }); const logger = setup({ type: 'stdout', format: 'pretty', level: 'trace' });
const fooManifest = generatePackageMetadata('foo', '1.0.0'); const fooManifest = generatePackageMetadata('foo', '1.0.0');
@ -44,7 +44,7 @@ describe('storage', () => {
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
await expect( await expect(
storage.syncUplinksMetadata(fooManifest.name, null, { storage.syncUplinksMetadata(fooManifest.name, null, {
@ -68,7 +68,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
await expect( await expect(
storage.syncUplinksMetadata(fooManifest.name, null, { storage.syncUplinksMetadata(fooManifest.name, null, {
@ -89,7 +89,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const [manifest] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest, { const [manifest] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest, {
retry: { limit: 0 }, retry: { limit: 0 },
@ -111,7 +111,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest); const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest);
@ -152,7 +152,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const [response] = await storage.syncUplinksMetadata(fooManifest.name, null); const [response] = await storage.syncUplinksMetadata(fooManifest.name, null);
@ -174,7 +174,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest); const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest);
@ -198,7 +198,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest, { const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest, {
@ -227,7 +227,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
const [response] = await storage.syncUplinksMetadata('foo', null, { const [response] = await storage.syncUplinksMetadata('foo', null, {

View file

@ -15,7 +15,7 @@ import { Manifest } from '@verdaccio/types';
import { Storage } from '../src'; import { Storage } from '../src';
import { configExample, defaultRequestOptions, generateRandomStorage } from './helpers'; import { configExample, defaultRequestOptions, generateRandomStorage } from './helpers';
setup({ type: 'stdout', format: 'pretty', level: 'trace' }); const logger = setup({ type: 'stdout', format: 'pretty', level: 'trace' });
const fakeHost = 'localhost:4873'; const fakeHost = 'localhost:4873';
@ -35,7 +35,7 @@ describe('storage', () => {
storage: generateRandomStorage(), storage: generateRandomStorage(),
}) })
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
storage.init(config).then(() => { storage.init(config).then(() => {
const ac = new AbortController(); const ac = new AbortController();
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
@ -75,7 +75,7 @@ describe('storage', () => {
storage: generateRandomStorage(), storage: generateRandomStorage(),
}) })
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
storage.init(config).then(() => { storage.init(config).then(() => {
const abort = new AbortController(); const abort = new AbortController();
storage storage
@ -115,7 +115,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
storage.init(config).then(() => { storage.init(config).then(() => {
const abort = new AbortController(); const abort = new AbortController();
storage storage
@ -158,7 +158,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
storage.init(config).then(() => { storage.init(config).then(() => {
const ac = new AbortController(); const ac = new AbortController();
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
@ -221,7 +221,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
storage.init(config).then(() => { storage.init(config).then(() => {
const req = httpMocks.createRequest({ const req = httpMocks.createRequest({
method: 'GET', method: 'GET',
@ -274,7 +274,7 @@ describe('storage', () => {
__dirname __dirname
) )
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
storage.init(config).then(() => { storage.init(config).then(() => {
const ac = new AbortController(); const ac = new AbortController();
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0'); const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
@ -321,7 +321,7 @@ describe('storage', () => {
storage: generateRandomStorage(), storage: generateRandomStorage(),
}) })
); );
const storage = new Storage(config); const storage = new Storage(config, logger);
await storage.init(config); await storage.init(config);
await expect(storage.removeTarball('foo', 'foo-1.0.0.tgz', 'rev', username)).rejects.toThrow( await expect(storage.removeTarball('foo', 'foo-1.0.0.tgz', 'rev', username)).rejects.toThrow(
API_ERROR.NO_PACKAGE API_ERROR.NO_PACKAGE