From bca8931d53d4211dd7becf44a90f0508d8589563 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Wed, 17 Mar 2021 14:40:50 +0100 Subject: [PATCH] fix(npm): datasource improvements (#9178) --- lib/config/decrypt.ts | 2 +- .../npm/__snapshots__/get.spec.ts.snap | 33 --------- .../npm/__snapshots__/index.spec.ts.snap | 72 ------------------- lib/datasource/npm/get.spec.ts | 30 ++++---- lib/datasource/npm/get.ts | 37 +--------- lib/datasource/npm/index.spec.ts | 11 --- lib/manager/npm/post-update/index.ts | 4 +- lib/workers/repository/init/config.ts | 4 +- 8 files changed, 21 insertions(+), 172 deletions(-) diff --git a/lib/config/decrypt.ts b/lib/config/decrypt.ts index 76ef5f7274..5ad212fa6a 100644 --- a/lib/config/decrypt.ts +++ b/lib/config/decrypt.ts @@ -48,7 +48,7 @@ export function decryptConfig(config: RenovateConfig): RenovateConfig { { decryptedToken: maskToken(token) }, 'Migrating npmToken to npmrc' ); - if (decryptedConfig.npmrc) { + if (is.string(decryptedConfig.npmrc)) { /* eslint-disable no-template-curly-in-string */ if (decryptedConfig.npmrc.includes('${NPM_TOKEN}')) { logger.debug('Replacing ${NPM_TOKEN} with decrypted token'); diff --git a/lib/datasource/npm/__snapshots__/get.spec.ts.snap b/lib/datasource/npm/__snapshots__/get.spec.ts.snap index 32ea080110..e6a41feecf 100644 --- a/lib/datasource/npm/__snapshots__/get.spec.ts.snap +++ b/lib/datasource/npm/__snapshots__/get.spec.ts.snap @@ -7,7 +7,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -19,7 +18,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -31,7 +29,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -43,7 +40,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -55,7 +51,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -67,7 +62,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -79,7 +73,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -90,7 +83,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -101,7 +93,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -119,7 +110,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -137,7 +127,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -155,7 +144,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -174,7 +162,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -192,7 +179,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -210,7 +196,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -228,7 +213,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -246,7 +230,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -264,7 +247,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -282,7 +264,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -300,7 +281,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -318,7 +298,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -336,7 +315,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -354,7 +332,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -372,7 +349,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -390,7 +366,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -407,7 +382,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -424,7 +398,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -441,7 +414,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -457,7 +429,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -473,7 +444,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -490,7 +460,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic dGVzdDp0ZXN0", - "cache-control": "no-cache", "host": "test.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -507,7 +476,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic XXX", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -524,7 +492,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer XXX", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, diff --git a/lib/datasource/npm/__snapshots__/index.spec.ts.snap b/lib/datasource/npm/__snapshots__/index.spec.ts.snap index b864d82498..e45039df17 100644 --- a/lib/datasource/npm/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/npm/__snapshots__/index.spec.ts.snap @@ -6,7 +6,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -45,7 +44,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "npm.mycustomregistry.com", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -84,7 +82,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -123,7 +120,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -161,7 +157,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -200,7 +195,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -234,7 +228,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -268,7 +261,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -278,22 +270,6 @@ Array [ ] `; -exports[`datasource/npm/index should reject name mismatch 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", - "host": "registry.npmjs.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://registry.npmjs.org/different", - }, -] -`; - exports[`datasource/npm/index should replace any environment variable in npmrc 1`] = ` Object { "name": "foobar", @@ -323,7 +299,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.from-env.com", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -376,7 +351,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -392,7 +366,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -408,7 +381,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -424,7 +396,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -464,7 +435,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic 1234", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -480,7 +450,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -496,7 +465,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -512,7 +480,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -528,7 +495,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -544,40 +510,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", - "host": "registry.npmjs.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://registry.npmjs.org/foobar", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", - "host": "registry.npmjs.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://registry.npmjs.org/foobar", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", - "host": "registry.npmjs.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://registry.npmjs.org/foobar", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -617,7 +549,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer some-token", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -656,7 +587,6 @@ Array [ "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", - "cache-control": "no-cache", "host": "registry.npmjs.org", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -696,7 +626,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer abcde", - "cache-control": "no-cache", "host": "npm.mycustomregistry.com", "user-agent": "https://github.com/renovatebot/renovate", }, @@ -736,7 +665,6 @@ Array [ "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Bearer abcde", - "cache-control": "no-cache", "host": "npm.mycustomregistry.com", "user-agent": "https://github.com/renovatebot/renovate", }, diff --git a/lib/datasource/npm/get.spec.ts b/lib/datasource/npm/get.spec.ts index b44e95dd86..76c91caf8e 100644 --- a/lib/datasource/npm/get.spec.ts +++ b/lib/datasource/npm/get.spec.ts @@ -46,7 +46,7 @@ describe(getName(__filename), () => { .reply(200, { name: '@myco/test' }); setNpmrc(npmrc); - await getDependency('@myco/test', 0); + await getDependency('@myco/test'); const trace = httpMock.getTrace(); expect(trace[0].headers.authorization).toEqual('Bearer XXX'); @@ -78,7 +78,7 @@ describe(getName(__filename), () => { .get(getPath(npmrc)) .reply(200, { name: '@myco/test' }); setNpmrc(npmrc); - await getDependency('@myco/test', 0); + await getDependency('@myco/test'); const trace = httpMock.getTrace(); expect(trace[0].headers.authorization).toEqual('Basic dGVzdDp0ZXN0'); @@ -102,7 +102,7 @@ describe(getName(__filename), () => { .get(getPath(npmrc)) .reply(200, { name: '@myco/test' }); setNpmrc(npmrc); - await getDependency('@myco/test', 0); + await getDependency('@myco/test'); const trace = httpMock.getTrace(); expect(trace[0].headers.authorization).toBeUndefined(); @@ -128,7 +128,7 @@ describe(getName(__filename), () => { .get(getPath(npmrc)) .reply(200, { name: '@myco/test' }); setNpmrc(npmrc); - await getDependency('@myco/test', 0); + await getDependency('@myco/test'); expect(httpMock.getTrace()).toMatchSnapshot(); }); @@ -149,7 +149,7 @@ describe(getName(__filename), () => { .get('/renovate') .reply(200, { name: 'renovate' }); setNpmrc(npmrc); - await getDependency('renovate', 0); + await getDependency('renovate'); expect(httpMock.getTrace()).toMatchSnapshot(); }); @@ -171,7 +171,7 @@ describe(getName(__filename), () => { .get('/renovate') .reply(200, { name: 'renovate' }); setNpmrc(npmrc); - await getDependency('renovate', 0); + await getDependency('renovate'); expect(httpMock.getTrace()).toMatchSnapshot(); }); @@ -184,7 +184,7 @@ describe(getName(__filename), () => { .scope('https://test.org') .get('/none') .reply(200, { name: '@myco/test' }); - expect(await getDependency('none', 0)).toBeNull(); + expect(await getDependency('none')).toBeNull(); httpMock .scope('https://test.org') @@ -195,7 +195,7 @@ describe(getName(__filename), () => { versions: { '1.0.0': {} }, 'dist-tags': { latest: '1.0.0' }, }); - expect(await getDependency('@myco/test', 0)).toBeDefined(); + expect(await getDependency('@myco/test')).toBeDefined(); httpMock .scope('https://test.org') @@ -205,26 +205,26 @@ describe(getName(__filename), () => { versions: { '1.0.0': {} }, 'dist-tags': { latest: '1.0.0' }, }); - expect(await getDependency('@myco/test2', 0)).toBeDefined(); + expect(await getDependency('@myco/test2')).toBeDefined(); httpMock.scope('https://test.org').get('/error-401').reply(401); - expect(await getDependency('error-401', 0)).toBeNull(); + expect(await getDependency('error-401')).toBeNull(); httpMock.scope('https://test.org').get('/error-402').reply(402); - expect(await getDependency('error-402', 0)).toBeNull(); + expect(await getDependency('error-402')).toBeNull(); httpMock.scope('https://test.org').get('/error-404').reply(404); - expect(await getDependency('error-404', 0)).toBeNull(); + expect(await getDependency('error-404')).toBeNull(); httpMock.scope('https://test.org').get('/error4').reply(200, null); - expect(await getDependency('error4', 0)).toBeNull(); + expect(await getDependency('error4')).toBeNull(); setNpmrc(); httpMock .scope('https://registry.npmjs.org') .get('/npm-parse-error') .reply(200, 'not-a-json'); - await expect(getDependency('npm-parse-error', 0)).rejects.toThrow( + await expect(getDependency('npm-parse-error')).rejects.toThrow( ExternalHostError ); @@ -232,7 +232,7 @@ describe(getName(__filename), () => { .scope('https://registry.npmjs.org') .get('/npm-error-402') .reply(402); - expect(await getDependency('npm-error-402', 0)).toBeNull(); + expect(await getDependency('npm-error-402')).toBeNull(); expect(httpMock.getTrace()).toMatchSnapshot(); }); diff --git a/lib/datasource/npm/get.ts b/lib/datasource/npm/get.ts index cd62dbc36b..4c00185a9e 100644 --- a/lib/datasource/npm/get.ts +++ b/lib/datasource/npm/get.ts @@ -1,7 +1,6 @@ import { OutgoingHttpHeaders } from 'http'; import url from 'url'; import is from '@sindresorhus/is'; -import delay from 'delay'; import registryAuthToken from 'registry-auth-token'; import getRegistryUrl from 'registry-auth-token/registry-url'; import { logger } from '../../logger'; @@ -67,8 +66,7 @@ export interface NpmResponse { } export async function getDependency( - packageName: string, - retries = 3 + packageName: string ): Promise<NpmDependency | null> { logger.trace(`npm.getDependency(${packageName})`); @@ -135,29 +133,12 @@ export async function getDependency( delete headers.authorization; } - // This tells our http layer not to serve responses directly from the cache and instead to revalidate them every time - headers['Cache-Control'] = 'no-cache'; - try { - const useCache = retries === 3; // Disable cache if we're retrying const opts: HttpOptions = { headers, - useCache, }; const raw = await http.getJson<NpmResponse>(pkgUrl, opts); - if (retries < 3) { - logger.debug({ pkgUrl, retries }, 'Recovered from npm error'); - } const res = raw.body; - // eslint-disable-next-line no-underscore-dangle - const returnedName = res.name ? res.name : res._id || ''; - if (returnedName.toLowerCase() !== packageName.toLowerCase()) { - logger.warn( - { lookupName: packageName, returnedName: res.name, regUrl }, - 'Returned name does not match with requested name' - ); - return null; - } if (!res.versions || !Object.keys(res.versions).length) { // Registry returned a 200 OK but with no versions logger.debug({ dependency: packageName }, 'No versions returned'); @@ -269,22 +250,6 @@ export async function getDependency( return null; } if (uri.host === 'registry.npmjs.org') { - // istanbul ignore if - if ( - (err.name === 'ParseError' || - err.code === 'ECONNRESET' || - err.code === 'ETIMEDOUT') && - retries > 0 - ) { - // Delay a random time to avoid contention - const delaySeconds = 5 + Math.round(Math.random() * 25); - logger.warn( - { pkgUrl, errName: err.name, delaySeconds }, - 'Retrying npm error' - ); - await delay(1000 * delaySeconds); - return getDependency(packageName, retries - 1); - } // istanbul ignore if if (err.name === 'ParseError' && err.body) { err.body = 'err.body deleted by Renovate'; diff --git a/lib/datasource/npm/index.spec.ts b/lib/datasource/npm/index.spec.ts index c5bff853ad..a4979577cf 100644 --- a/lib/datasource/npm/index.spec.ts +++ b/lib/datasource/npm/index.spec.ts @@ -169,16 +169,6 @@ describe(getName(__filename), () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); - it('should reject name mismatch', async () => { - httpMock - .scope('https://registry.npmjs.org') - .get('/different') - .reply(200, npmResponse); - const res = await getPkgReleases({ datasource, depName: 'different' }); - expect(res).toBeNull(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - it('should handle no time', async () => { delete npmResponse.time['0.0.2']; httpMock @@ -208,7 +198,6 @@ describe(getName(__filename), () => { httpMock .scope('https://registry.npmjs.org') .get('/foobar') - .times(4) .reply(200, 'oops'); await expect( getPkgReleases({ datasource, depName: 'foobar' }) diff --git a/lib/manager/npm/post-update/index.ts b/lib/manager/npm/post-update/index.ts index 40b373e901..1e7032521d 100644 --- a/lib/manager/npm/post-update/index.ts +++ b/lib/manager/npm/post-update/index.ts @@ -123,9 +123,9 @@ export async function writeExistingFiles( packageFiles: AdditionalPackageFiles ): Promise<void> { const npmrcFile = upath.join(config.localDir, '.npmrc'); - if (config.npmrc) { + if (is.string(config.npmrc)) { logger.debug(`Writing repo .npmrc (${config.localDir})`); - await outputFile(npmrcFile, `${String(config.npmrc)}\n`); + await outputFile(npmrcFile, `${config.npmrc}\n`); } else if (config.ignoreNpmrcFile) { logger.debug('Removing ignored .npmrc file before artifact generation'); await remove(npmrcFile); diff --git a/lib/workers/repository/init/config.ts b/lib/workers/repository/init/config.ts index 4751474054..e4dc47a5f0 100644 --- a/lib/workers/repository/init/config.ts +++ b/lib/workers/repository/init/config.ts @@ -181,7 +181,7 @@ export async function mergeRenovateConfig( // Decrypt before resolving in case we need npm authentication for any presets const decryptedConfig = decryptConfig(migratedConfig); // istanbul ignore if - if (decryptedConfig.npmrc) { + if (is.string(decryptedConfig.npmrc)) { logger.debug('Found npmrc in decrypted config - setting'); npmApi.setNpmrc(decryptedConfig.npmrc); } @@ -191,7 +191,7 @@ export async function mergeRenovateConfig( ); logger.trace({ config: resolvedConfig }, 'resolved config'); // istanbul ignore if - if (resolvedConfig.npmrc) { + if (is.string(resolvedConfig.npmrc)) { logger.debug( 'Ignoring any .npmrc files in repository due to configured npmrc' ); -- GitLab