2

When one issues a bower install mypackage --save, by default, for version, bower uses the tilde range selector (~) prefix for the latest patch version:

"angular-ui-grid": "~3.1.0"

Because in reality patch versions do cause breaking changes (we've experienced this four times now with our dependencies packages), we'd like to change the behavior to use exact version semver instead:

"angular-ui-grid": "3.1.0"

Is there a way to automatically enforce this or set exact match to the default? I can't expect members of the dev team to remember to delete the ~ everytime they add a bower package.

core
  • 32,451
  • 45
  • 138
  • 193

1 Answers1

3

Have you read the documentation? It looks like -E or --save-exact is what you need.

Edit: just tested it. That's what you need. Your command would then be

bower install mypackage --save-exact

If you want to have that be the default, create a .bowerrc in your home directory and/or in the project directory like:

{
  "save-exact": true
}
Tom Panning
  • 4,613
  • 2
  • 26
  • 47
Joseph Marikle
  • 76,418
  • 17
  • 112
  • 129
  • 1
    I was just reading the documentation, and thought I might add that Bower also has pre/post install hooks. You could also run a script to check for/remove the ~ in version numbers in the the bower.json file, or (if you're lucky) somehow enforce that the `-E` argument was passed to bower. – Sunil D. Feb 02 '16 at 17:21
  • Thanks, Sunil. That is actually very helpful. Trusting developers to remember "--save-exact" isn't realistic when we've got full-stack devs working on front-end code, unfortunately. – core Feb 02 '16 at 17:22
  • 1
    For enforcing `-E`, you can easily make it an alias if you're running a BASH shell. Something like `alias bower='bower -E'` This would be placed in the .bash_profile script; or more globally, it can be placed in `/etc/profile` – Joseph Marikle Feb 02 '16 at 17:23