Skip to content
Snippets Groups Projects
Unverified Commit 73e7492d authored by Gary Lockett's avatar Gary Lockett Committed by GitHub
Browse files

fix(manager/composer): respect the PHP override in composer.json (#13657)


* fix(composer): respect the PHP override in composer.json

Signed-off-by: default avatarGary Lockett <gary@creativecow.uk>

* chore(docs): document new configuration

Signed-off-by: default avatarGary Lockett <gary@creativecow.uk>

* Apply suggestions from code review

Co-authored-by: default avatarMichael Kriese <michael.kriese@visualon.de>

* fix(tests): add missing composer version to expected output

Signed-off-by: default avatarGary Lockett <gary@creativecow.uk>

Co-authored-by: default avatarMichael Kriese <michael.kriese@visualon.de>
Co-authored-by: default avatarRhys Arkins <rhys@arkins.net>
parent 42537f22
No related merge requests found
...@@ -8,6 +8,17 @@ export interface Repo { ...@@ -8,6 +8,17 @@ export interface Repo {
} }
export interface ComposerConfig { export interface ComposerConfig {
type?: string; type?: string;
/**
* Setting a fixed PHP version (e.g. {"php": "7.0.3"}) will let you fake the
* platform version so that you can emulate a production env or define your
* target platform in the config.
* See https://getcomposer.org/doc/06-config.md#platform
*/
config?: {
platform?: {
php?: string;
};
};
/** /**
* A repositories field can be an array of Repo objects or an object of repoName: Repo * A repositories field can be an array of Repo objects or an object of repoName: Repo
* Also it can be a boolean (usually false) to disable packagist. * Also it can be a boolean (usually false) to disable packagist.
......
...@@ -18,6 +18,18 @@ describe('manager/composer/utils', () => { ...@@ -18,6 +18,18 @@ describe('manager/composer/utils', () => {
).toEqual({ php: '>=5.3.2', composer: '1.1.0' }); ).toEqual({ php: '>=5.3.2', composer: '1.1.0' });
}); });
it('returns platform php version', () => {
expect(
extractContraints(
{
config: { platform: { php: '7.4.27' } },
require: { php: '~7.4 || ~8.0' },
},
{}
)
).toEqual({ composer: '1.*', php: '7.4.27' });
});
it('returns from require-dev', () => { it('returns from require-dev', () => {
expect( expect(
extractContraints( extractContraints(
......
...@@ -69,8 +69,10 @@ export function extractContraints( ...@@ -69,8 +69,10 @@ export function extractContraints(
const res: Record<string, string> = { composer: '1.*' }; const res: Record<string, string> = { composer: '1.*' };
// extract php // extract php
if (composerJson.require?.php) { if (composerJson.config?.platform?.php) {
res.php = composerJson.require?.php; res.php = composerJson.config.platform.php;
} else if (composerJson.require?.php) {
res.php = composerJson.require.php;
} }
// extract direct composer dependency // extract direct composer dependency
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment