composer / semver

Semantic versioning utilities with the addition of version constraints parsing and checking.
MIT License
3.15k stars 76 forks source link

Doubts on Semver comparison for versions like a.b.x-dev #70

Closed lcwj3 closed 5 years ago

lcwj3 commented 5 years ago

I am trying to use satisfiedBy to parse php dependencies, somehow I found an error like this:

library name: aarontong00/zippy
version:1.3

the dependencies of this library version is:

php: >=5.5
doctrine/collections: v1.4.0
symfony/filesystem: ^2.0.5 || ^3.0
symfony/process: ^2.1 || ^3.0 || ^4.0
symfony/polyfill-mbstring: ^1.3

For all versions of symfony/filesystem, I parsed the deps like this:

function check($req, $v)
{
    $satisfies = array();
    $vers = explode('|', $v);
    $satisfies = Semver::satisfiedBy($vers, $req);
    echo implode('|', $satisfies);
}
check('^2.0.5 || ^3.0', '3.3.x-dev|3.4.x-dev|3.4.32|dev-1');

The output is 3.3.x-dev|3.4.x-dev|3.4.32 but when I used composer update to install this aarontong00/zippy:1.3, the installed version of symfony/filesystem is 3.4.32. So I think the output of satisfiedBy shouldn't include the dev versions if the dev tags are not considered when install.

stof commented 5 years ago

dev branches are satisfying the constraint. But by default, the composer solver excludes dev versions (due to minimum-stability being stable by default).

lcwj3 commented 5 years ago

Thanks for you kind and quick reply. So does this means I need to filter out stable versions before I parse the deps? Is there any other tool I can use to do this? Thank you very much!

stof commented 5 years ago

Well, I don't know what you are trying to achieve, so I cannot tell you what you should do to achieve it.

Seldaek commented 5 years ago

You can easily exclude them using VersionParser::parseStability, keeping only 'stable' ones or whatever you are interested in.

lcwj3 commented 5 years ago

So sorry for late reply, actually I am trying to build a dependency graph for php packages, that is why I need to parse the dependencies accurately, will try the VersionParser::parseStability, thank both of you so much! Will close this issue now.