Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you uninstall all your bower packages?

Sometimes it's useful to rebuild an entire site and force bower to reinstall new versions of all the packages in bower.json.

However, there doesn't seem to be any way of doing that:

Attempt #1:

$ bower uninstall bower not-installed 0 

Nope, that only works on a package-by-package basis, even though a clean 'bower install' uses bower.json.

Attempt #2:

$ bower install -f -l 0 $ 

Nope, despite '-f', this does absolutely nothing if the dependencies are met.

Attempt #3:

$ rm -r bower_components $ 

! Ah victory! ... wait, what's this?

rm: bower_components: No such file or directory 

Oh darn, there's a .bowrc in this project that sets the directory to install things to.

My current terrible solution:

Run custom script that:

- Parse .bowerrc if one exists - Load the directory if one is specified in the json block - If the directory currently exists... - ...recursively delete the directory. 

It works, I suppose, but it's pretty annoying to have to setup repeatedly.

Am I missing something?

Is there not just a simple bower command to delete the local installed modules?

Seems like really basic functionality I would expect bower uninstall to do.

(This isn't really a very javascript question, but I'll happily accept something that hooks into the bower module somehow to make this happen in a simple node script)

Context

Edit: If you want 'motivation' for such a task, it's this: We have a jenkins server that builds our projects and runs tests. However, periodically it fails for no obvious reason; investigating, it's almost always because jenkins is using a previous copy of the repository with just a git-pull to update to the most recent version before building and running tests; as a result, the previous bower_components directory is there, and it is full of cached copies of the various components.

Here a few example of things which are #@$@#$'d and require bower to be run again as a forced install:

1) Some idiot (>_> fitvids) deletes the previous tagged release of a project.

2) Some project has dropped off of bower / moved its github page

3) Some project (>_> jquery) has changed the way the files are laid out in a non-major version revision.

I realize that the 'correct' solution to this problem is: fix jenkins so it creates a new temporary directory for each build. ...but that's not in my control.

So, as a build step, I need to automate a way to delete the bower components and force them to all be reinstalled; either as a grunt task (part of the build) or a jenkins build step. However, remember from (3) above, that our projects use .bowerrc, so it's not as simple as simply deleting a folder.

It would be great if I could uninstall all the existing bower components as a pre-build step to make this work.

So... back to the question: Can this be done with bower?

like image 746
Doug Avatar asked Apr 08 '14 04:04

Doug


People also ask

How do I uninstall Bower package?

Uninstall packages If you use the bower. json file, remove the package from this file and launch bower install again. It will not remove it, you have to use the bower uninstall command.


2 Answers

Updated Answer

If you're trying to update all of your packages, use

$ bower update 

Original Answer

Go to your bower.json file and remove all of the components, or libraries, that you want to uninstall from devDependencies.

After you have removed the ones you want gone, execute -

$ bower prune 
  1. start with -

    "devDependencies": {     "angular": "~1.2.15",     "angular-ui-router": "~0.2.10",     "moment": "~2.5.1" } 
  2. remove angular references from file -

    "devDependencies": {     "moment": "~2.5.1" } 
  3. execute

    $ bower prune 
  4. watch your angular dependencies get uninstalled

like image 177
VtoCorleone Avatar answered Sep 28 '22 01:09

VtoCorleone


how about

  1. edit the bower.json
  2. 'rm -Rf bower_components/*'
  3. bower install

I was trying to upgrade to polymer 0.2.4 from 0.2.3. I can't seem to find a quick way to uninstall a set of dependencies. So I just manually removed those polymer* dir under bower_components. But for some reason bower kept remembering I had 0.2.3 installed event with bower.json modified. A 'rm -Rf bower_component/*' seems to do the tricks.

like image 35
user3206144 Avatar answered Sep 28 '22 02:09

user3206144