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})`);
|
logger.trace(`getPreset(${preset})`);
|
||||||
const { packageName, presetName, params } = parsePreset(preset);
|
const { packageName, presetName, params } = parsePreset(preset);
|
||||||
let presetConfig;
|
let presetConfig;
|
||||||
const dep = await npm.getPkgReleases(packageName);
|
const dep = await npm.getPreset(packageName);
|
||||||
if (!dep) {
|
if (!dep) {
|
||||||
throw Error('dep not found');
|
throw Error('dep not found');
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ const endpoints = require('../util/endpoints');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
maskToken,
|
maskToken,
|
||||||
setNpmrc,
|
setNpmrc,
|
||||||
|
getPreset,
|
||||||
getPkgReleases,
|
getPkgReleases,
|
||||||
resetMemCache,
|
resetMemCache,
|
||||||
resetCache,
|
resetCache,
|
||||||
|
@ -110,6 +111,13 @@ function getPkgReleases(input, config) {
|
||||||
return getDependency(purl.fullname, retries);
|
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) {
|
async function getDependency(name, retries = 5) {
|
||||||
logger.trace(`getPkgReleases(${name})`);
|
logger.trace(`getPkgReleases(${name})`);
|
||||||
if (memcache[name]) {
|
if (memcache[name]) {
|
||||||
|
@ -215,7 +223,6 @@ async function getDependency(name, retries = 5) {
|
||||||
latestVersion: res['dist-tags'].latest,
|
latestVersion: res['dist-tags'].latest,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
versions: {},
|
versions: {},
|
||||||
'renovate-config': latestVersion['renovate-config'],
|
|
||||||
};
|
};
|
||||||
if (latestVersion.deprecated) {
|
if (latestVersion.deprecated) {
|
||||||
dep.deprecationMessage = `On registry \`${regUrl}\`, the "latest" version (v${
|
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 presetMonorepo = require('../_fixtures/npm/renovate-config-monorepo');
|
||||||
const presetIkatyang = require('../_fixtures/npm/renovate-config-ikatyang');
|
const presetIkatyang = require('../_fixtures/npm/renovate-config-ikatyang');
|
||||||
|
|
||||||
npm.getPkgReleases = jest.fn(dep => {
|
npm.getPreset = jest.fn(dep => {
|
||||||
if (dep === 'renovate-config-default') {
|
if (dep === 'renovate-config-default') {
|
||||||
return {
|
return {
|
||||||
'renovate-config':
|
'renovate-config':
|
||||||
|
|
|
@ -19,7 +19,6 @@ Object {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"versions": Object {},
|
||||||
}
|
}
|
||||||
|
@ -44,7 +43,6 @@ Object {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"versions": Object {},
|
||||||
}
|
}
|
||||||
|
@ -67,7 +65,6 @@ Object {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"versions": Object {},
|
||||||
}
|
}
|
||||||
|
@ -92,7 +89,6 @@ Object {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"versions": Object {},
|
||||||
}
|
}
|
||||||
|
@ -117,7 +113,6 @@ Object {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"versions": Object {},
|
||||||
}
|
}
|
||||||
|
@ -151,7 +146,6 @@ Marking the latest version of an npm package as deprecated results in the entire
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"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."
|
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`] = `
|
exports[`api/npm should send an authorization header if provided 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"homepage": undefined,
|
"homepage": undefined,
|
||||||
|
@ -184,7 +184,6 @@ Object {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"versions": Object {},
|
||||||
}
|
}
|
||||||
|
@ -209,7 +208,6 @@ Object {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"versions": Object {},
|
||||||
}
|
}
|
||||||
|
@ -234,7 +232,6 @@ Object {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"renovate-config": undefined,
|
|
||||||
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
"repositoryUrl": "https://github.com/renovateapp/dummy",
|
||||||
"versions": Object {},
|
"versions": Object {},
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,37 @@ describe('api/npm', () => {
|
||||||
expect(getRelease(res, '0.0.1').canBeUnpublished).toBe(false);
|
expect(getRelease(res, '0.0.1').canBeUnpublished).toBe(false);
|
||||||
expect(getRelease(res, '0.0.2').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 () => {
|
it('should return deprecated', async () => {
|
||||||
const deprecatedPackage = {
|
const deprecatedPackage = {
|
||||||
name: 'foobar',
|
name: 'foobar',
|
||||||
|
|
Loading…
Reference in a new issue