composer-phpdependency-managementpackagist

Why is repository local directive in composer not working?


There is a project "OctoberCMS" that has a library called "rain" viz. a dependency. I cloned them to my desktop using:

git clone --branch develop git@github.com:octobercms/october.git
git clone --branch develop git@github.com: octobercms/library.git

(Actually cloned forked versions but anyway showing the original repo URLs above) So the thing is that I want to make changes and a PR to the library project. So I opened the composer.json inside october folder and then added:

"repositories": [
    {
        "type": "path",
        "url": "../library",
        "options": {
            "symlink": true
        }
    }
],

And since the main OctoberCMS project already has october/rain viz the library project as a dependency declared in it's composer, I changed the code from "october/rain": "1.1.*", to "october/rain": "@dev",, hoping that it will symlink and load the local repo. But it didn't work.

I figured that the other dependencies of OctoberCMS i.e. system, backend and cms also require `"october/rain": "1.1.*" and perhaps that is why composer loads the packagist version over my local clone. So instead, I tried using the replace directive, since I read that it helps to tell dependencies to ignore whatever is in the block as it's satisfied,

"replace" : {
    "october/rain": "~1.1.0"
},

hoping that composer will think that this is satisfied by the main project's composer directive with @dev but that didn't work either. When I finally removed the 3 requires i.e.:

"october/system": "1.1.*",
"october/backend": "1.1.*",
"october/cms": "1.1.*",

Then the symlinking works and indeed my local repo is referenced, however the project fails since it's dependencies don't exist. So I'm confused on what I could do to fix this.


Solution

  • Tell composer to use the develop branch, but create an inline alias to a version that satisfies the other dependencies:

    {
        "require": {
            ...
        
            "october/rain": "dev-develop as 1.1.x-dev",
    
            ...
        }
    }
    

    For further development, I suggest you update the branch alias in the october/rain repository:

    {
        "extra": {
            "branch-alias": {
                "dev-development": "1.1.x-dev"
            }
        }
    }
    

    This needs to change with each release / development phase.