How to register a local git package in Bower?

user391986 picture user391986 · Oct 29, 2012 · Viewed 40.5k times · Source

How can I register a local git package in bower?

My current component.json is as follows

{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1"
  }
}

However I also would like to add a package I have created at C:/mypackage which is a git repository with versions tagged. When I do bower install --save C:/mypackage it properly adds it to project but it doesn't add it to my component.json.

I am trying bower register mypackage C:/mypackage but it keeps giving me

bower error Incorrect format

What am I doing wrong?

Answer

el2iot2 picture el2iot2 · Jan 28, 2013

Option 1: Public Bower registration

Bower is built mostly to share public (client-side) code in a "non-opinionated" manner. The primary use case, then, is to have a publicly accessible repository (on GitHub) that is registerd with a name and git repository url. I just did this myself:

bower register linksoup git://github.com/automatonic/linksoup

This is just telling the bower server that when you install linksoup to go and grab the code at the git://github.com/automatonic/linksoup repository, and put it in the local project's component directory.

If this is what you want to do, then just set up a repository on github/etc., push your code there, and then register with the resulting repository info.

Option 2: Private dependency

There are many reasons not to post your code at a publicly accessible repository. It may not be open source, etc. if your mypackage code is not meant to be public, then you should probably not be registering it on the public bower server... Further, even if you could register a local directory, it would only work on your machine...which defeats the purpose of sharing the code via bower.

If you just want to have bower manage a local, private dependency, then I am going to riff off of blockhead's solution:

{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1",
    "mypackage": "file:///path/to/mypackage/.git"
  }
}

This is just saying that myproject needs mypackage, and to use git clone to retrieve it. My guess is that this can use anything git can understand (including local repositories). But you should note that this may run into problems for anyone else working on this code that cannot access your local path.

Best Guess

It looks to me as if you may have assumed that bower register was a local operation (telling bower how to find a dependency via some sort of local registry). As far as I can tell, this is only a remote and public registration, which is why this is unsupported.

You may also be looking for a way to do something like a link operation with npm. That is, work on a dependency module without always having your dev cycle include a publish.

A little detail about how many people are involved and what you were trying to accomplish would facilitate a more targeted answer.