mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
feat(composer): packagist.org optimisation
Use direct lookup for packagist.org only
This commit is contained in:
parent
93a331f214
commit
1409f923d9
5 changed files with 132 additions and 9 deletions
|
@ -171,8 +171,25 @@ async function getAllPackages(regUrl) {
|
||||||
return allPackages;
|
return allPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function packagistOrgLookup(name) {
|
||||||
|
const regUrl = 'https://packagist.org';
|
||||||
|
const pkgUrl = URL.resolve(regUrl, `/packages/${name}.json`);
|
||||||
|
const res = (await got(pkgUrl, {
|
||||||
|
json: true,
|
||||||
|
retries: 5,
|
||||||
|
})).body.package;
|
||||||
|
const dep = extractDepReleases(res.versions);
|
||||||
|
dep.name = name;
|
||||||
|
logger.trace({ dep }, 'dep');
|
||||||
|
return dep;
|
||||||
|
}
|
||||||
|
|
||||||
async function packageLookup(regUrl, name) {
|
async function packageLookup(regUrl, name) {
|
||||||
try {
|
try {
|
||||||
|
if (regUrl === 'https://packagist.org') {
|
||||||
|
const packagistResult = await packagistOrgLookup(name);
|
||||||
|
return packagistResult;
|
||||||
|
}
|
||||||
const allPackages = await getAllPackages(regUrl);
|
const allPackages = await getAllPackages(regUrl);
|
||||||
if (!allPackages) {
|
if (!allPackages) {
|
||||||
return null;
|
return null;
|
||||||
|
|
1
test/_fixtures/packagist/mailchimp-api.json
Normal file
1
test/_fixtures/packagist/mailchimp-api.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,90 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`datasource/packagist getPkgReleases processes real versioned data 1`] = `
|
||||||
|
Object {
|
||||||
|
"homepage": "https://github.com/drewm/mailchimp-api",
|
||||||
|
"name": "drewm/mailchimp-api",
|
||||||
|
"releases": Array [
|
||||||
|
Object {
|
||||||
|
"gitRef": "v1.0",
|
||||||
|
"releaseTimestamp": "2014-05-30T16:51:39+00:00",
|
||||||
|
"version": "1.0",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v1.1",
|
||||||
|
"releaseTimestamp": "2015-07-07T15:38:25+00:00",
|
||||||
|
"version": "1.1",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.0",
|
||||||
|
"releaseTimestamp": "2016-01-17T13:08:01+00:00",
|
||||||
|
"version": "2.0",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.1",
|
||||||
|
"releaseTimestamp": "2016-01-30T16:12:54+00:00",
|
||||||
|
"version": "2.1",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.1.1",
|
||||||
|
"releaseTimestamp": "2016-04-06T08:37:20+00:00",
|
||||||
|
"version": "2.1.1",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.1.2",
|
||||||
|
"releaseTimestamp": "2016-04-06T12:41:37+00:00",
|
||||||
|
"version": "2.1.2",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.1.3",
|
||||||
|
"releaseTimestamp": "2016-04-12T09:09:47+00:00",
|
||||||
|
"version": "2.1.3",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.2",
|
||||||
|
"releaseTimestamp": "2016-04-23T12:43:28+00:00",
|
||||||
|
"version": "2.2",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.2.1",
|
||||||
|
"releaseTimestamp": "2016-04-23T18:00:21+00:00",
|
||||||
|
"version": "2.2.1",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.2.2",
|
||||||
|
"releaseTimestamp": "2016-07-01T09:58:24+00:00",
|
||||||
|
"version": "2.2.2",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.2.3",
|
||||||
|
"releaseTimestamp": "2016-07-01T15:53:33+00:00",
|
||||||
|
"version": "2.2.3",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.2.4",
|
||||||
|
"releaseTimestamp": "2016-07-01T15:53:33+00:00",
|
||||||
|
"version": "2.2.4",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.3",
|
||||||
|
"releaseTimestamp": "2016-12-21T14:50:24+00:00",
|
||||||
|
"version": "2.3",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.4",
|
||||||
|
"releaseTimestamp": "2017-02-16T13:24:20+00:00",
|
||||||
|
"version": "2.4",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.5",
|
||||||
|
"releaseTimestamp": "2018-02-16T15:31:05+00:00",
|
||||||
|
"version": "2.5",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"repositoryUrl": "https://github.com/drewm/mailchimp-api",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`datasource/packagist getPkgReleases supports includes packages 1`] = `
|
exports[`datasource/packagist getPkgReleases supports includes packages 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"homepage": "http://guzzlephp.org/",
|
"homepage": "http://guzzlephp.org/",
|
||||||
|
|
|
@ -8,17 +8,29 @@ jest.mock('../../lib/util/host-rules');
|
||||||
|
|
||||||
const includesJson = fs.readFileSync('test/_fixtures/packagist/includes.json');
|
const includesJson = fs.readFileSync('test/_fixtures/packagist/includes.json');
|
||||||
const beytJson = fs.readFileSync('test/_fixtures/packagist/1beyt.json');
|
const beytJson = fs.readFileSync('test/_fixtures/packagist/1beyt.json');
|
||||||
|
const mailchimpJson = fs.readFileSync(
|
||||||
|
'test/_fixtures/packagist/mailchimp-api.json'
|
||||||
|
);
|
||||||
|
|
||||||
describe('datasource/packagist', () => {
|
describe('datasource/packagist', () => {
|
||||||
describe('getPkgReleases', () => {
|
describe('getPkgReleases', () => {
|
||||||
|
let config;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
hostRules.find = jest.fn(input => input);
|
hostRules.find = jest.fn(input => input);
|
||||||
global.repoCache = {};
|
global.repoCache = {};
|
||||||
|
config = {
|
||||||
|
registryUrls: [
|
||||||
|
{
|
||||||
|
type: 'composer',
|
||||||
|
url: 'https://composer.renovatebot.com',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
return global.renovateCache.rmAll();
|
return global.renovateCache.rmAll();
|
||||||
});
|
});
|
||||||
it('supports custom registries', async () => {
|
it('supports custom registries', async () => {
|
||||||
const config = {
|
config = {
|
||||||
registryUrls: [
|
registryUrls: [
|
||||||
{
|
{
|
||||||
type: 'composer',
|
type: 'composer',
|
||||||
|
@ -66,7 +78,7 @@ describe('datasource/packagist', () => {
|
||||||
});
|
});
|
||||||
const res = await datasource.getPkgReleases(
|
const res = await datasource.getPkgReleases(
|
||||||
'pkg:packagist/vendor/package-name',
|
'pkg:packagist/vendor/package-name',
|
||||||
{}
|
config
|
||||||
);
|
);
|
||||||
expect(res).toMatchSnapshot();
|
expect(res).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
@ -78,7 +90,7 @@ describe('datasource/packagist', () => {
|
||||||
);
|
);
|
||||||
const res = await datasource.getPkgReleases(
|
const res = await datasource.getPkgReleases(
|
||||||
'pkg:packagist/vendor/package-name',
|
'pkg:packagist/vendor/package-name',
|
||||||
{}
|
config
|
||||||
);
|
);
|
||||||
expect(res).toBeNull();
|
expect(res).toBeNull();
|
||||||
});
|
});
|
||||||
|
@ -90,8 +102,8 @@ describe('datasource/packagist', () => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const res = await datasource.getPkgReleases(
|
const res = await datasource.getPkgReleases(
|
||||||
'pkg:packagist/vendor/package-name',
|
'pkg:packagist/drewm/mailchip-api',
|
||||||
{}
|
config
|
||||||
);
|
);
|
||||||
expect(res).toBeNull();
|
expect(res).toBeNull();
|
||||||
});
|
});
|
||||||
|
@ -116,7 +128,7 @@ describe('datasource/packagist', () => {
|
||||||
});
|
});
|
||||||
const res = await datasource.getPkgReleases(
|
const res = await datasource.getPkgReleases(
|
||||||
'pkg:packagist/guzzlehttp/guzzle',
|
'pkg:packagist/guzzlehttp/guzzle',
|
||||||
{}
|
config
|
||||||
);
|
);
|
||||||
expect(res).toMatchSnapshot();
|
expect(res).toMatchSnapshot();
|
||||||
expect(res).not.toBeNull();
|
expect(res).not.toBeNull();
|
||||||
|
@ -155,7 +167,7 @@ describe('datasource/packagist', () => {
|
||||||
});
|
});
|
||||||
const res = await datasource.getPkgReleases(
|
const res = await datasource.getPkgReleases(
|
||||||
'pkg:packagist/wpackagist-plugin/1beyt',
|
'pkg:packagist/wpackagist-plugin/1beyt',
|
||||||
{}
|
config
|
||||||
);
|
);
|
||||||
expect(res).toMatchSnapshot();
|
expect(res).toMatchSnapshot();
|
||||||
expect(res).not.toBeNull();
|
expect(res).not.toBeNull();
|
||||||
|
@ -194,9 +206,17 @@ describe('datasource/packagist', () => {
|
||||||
});
|
});
|
||||||
const res = await datasource.getPkgReleases(
|
const res = await datasource.getPkgReleases(
|
||||||
'pkg:packagist/some/other',
|
'pkg:packagist/some/other',
|
||||||
{}
|
config
|
||||||
);
|
);
|
||||||
expect(res).toBeNull();
|
expect(res).toBeNull();
|
||||||
});
|
});
|
||||||
|
it('processes real versioned data', async () => {
|
||||||
|
got.mockReturnValueOnce({
|
||||||
|
body: JSON.parse(mailchimpJson),
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
await datasource.getPkgReleases('pkg:packagist/drewm/mailchimp-api')
|
||||||
|
).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -941,7 +941,7 @@ describe('manager/npm/lookup', () => {
|
||||||
config.packageFile = 'composer.json';
|
config.packageFile = 'composer.json';
|
||||||
config.currentValue = '1.0.0';
|
config.currentValue = '1.0.0';
|
||||||
nock('https://packagist.org')
|
nock('https://packagist.org')
|
||||||
.get('/packages.json')
|
.get('/packages/foo/bar.json')
|
||||||
.reply(404);
|
.reply(404);
|
||||||
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
|
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue