Search code examples
composer-phppackagist

Composer tilde syntax (Next significant release)


I've installed amnah/yii2-user library from packagist via composer into my project. The project's composer.json relevant require section looks like:

"amnah/yii2-user": "~2.0"

To my understanding, this should install the latest version with a major version of "2". When I check the installed package via composer show amnah/yii2-user -v, I see the following version information:

versions : dev-master, 2.1.0-alpha4, 2.1.0-alpha3, 2.1.0-alpha2, 2.1.0alpha,

* 2.0.0-alpha2, 2.0.0-alpha, 1.0.0-beta

So 2.0.0-alpha2 is installed, the 2.1 versions are ignored. Isn't it supposed to work like

Another way of looking at it is that using ~ specifies a minimum version, but allows the last digit specified to go up.

as the documentation states? I'd need the latest 2.x version installed. What am I missing?


Solution

  • If you need the latest 2.x version installed, you should use ~2.1 if "latest" means that at that time a version 2.1 is the most current version released.

    But I wonder why you are getting the alpha version installed. Usually Composer defaults to only install stable versions, no release candidates (rc), beta, alpha nor dev versions. Did you add a setting for minimum-stability and/or preferred-stability?

    So if you want alpha versions, you should require ~2.1@alpha.

    And a word of caution: The project you are using does require yiisoft/yii2: * and yiisoft/yii2-authclient: * - asterisk meaning that ANY version is sufficient. Yii itself claims that the released 1.1 version is incompatible with the newer 2.0 series (which is not yet released), whatever that means.