PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 2, 2022

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

 March 02, 2022     composer-php, json, php     No comments   

Issue

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?


Solution

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.



Answered By - Wouter J
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing