pub_semver
v2.2.1Versions and version constraints implementing pub's versioning policy. This is very similar to vanilla semver, with a few corner cases.
Архив пакета: https://pubdev.letsnova.ru/api/archives/pub_semver/2.2.1.tar.gz
dart pub add pub_semverREADME
Handles version numbers and version constraints in the same way that pub does.
Semantics
The semantics here very closely follow the Semantic Versioning spec version 2.0.0-rc.1. It differs from semver in a few corner cases:
-
Version ordering does take build suffixes into account. This is unlike semver 2.0.0 but like earlier versions of semver. Version
1.2.3+1is considered a lower number than1.2.3+2.Since a package may have published multiple versions that differ only by build suffix, pub still has to pick one of them somehow. Semver leaves that issue unresolved, so we just say that build numbers are sorted like pre-release suffixes.
-
Pre-release versions are excluded from most max ranges. Let's say a user is depending on "foo" with constraint
>=1.0.0 <2.0.0and that "foo" has published these versions:1.0.01.1.01.2.02.0.0-alpha2.0.0-beta2.0.02.1.0
Versions
2.0.0and2.1.0are excluded by the constraint since neither matches<2.0.0. However, since semver specifies that pre-release versions are lower than the non-prerelease version (i.e.2.0.0-beta < 2.0.0, then the<2.0.0constraint does technically allow those.But that's almost never what the user wants. If their package doesn't work with foo
2.0.0, it's certainly not likely to work with experimental, unstable versions of2.0.0's API, which is what pre-release versions represent.To handle that,
<version ranges don't allow pre-release versions of the maximum unless the max is itself a pre-release, or the min is a pre-release of the same version. In other words, a<2.0.0constraint will prohibit not just2.0.0but any pre-release of2.0.0. However,<2.0.0-betawill exclude2.0.0-betabut allow2.0.0-alpha. Likewise,>2.0.0-alpha <2.0.0will exclude2.0.0-alphabut allow2.0.0-beta. -
Pre-release versions are avoided when possible. The above case handles pre-release versions at the top of the range, but what about in the middle? What if "foo" has these versions:
1.0.01.2.0-alpha1.2.01.3.0-experimental
When a number of versions are valid, pub chooses the best one where "best" usually means "highest numbered". That follows the user's intuition that, all else being equal, they want the latest and greatest. Here, that would mean
1.3.0-experimental. However, most users don't want to use unstable versions of their dependencies.We want pre-releases to be explicitly opt-in so that package consumers don't get unpleasant surprises and so that package maintainers are free to put out pre-releases and get feedback without dragging all of their users onto the bleeding edge.
To accommodate that, when pub is choosing a version, it uses priority order which is different from strict comparison ordering. Any stable version is considered higher priority than any unstable version. The above versions, in priority order, are:
1.2.0-alpha1.3.0-experimental1.0.01.2.0
This ensures that users only end up with an unstable version when there are no alternatives. Usually this means they've picked a constraint that specifically selects that unstable version -- they've deliberately opted into it.
-
There is a notion of compatibility between pre-1.0.0 versions. Semver deems all pre-1.0.0 versions to be incompatible. This means that the only way to ensure compatibility when depending on a pre-1.0.0 package is to pin the dependency to an exact version. Pinned version constraints prevent automatic patch and pre-release updates. To avoid this situation, pub defines the "next breaking" version as the version which increments the major version if it's greater than zero, and the minor version otherwise, resets subsequent digits to zero, and strips any pre-release or build suffix. For example, here are some versions along with their next breaking ones:
0.0.3->0.1.00.7.2-alpha->0.8.01.2.3->2.0.0To make use of this, pub defines a "^" operator which yields a version constraint greater than or equal to a given version, but less than its next breaking one.
История изменений
2.2.1
- Fix parsing of pre-release and build identifiers to only treat pure-digit base-10 identifiers as integers, treating hexadecimal and signed identifiers as alphanumeric strings according to SemVer 2.0.0.
2.2.0
- Remove dependency on
package:meta. - Mark
Versionclass asfinalinstead of with@sealed. - Clarify that the lists returned by
the
preReleaseandbuildproperties ofVersionand therangesproperty ofVersionUnionshould not be modified. - Note that
VersionConstraint.anyandVersionConstraint.emptystatic fields shouldn't be reassigned and will be madefinalin a future release.
2.1.5
- Require Dart
3.4.0. - Move to
dart-lang/toolsmonorepo.
2.1.4
- Added topics to
pubspec.yaml.
2.1.3
- Add type parameters to the signatures of the
Version.preReleaseandVersion.buildfields (List==>List<Object>). #74. - Require Dart 2.17.
2.1.2
- Add markdown badges to the readme.
2.1.1
- Fixed the version parsing pattern to only accept dots between version components.
2.1.0
- Added
Version.canonicalizedVersionto help scrub leading zeros and highlight thatVersion.toString()preserves leading zeros. - Annotated
Versionwith@sealedto discourage users from implementing the interface.
2.0.0
- Stable null safety release.
Version.primarynow throwsStateErrorif theversionsargument is empty.
1.4.4
- Fix a bug of
VersionRange.unionwhere ranges bounded at infinity would get combined wrongly.
1.4.3
- Update Dart SDK constraint to
>=2.0.0 <3.0.0. - Update
package:collectionconstraint to^1.0.0.
1.4.2
- Set max SDK version to
<3.0.0.
1.4.1
- Fix a bug where there upper bound of a version range with a build identifier could accidentally be rewritten.
1.4.0
-
Add a
Version.firstPreReleasegetter that returns the first possible pre-release of a version. -
Add a
Version.isFirstPreReleasegetter that returns whether a version is the first possible pre-release. -
new VersionRange()with an exclusive maximum now replaces the maximum with its first pre-release version. This matches the existing semantics, where an exclusive maximum would exclude pre-release versions of that maximum.Explicitly representing this by changing the maximum version ensures that all operations behave correctly with respect to the special pre-release semantics. In particular, it fixes bugs where, for example,
(>=1.0.0 <2.0.0-dev).union(>=2.0.0-dev <2.0.0)and(>=1.0.0 <3.0.0).difference(^1.0.0)wouldn't include2.0.0-dev. -
Add an
alwaysIncludeMaxPreReleaseparameter tonew VersionRange(), which disables the replacement described above and allows users to create ranges that do include the pre-release versions of an exclusive max version.
1.3.7
- Fix more bugs with
VersionRange.intersect(),VersionRange.difference(), andVersionRange.union()involving version ranges with pre-release maximums.
1.3.6
- Fix a bug where constraints that only allowed pre-release versions would be parsed as empty constraints.
1.3.5
- Fix a bug where
VersionRange.intersect()would return incorrect results for pre-release versions with the same base version number as release versions.
1.3.4
- Fix a bug where
VersionRange.allowsAll(),VersionRange.allowsAny(), andVersionRange.difference()would return incorrect results for pre-release versions with the same base version number as release versions.
1.3.3
- Fix a bug where
VersionRange.difference()with a union constraint that covered the entire range would crash.
1.3.2
- Fix a checked-mode error in
VersionRange.difference().
1.3.1
- Fix a new strong mode error.
1.3.0
-
Make the
VersionUnionclass public. This was previously used internally to implementnew VersionConstraint.unionOf()andVersionConstraint.union(). Now it's public so you can use it too. -
Added
VersionConstraint.difference(). This returns a constraint matching all versions matched by one constraint but not another. -
Make
VersionRangeimplementComparable<VersionRange>. Ranges are ordered first by lower bound, then by upper bound.
1.2.4
- Fix all remaining strong mode warnings.
1.2.3
- Addressed three strong mode warnings.
1.2.2
- Make the package analyze under strong mode and compile with the DDC (Dart Dev
Compiler). Fix two issues with a private subclass of
VersionConstrainthaving different types for overridden methods.
1.2.1
- Allow version ranges like
>=1.2.3-dev.1 <1.2.3to match pre-release versions of1.2.3. Previously, these didn't match, since the pre-release versions had the same major, minor, and patch numbers as the max; now an exception has been added if they also have the same major, minor, and patch numbers as the min and the min is also a pre-release version.
1.2.0
-
Add a
VersionConstraint.union()method and anew VersionConstraint.unionOf()constructor. These each return a constraint that matches multiple existing constraints. -
Add a
VersionConstraint.allowsAll()method, which returns whether one constraint is a superset of another. -
Add a
VersionConstraint.allowsAny()method, which returns whether one constraint overlaps another. -
Versionnow implementsVersionRange.
1.1.0
-
Add support for the
^operator for compatible versions according to pub's notion of compatibility.^1.2.3is equivalent to>=1.2.3 <2.0.0;^0.1.2is equivalent to>=0.1.2 <0.2.0. -
Add
Version.nextBreaking, which returns the next version that introduces breaking changes after a given version. -
Add
new VersionConstraint.compatibleWith(), which returns a range covering all versions compatible with a given version. -
Add a custom
VersionRange.hashCodeto make it properly hashable.
1.0.0
- Initial release.
