3
votes

TL;DR:

My Project requires library A, A requires B1. B1 is broken but there is a fork B2. I want to achieve that composer will install B2 instead of B1 even if A requires B1 and not B2.

How to do that?

More in detail:

In a symfony project we require the following library:

"require": {
   "emanueleminotto/twig-cache-bundle": "1.0.2",
}

This library requires itself another library that is currently broken:

"require": {
    "asm89/twig-cache-extension": "^1.3"
},

For the broken library exists already a pull request for over 4 month but the maintainer refuses to merge it.

My question is, if it would be possible to overwrite the dependencies also for sub-dependencies, that always the patched fork would be used instead of the original one?

For the asm89/twig-cache-extension exists the following fork with fixes: https://github.com/blackandred/twig-cache-extension

I tried to add this fork to my composer.json and registered the fork explicitly under "repositories":

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/blackandred/twig-cache-extension"
    }
],

and added the dependency also in my composer-json with a changed version to "dev-master":

"require": {
    "asm89/twig-cache-extension": "dev-master",
    "emanueleminotto/twig-cache-bundle": "1.0.2",
}

But since the emanueleminotto/twig-cache-bundle still requires the original library, composer ignores the fork and installs the original.

Anything i can do here?

2

2 Answers

8
votes

I believe the docs have a good example for this scenario.

Basically you need to define an alias in your composer.json as following:

"require": {
    "asm89/twig-cache-extension": "dev-master  as 1.3",
    "emanueleminotto/twig-cache-bundle": "1.0.2",
}

Added by the questioner:

One step was still missing: "composer update asm89/twig-cache-extension"

2
votes

Add the replace section into composer.json of your fork:

{
    "replace": { 
        "asm89/twig-cache-extension": "self.version" 
    } 
}