Update bower dependencies, bower.json in Ember-CLI app [duplicate] - bower

I listed (and/or installed) several dependencies with Bower inside the bower.json file and/or with
bower install https://github.com/username/project.git
That worked fine.
Now I can list all them with
bower list
and then I can pick the name of each dependency of my project and run
bower update dependency-name
Question: How can I bulk update all of them? Or do I have to write a shell script to loop through and update them?

You can update all by running bower update.
Use the -h flag on any command to see how you can use it. Eg bower update -h.

This process is a little slow but is secure because you can realize when your app gets broken.
lets say that you want to update bootstrap you just need to run bower install --save bootstrap and you bower.json file will be updated
Before
{
"name": "my-awesome-app",
"version": "0.0.0",
"dependencies": {
"bootstrap": "~3.0.0",
"requirejs": "~2.1.11",
"modernizr": "~2.8.2",
"jquery": "~2.1.1",
"underscore-amd": "~1.5.2",
"backbone-amd": "~1.1.0",
"require-handlebars-plugin": "~0.8.0"
}
}
After
{
"name": "my-awesome-app",
"version": "0.0.0",
"dependencies": {
"bootstrap": "~3.3.1",
"requirejs": "~2.1.11",
"modernizr": "~2.8.2",
"jquery": "~2.1.1",
"underscore-amd": "~1.5.2",
"backbone-amd": "~1.1.0",
"require-handlebars-plugin": "~0.8.0"
}
}

Used bower-update-all to update all bower dependencies in bower.json, as follows:
npm install -g bower-update-all
bower-update-all

If you want to force all dependencies to update you can use bower install --save --force. This is the same as bower install --save [dep1] [dep2] ...
The short version is bower i -S -f

Related

Yeoman Angular generator - bower_components missing in app folder

Im on windows and when I use Angular generator to scaffold my application bower_components is missing in app directory - instead its in the root directory
This is my app directory after fresh scaffolding:
So I have to manually put bower components in the app directory...
Any ideas why is this happening?
P.S in bower.json I have:
"appPath": "app"
But that option is not respected, when I run bower install it doesnt add bower_components into the app directory.
Made it work - edited .bowerrc
{
"directory": "app/bower_components"
}
and then bower install.
Now all dependencies are in app directory.
try edit your bower.json file, then run bower install
{
"name": "mi-portfolio",
"version": "0.0.0",
"directory": "bower_components/"
"dependencies":
{
"angular": "1.2.6",
"json3": "~3.2.6",
"es5-shim": "~2.1.0",
"jquery": "~1.10.2",
"bootstrap": "~3.0.3",
"angular-cookies": "1.2.6",
"angular-sanitize": "1.2.6"
},
"devDependencies":
{
"angular-mocks": "1.2.6",
"angular-scenario": "1.2.6"
}
}
look here bower code

How to know when a new package version using bower?

I am using bower see dependencies from my bower.json below, so the question is I want bower to give a report of dependencies with newer version release but without installing it, for insatnce using npm-check-updates for npm give a nice list of dependencies that are outdated.
...
"dependencies": {
"angular": "1.3.0-beta.17",
"angular-animate": "1.3.0-beta.17",
"angular-mocks": "1.3.0-beta.17",
"angular-resource": "1.3.0-beta.17",
"angular-route": "1.3.0-beta.17",
"angular-ui-select2": "~0.0.5",
"underscore": "~1.x",
"bootstrap": "~3.x",
"components-font-awesome": "~4.x",
"angular-bootstrap": "~0.11.0",
"ng-grid": "~2.0.11",
"AngularJS-Toaster": "~0.4.6",
"intro.js": "~0.9.0",
"angular-intro.js": "~1.1.1"
},
...
You can just do bower ls and it'll tell you which packages are outdated. However there's discussion regarding adding an outdated command alias to be consistent with other package managers, included npm. You can voice your support here: https://github.com/bower/bower/issues/1138

Why does Bower remove my "resolutions" and how do I stop it

I have a bower.json file
{
"name": "example-project",
"private": true,
"dependencies": {
"angular": "1.2.14",
"angular-scenario": "1.2.14",
"angular-resource": "1.2.14",
"angular-ui-router": "0.2.10",
"angular-strap": "2.0.0"
}
}
When I run grunt (with grunt-bowercopy or grunt-bower-task) I get an error Fatal error: Unable to find suitable version for angular
When I run bower install it says it doesn't know which version of angular to use:
Unable to find a suitable version for angular, please choose one:
1) angular#1.2.14 which resolved to 1.2.14 and is required by angular-scenario#1.2.14, example-project
2) angular#>= 1.0.8 which resolved to 1.2.16 and is required by angular-ui-router#0.2.10
3) angular#~1.2.10 which resolved to 1.2.16 and is required by angular-strap#2.0.0
Prefix the choice with ! to persist it to bower.json
So that explains why grunt was failing - it had transitive dependencies and didn't know which one to select. So I choose 1 (!1 to persist). Now my bower.json looks like this:
{
"name": "example-project",
"private": true,
"dependencies": {
"angular": "1.2.14",
"angular-scenario": "1.2.14",
"angular-resource": "1.2.14",
"angular-ui-router": "0.2.10",
"angular-strap": "2.0.0"
},
"resolutions": {
"angular": "1.2.14"
}
}
Sweet! I run bower install again. This time it succeeds but removes the "resolutions" part. Now it just works for me without resolutions, but my coworkers will get the same error and have to go through the same process.
Why does it do this? Is there any way to stop it from happening?
-Update-
It seems that this is a bug. See bower issues https://github.com/bower/bower/issues/1061 and https://github.com/bower/bower/issues/1272. Hopefully the issue will get some attention and get resolved.
Upgrade to Bower 1.4.0 or greater where this issue is resolved.
Previous Answer:
A workaround suggested by edeustace (see https://github.com/bower/bower/issues/1061) is to add a script to your build (grunt, gulp, etc) that resets the resolutions as they should be after running bower. It's an ugly solution but should do the trick until the issue gets resolved.

permanently ignore a dependency with bower

I am downloading angular, angular-bootstrap and bootstrap with bower. Bootstrap has a dependency on jquery which is installed in the process. But i don't need it in my project as i am only using bootstrap's css.
So i tried to permanently remove the dependency on jquery with
bower uninstall jquery --save
It's uninstalling jquery, but the next time i make bower update, it's downloaded again.
Is there a way to tell bower to permanently skip a dependency ?
edit: I wish there was something like this:
"resolutions": {
"jquery": "no, thanks"
}
Pull request #1394 added official support for this feature and is present in bower version 1.6.3 and later. Check your version with bower -v, and run npm install -g bower to upgrade.
For reference, please see the .bowerrc official specification document. If this doesn't work for you, please file an issue with bower because it is a bug.
We use it like this in our .bowerrc such as the following:
{
"ignoredDependencies": [
"bootstrap",
"bootstrap-sass",
"bootstrap-sass-official"
]
}
We had a similar situation where we had Backbone depend on Underscore in its bower.json, but we're using Lo-Dash in its stead, so Bower was unnecessarily pulling down Underscore for each install. We have automated checks for 3rd party license compliance, so we didn't want anything we don't actually use.
I realize this isn't exactly what they're meant for, but Bower's install-hooks can be used to clean unneeded deps post-install (at least until Bower gets the sort of "no thanks" resolution you hinted at). In your .bowerrc:
{
"directory": "app/bower_components",
"scripts": {
"postinstall": "rm -rf app/bower_components/underscore"
}
}
It's a bit of a hack, but works.
Something you can do also in your bower.json file:
{
"dependencies": {
...
"bootstrap": "^3.2.0"
}
"overrides": {
"bootstrap": {
"dependencies": []
}
}
}
This means: remove all boostrap's dependencies, which is what you want since jquery is the only one (you can check with bower info bootstrap)
Add it to your .gitignore if you commit your dependencies. Otherwise leave it as it makes no difference. You should just use what you need and ignore the rest.
The above answers are correct but an additional solution is to use wiredep as explained in this answer:
grunt-bower-install: exclude certain components
After installing grunt-wiredep, you can add something similar to this to your Grunt.js to exclude jquery from being injected:
// Automatically inject Bower components into the app
wiredep: {
options: {},
app: {
src: ['<%= my.app %>/index.html'],
exclude: ['bower_components/jquery']
}
},
Bower will still download jquery unfortunately but at least you can tell it not to be included in the HTML src.
DISCLAIMER: This doesn't fix your particular problem, but it helped with mine, so maybe it'll help other people.
I'm using grunt-bower-task to pull the files into a lib directory. I wanted to exclude "angular" and just include "angular.js". One of my dependencies was pulling in "angular". In my bower.json I now have:
{
"name": "myapp",
"version": "0.0.1",
"dependencies": {
"angular.js": "1.3.15",
"angular-bootstrap": "0.13.0",
"angular-cookies": "1.3.15",
"angular-storage": "0.5.0",
"angular-ui-router": "0.2.15",
"mjolnic-bootstrap-colorpicker": "2.1"
},
"exportsOverride": {
"angular": {
"dump": "*.xxx"
},
"angular.js": {
"js": [ "*.js", "*.js.map" ],
"css": "*.css"
}
},
"resolutions": {
"angular": "1.3.15"
}
}
In my gruntfile.js I have:
bower: {
install: {
options: {
targetDir: './lib',
layout: 'byType',
install: true,
cleanTargetDir: true,
cleanBowerDir: false
}
}
},
This stops the "angular" files from being copied to the destination.

How to resolve Bower dependency version conflicts?

I have a project that depends on both:
jquery ~1.9.1
another project which in turn depends on jquery >=1.7.2
But when I run bower install, it ends up installing jquery 2.0.2.
This seems broken.
How do I either (a) make it correctly solve the constraints or (b) explicitly force a final version to be installed (workaround)?
You can add resolutions to the object in your bower.json file and specify the component name & version to automatically resolve the conflict when running bower commands.
Like this:
{
"name": "project-x",
"private": true,
"dependencies": {
"bootstrap-sass": "~3.3.7",
"modernizr": "~2.8.3",
"jquery": "~1.11.3"
},
"devDependencies": {},
"resolutions": {
"jquery": "~1.11.3"
}
}
Also you can run bower install and when bower will ask for "suitable version" (if interactive mode is on), prefix choice with !, so bower will save your choice into bower.json file.
use --force-latest
enter link description here

Resources