What is the recommended manifest JSON format for Bower packages? - json

Using the $ bower init command, I have created a bower.json for my package and registered it with Bower, no problem.
After looking at the Github homepages for some popular Bower packages, e.g. RequireJS and Modernizr, I've noticed their repo's don't contain a bower.json or a component.json. How is this possible?
I've also noticed that when I download any Bower package, the package contains a .bower.json file (note the dot in the beginning) and that file contains quite a bit more information than what I was asked during $ bower init for my package. For example, below is the .bower.json from Modernizr:
{
"name": "modernizr",
"homepage": "https://github.com/Modernizr/Modernizr",
"version": "2.6.2",
"_release": "2.6.2",
"_resolution": {
"type": "version",
"tag": "v2.6.2",
"commit": "ca45d02757b83367d8455d477e3cbc42dfdee035"
},
"_source": "git://github.com/Modernizr/Modernizr.git",
"_target": "~2.6.2",
"_direct": true
}
When I download my newly created package, it just contains the same info that I originally checked in to git.
Is there a new format for bower.json that I should be using? Or did I simply miss something in the setup process?

Bower doesn't need a bower.json or a component.json to install packages. The manifest file provide some useful info, like dependencies, ignored files, version and etc, but in the end it just downloads Git commits and place them somewhere.
In the case of Modernizr/Require.js, someone just registered their repos and Bower is retrieving a tag.
About the .bower.json file: this is generated by Bower itself after installing a package. It contains some more verbose info about a package, like the commit from which the package was retrieved, for example.
TL;DR: Keep using bower init, it'll do the right thing for you!

I am using Yeoman and the following is the content of my bower.json file. I thought it might help you. (I have installed all the latest versions of bower and grunt)
{
"name": "yowebapp",
"version": "0.0.0",
"dependencies": {
"sass-bootstrap": "~3.0",
"requirejs": "~2.1.4",
"modernizr": "~2.6.2",
"jquery": "~1.9.1",
"d3":"~3.3.2",
"angular":"1.0.7"
},
"devDependencies": {}
}
and I download my dependencies with bower install.

Related

grunt - config object

This sample grunt file https://gruntjs.com/sample-gruntfile reads in a config object from package.json and stores it in the pkg property:
pkg: grunt.file.readJSON('package.json')
However, the page doesn't give a sample package.json file. Later on it refers to pkg.name. I assume this is a top level key in package.json. E.g.
{
"name": "this value here",
}
Is that correct?
Yes that's correct.
The package.json file is the heart of npm which is used by grunt.
You can generate one for your project using npm initand filling out the options or you can manually create and update it.
It gets updated automatically when using the --save option when adding modules to grunt.
npm install grunt-contrib-copy --save
This will install the module to your node_modules folder and update the dependencies section in your package.json
You only need to save the package.json file in your repo and each developer can download all dependencies listed in your package.json by calling npm install

Cannot read Composer package from private hg repository on bitbucket

I am trying to use a Composer package from a private Mercurial repository on bitbucket. Composer says it can't find the package.
Let's call the package my-user/my-private-repo. For what it's worth, I've added my SSH public key to bitbucket for this repository. The composer.json file for the package looks like this:
{
"name": "my-user/my-private-repo",
"version": "0.0.1",
"description": "Some Composer Package",
"author": "me",
"license": "blah",
"require-dev": {
"phpunit/phpunit": "5.0.*"
}
}
And the composer.json for the project in which I want to use that package looks like:
{
"require": {
"my-user/my-private-repo": "^0.0.1"
},
"repositories": [
{
"type":"package",
"package":{
"name":"my-user/my-private-repo",
"version": "default",
"source":{
"type": "hg",
"url": "bitbucket.org/my-user/my-private-repo",
"reference":"default"
}
}
}
]
}
When I run composer update, I get the following error:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package my-user/my-private-repo could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
I've read everything I can find on SO that seems relevant, but I can't seem to get past this error. How can I use my Composer package in a project?
Don't use the "package" type. This is only really useful for software that is NOT inside a repository. It is meant as a replacement to integrate ZIP downloads into Composer.
Additionally, it is complicated to collect all necessary info for that "package" type.
Repositories are way easier:
"repositories": [
{
"type": "vcs",
"url": "ssh://hg#bitbucket.org/my-user/my-private-repo"
}
]
The repository must have a valid composer.json file - and it really helps if it also has tagged versions, because dependencies using branches will break eventually because you cannot signal backward incompatible changes and cannot go back to a defined earlier version.
The composer.json MUST NOT have a version. That's what repository tags are for.
Note: The "type":"vcs" works generally well and will detect Git, Hg, or SVN repos.

