Installing a dependency with Bower from URL and specify version
I am trying to install a dependency with Bower using a URL. As of Bower documentation:
Bower offers several ways to install packages:
# Using the dependencies listed in the current directory's bower.json
bower install
# Using a local or remote package
bower install <package>
# Using a specific version of a package
bower install <package>#<version>
# Using a different name and a specific version of a package
bower install <name>=<package>#<version>
Where <package>
can be any one of the following:
- A name that maps to a package registered with Bower, e.g, jquery.
- A remote Git endpoint, e.g.,
git://github.com/someone/some-package.git
. Can be public or private. - A local endpoint, i.e., a folder that's a Git repository.
- A shorthand endpoint, e.g.,
someone/some-package
(defaults to GitHub). - A URL to a file, including zip and tar files. Its contents will be extracted.
However, then it says, that all the types except the URL allow to specify a version.
How do I specify a version for a URL downloaded dependency?
Solution 1:
Use a git endpoint instead of a package name:
bower install https://github.com/jquery/jquery.git#2.0.3
Solution 2:
If you use bower.json file to specify your dependencies:
{
"dependencies": {
...
"photo-swipe": "[email protected]:dimsemenov/PhotoSwipe.git#v3.0.x",
#bower 1.4 (tested with that version) can read repositorios with uri format
"photo-swipe": "git://github.com/dimsemenov/PhotoSwipe.git#v3.0.x",
}
}
Just remember bower also searches for released versions and tags so you can point to almost everything, and can interprate basic query patterns like previous example. that will fetch latest minor update of version 3.0 (tested from bower 1.3.5)
Update, as the question description also mention using only a URL and no mention of a github repository.
Another example is to execute this command using the desired url, like:
bower install gmap3MarkerWithLabel=http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.0/src/markerwithlabel.js -S
that command downloads your js library puts in {your destination path}/gmap3MarkerWithLabel/index.js and automatically creates an entry in your bower.json file called gmap3MarkerWithLabel: "..." After that, you can only execute bower update gmap3MarkerWithLabel
if needed.
Funny thing if you do the process backwars (add manually the entry in bower.json, an then bower install entryName) it doesn't work, you get a
bower ENOTFOUND Package gmapV3MarkerWithLabel not found
Solution 3:
Targeting a specific commit
Remote (github)
When using github, note that you can also target a specific commit (for example, of a fork you've made and updated) by appending its commit hash to the end of its clone url. For example:
"dependencies": {
"example": "https://github.com/owner_name/repo_name.git#9203e6166b343d7d8b3bb638775b41fe5de3524c"
}
Locally (filesystem)
Or you can target a git commit in your local file system if you use your project's .git directory, like so (on Windows; note the forward slashes):
"dependencies": {
"example": "file://C:/Projects/my-project/.git#9203e6166b343d7d8b3bb638775b41fe5de3524c"
}
This is one way of testing library code you've committed locally but not yet pushed to the repo.
Solution 4:
Use the following:
bower install --save git://github.com/USER/REPOS_NAME.git
More here: http://bower.io/#getting-started