How to define the semantics of downloaded packages with Composer?

Asked

Viewed 58 times

3

I created some PHP packages with the help of Composer as dependency manager and made them available in Packagist (https://packagist.org/users/fabiojaniolima/packages/).

After uploading the packages I installed them within an Laravel project. I used the following instruction:

composer require crphp/check

When looking at Laravel’s Commodore.json I saw the following line:

"crphp/check": "^1.0"

I can define inside the package crphp/check for when it is installed it assumes another version semantics, for example 1.1.*?

And this semantics "default" ^1.0 means what?

1 answer

3


According to the composer documentation:

Caret

The Operator behaves very similarly but it sticks Closer to semantic versioning, and will Always allow non-breaking updates. For example 1.2.3 is equivalent to >=1.2.3 <2.0.0 as None of the releases until 2.0 should break Backwards Compatibility. For pre-1.0 versions it also Acts with Safety in Mind and Treats 0.3 as >=0.3.0 <0.4.0.

My translation:

The operator ^ behaves very similar, but more attached to semantic versions, and will always allow updates without breaks. For example, ^1.2.3 is equivalent to >=1.2.3 <2.0.0, that none of the launches until 2.0 should break compatibility with previous versions. For versions with values lower than 1.0 also acts safely in mind and treats ^0.3 as >=0.3.0 <0.4.0.

This is the recommended operator for maximum interoperability when writing library code.

That is, when I use ^1.2.3, I’m telling the Commie "install from version 1.2.3 and, if updates are available, only update if it is smaller than version 2.0.0".

I believe Composer did this because the first number of the versioning sequence indicates that the library has changed significantly and will be dependent on the PHP version you use. That means "updates without break" quoted earlier.

If you want to define that your installation will assume the semantic version as 1.1, then you must specify in your Composer installation

composer require crphp/check 1.1.*

Or

composer require crphp/check ^1.1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.