NPM installs older version & doesn't fully installs recursive dependencies

In a project I inherited, the packages.json looks roughly like this:
{
"name": "...",
"version": "...",
"description": "",
"author": "...",
"license": "ISC",
"dependencies": {
"lodash": "^3.10.1",
"assemble": "^0.4.37",
"cheerio": "^0.16.0",
"grunt": "^0.4.4",
"grunt-build-control": "^0.1.3",
},
"keywords": [
"handlebars-helper-md",
"handlebars-helper-rel"
]
}
When I first got it, lodash was ~2.4.1 and I'm trying to update it to 3.10.1 (as shown above). However, npm continues to install 2.4.1 at the top-level (Despite the package.json requesting the newer version) and it does not install the requested versions 2.4.1 or 2.4.2 in some of the dependencies (like assemble and cheerio). Thus when I npm install lodash#3.10.1 it complains about unmet dependencies.
I've tried removing node_modules and npm clear cache and rm -rf $HOME/.npm in different orders and combinations with no change.
How do I get lodash#3.10.1 to install at the top-level and the requested version of lodash in all the dependencies (and not have the dependencies use the top-level copy of lodash -- which I thought was the normal way for npm to work)?
Preferably a solution would not require updating all the dependencies to new versions (assuming that is even possible). That could be a solution, but that would require a lot more validation to make sure nothing broke.

How can I get bootswatch theme to work with my Gruntfile.js?

Problem
I have installed bootswatch slate theme into my bower.json. I did this as follows:
bower install bootswatch-dist#slate
grunt
Unfortunately, when my Grunftile is invoke, it does not update my wwwroot components with bootswatch. What am I doing wrong?
bower.json
{
"name": "SampleLibrary",
"version": "0.0.0",
"license": "MIT",
"private": true,
"dependencies": {
"jquery-validation": "~1.13.1",
"jquery-validation-unobtrusive": "~3.2.2",
"bootstrap": "~3.3.2",
"jquery-ui": "~1.11.3",
"bootswatch-dist": "slate"
}
}
Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
bower: {
install: {
options: {
targetDir: "wwwroot/lib",
layout: "byComponent",
cleanTargetDir: false,
}
}
}
});
//This command registers the default task which will install bower packages into wwwroot/lib
grunt.registerTask("default", ["bower:install"]);
//This command loads the grunt plugins
grunt.loadNpmTasks("grunt-bower-task");
};
Attempts
I followed the directions given at these resouces:
Similar problem to mine, but no solution given?
Gruntfile documentation I have grunt-bower-task. Still broke.
Ran bower info bootswatch-dist to confirm #slate is indeed there. It is.
What is really frustrating is everything else listed as a dependency in the bower.json file goes to wwwroot except bootswatch. I was able to get bootswatch into the bower file using bower install, but my Gruntfile.js is ignoring it?
I'm really confused. Please help. ASP.NET5 and MVC6 has great promise, but trying to figure out how to bring in new dependencies has proven trickier than I first thought.
The answer is to use bootswatch directly as follows: bower install bootswatch
If you add the version then it does install all of the documented assets. So add the following in your bower.json file:
"bootswatch-dist": "3.3.5-slate",

Bower error: ENOTFOUND Package bower-bootstrap-accordion not found

I am trying to install this plug in which is the Angular UI Bootstrap, I do not need the full library, only that plug in, and I am getting the error:
the command I am entering in the terminal:
bower install bower-bootstrap-accordion --save
and then the error:
Bower error: ENOTFOUND Package bower-bootstrap-accordion not found
here is the bower.json
{
"name": "bower-bootstrap-accordion",
"license": "MIT",
"version": "0.11.0",
"author": {
"name": "https://github.com/angular-ui/bootstrap/graphs/contributors"
},
"dependencies": {
"bower-bootstrap-collapse": "0.11.0"
},
"main": "ui-accordion-tpls.js"
}
Link to the plugin
do I have to install the full library ?
bower-bootstrap-accordion is not registered in the Bower registry and therefore the Bower client cannot find it by name.
You can use the Git repository URL when defining the dependency. This will save the Bower client the need to search for the package URL in the Bower registry.
"dependencies": {
"bower-bootstrap-accordion" : "git://github.com/ui-bootstrap-bower-test/bower-bootstrap-accordion.git"
}
In addition this package has dependencies on additional packages such as bower-bootstrap-collapse, bower-bootstrap-transition which are also not registered in the Bower registry. You will have to include it in the same way in your dependencies.
I think all those packages are from the same author - https://github.com/ui-bootstrap-bower-test/