diff --git a/lib/api/npm.js b/lib/api/npm.js index fd54e203d265ef27fbb8cd085c6070b0c293b8cf..13b6179de6829fb6f2090f3e95cbd1e45ceec7ac 100644 --- a/lib/api/npm.js +++ b/lib/api/npm.js @@ -19,6 +19,9 @@ async function getDependency(name) { const authInfo = registryAuthToken(regUrl); const headers = {}; + // Reduce metadata https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md + headers.accept = 'application/vnd.npm.install-v1+json'; + if (authInfo) { headers.authorization = `${authInfo.type} ${authInfo.token}`; } diff --git a/test/api/__snapshots__/npm.spec.js.snap b/test/api/__snapshots__/npm.spec.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..79fa151c596a49c97b12b87169ca89295bd5694e --- /dev/null +++ b/test/api/__snapshots__/npm.spec.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`api/npm should fetch package info from npm 1`] = ` +Array [ + "https://npm.mycustomregistry.com/foobar", + Object { + "headers": Object { + "accept": "application/vnd.npm.install-v1+json", + }, + "json": true, + }, +] +`; + +exports[`api/npm should send an authorization header if provided 1`] = ` +Array [ + "https://npm.mycustomregistry.com/foobar", + Object { + "headers": Object { + "accept": "application/vnd.npm.install-v1+json", + "authorization": "Basic 1234", + }, + "json": true, + }, +] +`; diff --git a/test/api/npm.spec.js b/test/api/npm.spec.js index 919121320e89c63a1f9f4bdd1fce42474fc2d370..dc08c8ad7aad47385d27f722c2b4c3ddbd80605d 100644 --- a/test/api/npm.spec.js +++ b/test/api/npm.spec.js @@ -17,10 +17,7 @@ describe('api/npm', () => { const res = await npm.getDependency('foobar'); expect(res).toMatchObject({ some: 'data' }); const call = got.mock.calls[0]; - expect(call).toMatchObject([ - 'https://npm.mycustomregistry.com/foobar', - { json: true, headers: {} }, - ]); + expect(call).toMatchSnapshot(); }); it('should send an authorization header if provided', async () => { registryUrl.mockImplementation(() => 'https://npm.mycustomregistry.com/'); @@ -32,14 +29,6 @@ describe('api/npm', () => { const res = await npm.getDependency('foobar'); expect(res).toMatchObject({ some: 'data' }); const call = got.mock.calls[0]; - expect(call).toMatchObject([ - 'https://npm.mycustomregistry.com/foobar', - { - json: true, - headers: { - authorization: 'Basic 1234', - }, - }, - ]); + expect(call).toMatchSnapshot(); }); });