Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between composer prefer-dist and prefer-source?

Looking at the help for PHP Composer's install command, I see the following two options

$ composer help install Options:  --prefer-source            Forces installation from package sources when possible, including VCS information.  --prefer-dist              Forces installation from package dist even for dev versions. 

What's a "dist" installation? I poked around the composer site and Google but there didn't seem to be anything that addressed this (So I assume it's something core and obvious to folks familiar with Composer — apologies for the newbie question)

I'm assuming --prefer-source is where Composer will ask Packagist for the repository location, and then checkout/clone/export/etc. the project itself.

If so, then where does --prefer-dist download from? What does it download?

like image 514
Alan Storm Avatar asked Apr 25 '13 01:04

Alan Storm


People also ask

What is composer -- prefer Dist?

--prefer-dist: Reverse of --prefer-source, Composer will install from dist if possible. This can speed up installs substantially on build servers and other use cases where you typically do not run updates of the vendors. It is also a way to circumvent problems with git if you do not have a proper setup.

What does prefer Dist mean in laravel?

--prefer-dist would try to download and unzip archives of the dependencies using GitHub or another API when available. This is used for faster downloading of dependencies in most cases. It doesn't download the whole VCS history of the dependencies and it should be better cached.

What is Phar in composer?

It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, amongst other things. Now run php composer.phar in order to run Composer.

What is minimum stability in composer?

An alternative is to set your minimum-stability to dev, but tell composer you want to use stable whenever possible: "minimum-stability": "dev", "prefer-stable" : true. This basically means it will always use stable UNLESS there is no way to install a stable dependency, and therefore use dev.


1 Answers

According to http://getcomposer.org/doc/03-cli.md, the --prefer-source option will prefer to create a package directory that is a "version control repository". This is equivalent to you typing:

$ git clone ... 

or

$ svn checkout ... 

The --prefer-dist option will prefer to create a non-"version control repository", which is equivalent to you typing:

$ git clone ... ; rm -fr dir/.git 

or

$ svn export ... 

Also, you can define separate repos for source and dist in your composer.json. Here's an example:

{     "repositories": [         {             "type": "package",             "package": {                 "name": "joshuaclayton/blueprint-css",                 "version": "master",                 "source": {                     "url": "git://github.com/joshuaclayton/blueprint-css.git",                     "type": "git",                     "reference": "master",                 }             }         },         {             "type": "package",             "package": {                 "name": "fiftyone/mobi-lite-php",                 "version": "2013.03.06",                 "dist": {                     "url": "http://iweb.dl.sourceforge.net/project/fiftyone/51Degrees.mobi-Lite-2013.03.06.php.zip",                     "type": "zip"                 },             }         }     ] } 

NOTE: for whatever reason, when I use --prefer-dist, I sometimes get errors such as

Fatal error: Cannot redeclare class Zend_Db_Adapter_Pdo_Abstract in ... 

which do not appear when I use --prefer-source. For this reason, I only use --prefer-source, until I figure out the cause of this issue.

like image 152
Ross Smith II Avatar answered Sep 22 '22 21:09

Ross Smith II