Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "extra" field mean in composer.json file?

I try to add composer.json file to my library. In many examples that I saw I found "extra" field, that look like:

"extra": {
    "branch-alias": {
        "dev-master": "2.0.x-dev"
    }
}

My question is:

Is this a required field? What does it mean and what I must write in it?

like image 693
Victor Bocharsky Avatar asked Nov 11 '22 10:11

Victor Bocharsky


1 Answers

It's aliasing the master branch. Composer uses GIT versions and branches to get the version number of a release. So a 1.2 branch can be used as 1.2@dev, and a v1.2.1 tag is the 1.2.1 version.

However, the master branch is vague for Composer. It can't parse a version from that name. The same applies to other branches that doesn't follow a common version name. You can refer to the master branch using dev-master, but that's not always considered to be a good practise.

Also, assume the master branch was the 2.0.x dev branch. If you want to install the master branch, you actually want the latest 2.0.x dev version. So instead of referencing to a branch name (dev-master), you want to use something more semantic (2.0.x@dev). As a result, Composer can perfectly handle this when an alpha, beta, RC, etc. release is done for the latest 2.0.x branch.

In order to make Composer doing this, you have to alias the branch (in this case the master branch) to a version. That's done in the branch-alias part of the extra section. In the code you provided, the master branch is set to be the dev version of the latest 2.0.x release. So people can use 2.0.*@dev in their composer.json and they will get this master branch installed.

Short answer: It's branch aliasing, for more information see "Aliases" of the documentation.

like image 116
Wouter J Avatar answered Nov 13 '22 09:11

Wouter J