fix(npm): ignore deprecated versions

Closes #1988
This commit is contained in:
Rhys Arkins 2018-05-18 07:33:20 +02:00
parent d1bfeaa877
commit 7fcbb47b3a
3 changed files with 22 additions and 5 deletions

View file

@ -161,11 +161,15 @@ async function getDependency(name, retries = 5) {
'renovate-config': latestVersion['renovate-config'], 'renovate-config': latestVersion['renovate-config'],
}; };
Object.keys(dep.versions).forEach(version => { Object.keys(dep.versions).forEach(version => {
if (dep.versions[version].deprecated) {
delete dep.versions[version];
} else {
// We don't use any of the version payload currently // We don't use any of the version payload currently
dep.versions[version] = { dep.versions[version] = {
// fall back to arbitrary time for old npm servers // fall back to arbitrary time for old npm servers
time: res.time ? res.time[version] : '2017-01-01T12:00:00.000Z', time: res.time ? res.time[version] : '2017-01-01T12:00:00.000Z',
}; };
}
}); });
logger.trace({ dep }, 'dep'); logger.trace({ dep }, 'dep');
memcache[name] = dep; memcache[name] = dep;

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,7 @@
const npm = require('../../../lib/datasource/npm'); const npm = require('../../../lib/datasource/npm');
const registryAuthToken = require('registry-auth-token'); const registryAuthToken = require('registry-auth-token');
const nock = require('nock'); const nock = require('nock');
const fs = require('fs');
jest.mock('registry-auth-token'); jest.mock('registry-auth-token');
jest.mock('delay'); jest.mock('delay');
@ -48,6 +49,17 @@ describe('api/npm', () => {
const res = await npm.getDependency('foobar'); const res = await npm.getDependency('foobar');
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('ignores deprecated versions', async () => {
const verdaccio = fs.readFileSync(
'test/_fixtures/npm/verdaccio.json',
'utf8'
);
nock('https://registry.npmjs.org')
.get('/verdaccio')
.reply(200, verdaccio);
const res = await npm.getDependency('verdaccio');
expect(res.versions['3.0.0-test.1']).toBeUndefined();
});
it('should use homepage', async () => { it('should use homepage', async () => {
const npmResponseHomepage = { ...npmResponse }; const npmResponseHomepage = { ...npmResponse };
npmResponseHomepage.repository.url = ''; npmResponseHomepage.repository.url = '';