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

fix(store): add logging when requesting tarball (#4847)

* fix(api): error handling when requesting tarball

* add tarball test for scoped packages

* update changeset

* add logging for tarball requests

* Revert

* Update violet-boxes-float.md
This commit is contained in:
Marc Bernard 2024-09-28 06:47:45 -04:00 committed by GitHub
parent 2f704a6445
commit 5cfbc1485d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 57 additions and 0 deletions

View file

@ -0,0 +1,6 @@
---
'@verdaccio/store': patch
'@verdaccio/tarball': patch
---
fix(api): add logging when requesting tarball

View file

@ -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'));
});
});

View file

@ -21,6 +21,11 @@ describe('extractTarballFromUrl', () => {
tarball: 'https://localhost/npm_test-1.0.2.tgz', 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( expect(extractTarballFromUrl(metadata.versions['1.0.2'].dist.tarball)).toEqual(
'npm_test-1.0.2.tgz' 'npm_test-1.0.2.tgz'
); );
expect(extractTarballFromUrl(metadata.versions['1.0.3'].dist.tarball)).toEqual(
'npm_test-1.0.3.tgz'
);
}); });
}); });

View file

@ -257,6 +257,10 @@ class Storage {
} }
private async getTarballFromUpstream(name: string, filename: string, { signal }) { 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; let cachedManifest: Manifest | null = null;
try { try {
cachedManifest = await this.getPackageLocalMetadata(name); cachedManifest = await this.getPackageLocalMetadata(name);
@ -403,6 +407,7 @@ class Storage {
* @returns * @returns
*/ */
public async getTarball(name: string, filename: string, { signal }): Promise<PassThrough> { public async getTarball(name: string, filename: string, { signal }): Promise<PassThrough> {
this.logger.info({ name, filename }, 'get tarball for package @{name} filename @{filename}');
debug('get tarball for package %o filename %o', name, filename); debug('get tarball for package %o filename %o', name, filename);
// TODO: check if isOpen is need it after all. // TODO: check if isOpen is need it after all.
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars