How to update bower.json with installed packages?

JavascriptJqueryPackageBower

Javascript Problem Overview


In my project I've installed bower components without save option. Now, I would like update to bower.json?

How can I update bower.json with installed packages?

Javascript Solutions


Solution 1 - Javascript

Just list your dependencies:

bower list

Then you should run all install command with param '--save' like this:

bower install bootstrap --save

It's a hard work, but if you have a thousand dependencies, could you create a script to automatize the task.

Solution 2 - Javascript

A little trick if you don't want to write a script for that:

before doing anything rename your bower.json in bower2.json for example.

then you can do a: >$ bower init

(automatically create a bower.json file).

note that all questions should be pre-filled with your current config.

When it will ask you:

> set currently installed components as dependencies? say yes,

You now have all your dependencies in the new bower.json file (and you can check if everything is right with the old bower2.json)

Solution 3 - Javascript

A bit arduous way is to run bower list, look for packages labeled extraneous and add those manually to the dependencies in the bower.json.

If there are a lot of extraneous packages, it might be easier to workaround this by running bower init and answering Yes to "set currently installed components as dependencies?". This will take your current bower.json, read it and then create new one using information from the old one. So in an ideal case you will have the same file just with extraneous packages added.

Warning: Firstly, there might be something lost in the process (e.g. devDependecies). Secondly in the last version of bower (v1.2.7) this will not preserve current packages info! I feel it is a bug. However you can save the old file and (manually) merge it with the generated one.

Also, you should ask for an option or something by opening a bower issue as this would be welcomed by many developers.

Solution 4 - Javascript

You can use bower-check-updates (you need installed node.js on your machine):

bower-check-updates is a utility that automatically adjusts a bower.json with the latest version of all dependencies

bower-check-updates - is a fork of npm-check-updates, so it's all the same but updates bower.json, instead of package.json

npm install -g bower-check-updates
bower-check-updates -u
bower install 

This will install bower-check-updates globally, so you can launch it from anywhere.

P.S. for more information about npm-check-updates pleas see this topic

Solution 5 - Javascript

If there aren't that many bower packages you have installed, try writing bower install [package_name] --save. This will just update your bower.json file.

Solution 6 - Javascript

After bower-check-updates -u you must run bower install instead of npm install

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkongarajuView Question on Stackoverflow
Solution 1 - JavascriptHelder RobaloView Answer on Stackoverflow
Solution 2 - JavascriptSebastien HorinView Answer on Stackoverflow
Solution 3 - JavascriptRobin PokornyView Answer on Stackoverflow
Solution 4 - JavascriptSergei PanfilovView Answer on Stackoverflow
Solution 5 - JavascriptsuperjisanView Answer on Stackoverflow
Solution 6 - JavascriptÁmon TamásView Answer on Stackoverflow