mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
refactor: separate npm.getPresets
This commit is contained in:
parent
b69948f6b3
commit
32c775265a
5 changed files with 47 additions and 12 deletions
|
@ -161,7 +161,7 @@ async function getPreset(preset) {
|
|||
logger.trace(`getPreset(${preset})`);
|
||||
const { packageName, presetName, params } = parsePreset(preset);
|
||||
let presetConfig;
|
||||
const dep = await npm.getPkgReleases(packageName);
|
||||
const dep = await npm.getPreset(packageName);
|
||||
if (!dep) {
|
||||
throw Error('dep not found');
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ const endpoints = require('../util/endpoints');
|
|||
module.exports = {
|
||||
maskToken,
|
||||
setNpmrc,
|
||||
getPreset,
|
||||
getPkgReleases,
|
||||
resetMemCache,
|
||||
resetCache,
|
||||
|
@ -110,6 +111,13 @@ function getPkgReleases(input, config) {
|
|||
return getDependency(purl.fullname, retries);
|
||||
}
|
||||
|
||||
async function getPreset(pkgName) {
|
||||
const res = await getDependency(pkgName);
|
||||
return {
|
||||
'renovate-config': res['renovate-config'],
|
||||
};
|
||||
}
|
||||
|
||||
async function getDependency(name, retries = 5) {
|
||||
logger.trace(`getPkgReleases(${name})`);
|
||||
if (memcache[name]) {
|
||||
|
@ -215,7 +223,6 @@ async function getDependency(name, retries = 5) {
|
|||
latestVersion: res['dist-tags'].latest,
|
||||
repositoryUrl,
|
||||
versions: {},
|
||||
'renovate-config': latestVersion['renovate-config'],
|
||||
};
|
||||
if (latestVersion.deprecated) {
|
||||
dep.deprecationMessage = `On registry \`${regUrl}\`, the "latest" version (v${
|
||||
|
|
|
@ -6,7 +6,7 @@ const presetGroup = require('../_fixtures/npm/renovate-config-group');
|
|||
const presetMonorepo = require('../_fixtures/npm/renovate-config-monorepo');
|
||||
const presetIkatyang = require('../_fixtures/npm/renovate-config-ikatyang');
|
||||
|
||||
npm.getPkgReleases = jest.fn(dep => {
|
||||
npm.getPreset = jest.fn(dep => {
|
||||
if (dep === 'renovate-config-default') {
|
||||
return {
|
||||
'renovate-config':
|
||||
|
|
|
@ -19,7 +19,6 @@ Object {
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
@ -44,7 +43,6 @@ Object {
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
@ -67,7 +65,6 @@ Object {
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
@ -92,7 +89,6 @@ Object {
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
@ -117,7 +113,6 @@ Object {
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
@ -151,7 +146,6 @@ Marking the latest version of an npm package as deprecated results in the entire
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
@ -165,6 +159,12 @@ exports[`api/npm should return deprecated 2`] = `
|
|||
Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake."
|
||||
`;
|
||||
|
||||
exports[`api/npm should return preset 1`] = `
|
||||
Object {
|
||||
"renovate-config": undefined,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`api/npm should send an authorization header if provided 1`] = `
|
||||
Object {
|
||||
"homepage": undefined,
|
||||
|
@ -184,7 +184,6 @@ Object {
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
@ -209,7 +208,6 @@ Object {
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
@ -234,7 +232,6 @@ Object {
|
|||
"version": "0.0.2",
|
||||
},
|
||||
],
|
||||
"renovate-config": undefined,
|
||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||
"versions": Object {},
|
||||
}
|
||||
|
|
|
@ -61,6 +61,37 @@ describe('api/npm', () => {
|
|||
expect(getRelease(res, '0.0.1').canBeUnpublished).toBe(false);
|
||||
expect(getRelease(res, '0.0.2').canBeUnpublished).toBe(false);
|
||||
});
|
||||
it('should return preset', async () => {
|
||||
const presetPackage = {
|
||||
name: 'foobar',
|
||||
versions: {
|
||||
'0.0.1': {
|
||||
foo: 1,
|
||||
},
|
||||
'0.0.2': {
|
||||
foo: 2,
|
||||
deprecated: 'This is deprecated',
|
||||
},
|
||||
},
|
||||
repository: {
|
||||
type: 'git',
|
||||
url: 'git://github.com/renovateapp/dummy.git',
|
||||
},
|
||||
'dist-tags': {
|
||||
latest: '0.0.2',
|
||||
},
|
||||
time: {
|
||||
'0.0.1': '2018-05-06T07:21:53+02:00',
|
||||
'0.0.2': '2018-05-07T07:21:53+02:00',
|
||||
},
|
||||
'renovate-config': { foo: 1 },
|
||||
};
|
||||
nock('https://registry.npmjs.org')
|
||||
.get('/foobar')
|
||||
.reply(200, presetPackage);
|
||||
const res = await npm.getPreset('foobar');
|
||||
expect(res).toMatchSnapshot();
|
||||
});
|
||||
it('should return deprecated', async () => {
|
||||
const deprecatedPackage = {
|
||||
name: 'foobar',
|
||||
|
|
Loading…
Reference in a new issue