diff --git a/.changeset/violet-boxes-float.md b/.changeset/violet-boxes-float.md new file mode 100644 index 000000000..97f3b61bb --- /dev/null +++ b/.changeset/violet-boxes-float.md @@ -0,0 +1,6 @@ +--- +'@verdaccio/store': patch +'@verdaccio/tarball': patch +--- + +fix(api): add logging when requesting tarball diff --git a/packages/core/tarball/tests/convertDistRemoteToLocalTarballUrls.spec.ts b/packages/core/tarball/tests/convertDistRemoteToLocalTarballUrls.spec.ts index 3fdfd5fd0..902099005 100644 --- a/packages/core/tarball/tests/convertDistRemoteToLocalTarballUrls.spec.ts +++ b/packages/core/tarball/tests/convertDistRemoteToLocalTarballUrls.spec.ts @@ -78,3 +78,41 @@ describe('convertDistRemoteToLocalTarballUrls', () => { ); }); }); + +describe('convertDistRemoteToLocalTarballUrls - scoped', () => { + const fakeHost = 'fake.com'; + const buildURI = (host, version) => `http://${host}/@org/npm_test/-/npm_test-${version}.tgz`; + const cloneMetadata = (pkg = metadata) => Object.assign({}, pkg); + const metadata: any = { + name: '@org/npm_test', + versions: { + '1.0.0': { + dist: { + tarball: 'http://registry.org/@org/npm_test/-/npm_test-1.0.0.tgz', + }, + }, + '1.0.1': { + dist: { + tarball: 'http://registry.org/@org/npm_test/-/npm_test-1.0.1.tgz', + }, + }, + }, + }; + test('should build a URI for dist tarball based on new domain', () => { + const req = httpMocks.createRequest({ + method: 'GET', + headers: { + host: fakeHost, + [HEADERS.FORWARDED_PROTO]: 'http', + }, + url: '/', + }); + const convertDist = convertDistRemoteToLocalTarballUrls(cloneMetadata(), { + host: req.hostname, + headers: req.headers as any, + protocol: req.protocol, + }); + expect(convertDist.versions['1.0.0'].dist.tarball).toEqual(buildURI(fakeHost, '1.0.0')); + expect(convertDist.versions['1.0.1'].dist.tarball).toEqual(buildURI(fakeHost, '1.0.1')); + }); +}); diff --git a/packages/core/tarball/tests/getLocalRegistryTarballUri.spec.ts b/packages/core/tarball/tests/getLocalRegistryTarballUri.spec.ts index 01b113c4a..dda315178 100644 --- a/packages/core/tarball/tests/getLocalRegistryTarballUri.spec.ts +++ b/packages/core/tarball/tests/getLocalRegistryTarballUri.spec.ts @@ -21,6 +21,11 @@ describe('extractTarballFromUrl', () => { tarball: 'https://localhost/npm_test-1.0.2.tgz', }, }, + '1.0.3': { + dist: { + tarball: 'http://registry.org/@org/npm_test/-/npm_test-1.0.3.tgz', + }, + }, }, }; @@ -34,5 +39,8 @@ describe('extractTarballFromUrl', () => { expect(extractTarballFromUrl(metadata.versions['1.0.2'].dist.tarball)).toEqual( 'npm_test-1.0.2.tgz' ); + expect(extractTarballFromUrl(metadata.versions['1.0.3'].dist.tarball)).toEqual( + 'npm_test-1.0.3.tgz' + ); }); }); diff --git a/packages/store/src/storage.ts b/packages/store/src/storage.ts index a86929b8b..891fca2ee 100644 --- a/packages/store/src/storage.ts +++ b/packages/store/src/storage.ts @@ -257,6 +257,10 @@ class Storage { } private async getTarballFromUpstream(name: string, filename: string, { signal }) { + this.logger.info( + { name, filename }, + 'get tarball for package @{name} filename @{filename} from uplink' + ); let cachedManifest: Manifest | null = null; try { cachedManifest = await this.getPackageLocalMetadata(name); @@ -403,6 +407,7 @@ class Storage { * @returns */ public async getTarball(name: string, filename: string, { signal }): Promise { + this.logger.info({ name, filename }, 'get tarball for package @{name} filename @{filename}'); debug('get tarball for package %o filename %o', name, filename); // TODO: check if isOpen is need it after all. // eslint-disable-next-line @typescript-eslint/no-unused-vars