How to Make it Work
We Need to Be Restrictive
Third-party apps are generally fine to leave open-ended, using the
~ shorthands. More often than not, we want the latest bug fix. But as we're developing our own interdependent apps, we need to lock down the version request. It's verbose, but in most cases the only way to restrict the version to a set tuple, while allowing pre-releases within that tuple, while also rejecting any version outside of that tuple, is:
-0is literal text and
z+1is one more than the number represented by
1.2.3-0 <1.2.4. Note that we need to explicitly use the
-0part of the version; without it, Bower will only look for stable releases, and, in effect, we could have just said
=1.2.3. With the
-0, though, we gain several things:
- Bower will consider pre-releases acceptable, and pick up the latest
- Bower will refuse
1.2.4and higher, pre-release or otherwise, ensuring that the team gets the version they're working on.
- Bower will consider the
1.2.3release valid for that range and prefer it over the pre-releases, meaning the app that is requesting the version doesn't necessarily need to update its
bower.jsonin order to release. Ideally, at release time,
bower.jsonspecifies exact version numbers, but if a version was missed then this notation won't break the desired behavior.
>=1.2.4-0 <1.2.5, they will ensure that they don't accidentally pick up version
1.2.3when it becomes an official release.
Note that you can try these with your own private Bower registry. Create a new git repo, register it with your Bower server, and then iterate over changes to the readme file, while releasing the various tags. Then you can test with
bower info [your-bower-project]#[request version here].
spacecharacters – for example,
bower info test-semver#\>=1.0.0-0\ \<1.0.1– or else wrap the whole
package#versionpart in quotes, like
bower info "test-semver#>=1.0.0-0 <1.0.1". (For reference: how the command line uses spaces and angle brackets)
Examples of Favoring Stable Releases
|Bower assumes you want the latest stable release. |
|Only pre-release versions are greater than |
|Essentially the same as the above example. We want the latest patch greater than or equal to |
|none||Declaring a stable version with no range will not return any version if the stable version doesn't exist; Bower assumes you want the exact stable version requested and will not return the pre-release versions.|
Examples of Pre-release Tags
Apparently, Bower considers anything with a pre-release tag as simply a marker to get a pre-release. It considers the "latest" to be the highest in an alphabetically sorted list of tags. Therefore, pre-release
|The range really only limits the numeric triad to |
|Note that the pre-release tag doesn't even exist, and moreover there is no "dot number." Bower sees no foul in this. It muses, "Ah, you want a pre-release. Here's the latest pre-release!"|
|This actually works! Cumbersome as heck, but it does enable separation of pre-release tags.|
The End (v1.0.0-a.1)
Hopefully this guide to how Bower handles SemVers reduces your aches and pains. If you'd like to read more, check out the section below.