Can Bower resolve recursive dependencies correctly? - polymer

I'm trying to create a package containing "Polymer/polymer" and "Polymer/core-elements" both having specific version 0.3.5.
$ cat bower.json
{
"name": "bower-test",
"private": true,
"dependencies": {
"polymer": "Polymer/polymer#0.3.5",
"core-elements": "Polymer/core-elements#0.3.5"
},
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
$ bower --version
1.3.10
When I try to install the dependencies, bower reports about conflicts in polymer version resolution:
$ bower install
bower not-cached git://github.com/Polymer/polymer.git#0.3.5
bower resolve git://github.com/Polymer/polymer.git#0.3.5
bower not-cached git://github.com/Polymer/core-elements.git#0.3.5
bower resolve git://github.com/Polymer/core-elements.git#0.3.5
bower download https://github.com/Polymer/core-elements/archive/0.3.5.tar.gz
bower download https://github.com/Polymer/polymer/archive/0.3.5.tar.gz
bower extract core-elements#0.3.5 archive.tar.gz
bower invalid-meta core-elements is missing "main" entry in bower.json
bower invalid-meta core-elements is missing "ignore" entry in bower.json
bower resolved git://github.com/Polymer/core-elements.git#0.3.5
bower not-cached git://github.com/Polymer/core-ajax.git#>=0.3.0 <1.0.0
bower resolve git://github.com/Polymer/core-ajax.git#>=0.3.0 <1.0.0
-------------------------- skipped -------------------------------------
bower download https://github.com/Polymer/core-ajax/archive/0.4.0.tar.gz
-------------------------- skipped -------------------------------------
bower not-cached git://github.com/Polymer/polymer.git#>=0.4.0 <1.0.0
bower resolve git://github.com/Polymer/polymer.git#>=0.4.0 <1.0.0
-------------------------- skipped -------------------------------------
bower download https://github.com/Polymer/polymer/archive/0.4.0.tar.gz
Unable to find a suitable version for polymer, please choose one:
1) polymer#>=0.3.0 <1.0.0 which resolved to 0.3.5 and is required by core-elements#0.3.5, core-layout#0.3.5
2) polymer#0.3.5 which resolved to 0.3.5 and is required by bower-test
3) polymer#>=0.4.0 <1.0.0 which resolved to 0.4.0 and is required by core-ajax#0.4.0, core-animated-pages#0.4.0, core-animation#0.4.0, core-collapse#0.4.0, core-component-page#0.4.0, core-dropdown#0.4.0, core-field#0.4.0, core-header-panel#0.4.0, core-icons#0.4.0, core-iconset#0.4.0, core-iconset-svg#0.4.0, core-input#0.4.0, core-layout-grid#0.4.0, core-layout-trbl#0.4.0, core-list#0.4.0, core-localstorage#0.4.0, core-media-query#0.4.0, core-menu-button#0.4.0, core-meta#0.4.0, core-overlay#0.4.0, core-popup-menu#0.4.0, core-range#0.4.0, core-selection#0.4.0, core-selector#0.4.0, core-shared-lib#0.4.0, core-signals#0.4.0, core-splitter#0.4.0, core-style#0.4.0, core-tooltip#0.4.0, core-transition#0.4.0, marked-element#0.4.0, prettify-element#0.4.0
Full log
If I understand things right, that is what bower does:
Fetches core-elements#0.3.5
Sees that core-elements#0.3.5 depends on core-ajax#>=0.3.0
Fetches a latest version of core-ajax which is core-ajax#0.4.0
Sees that core-ajax#0.4.0 depends on polymer#>=0.4.0
Reports an error, because we specified exact version 0.3.5 for polymer in bower.json.
A valid configuration for dependencies does exist (take core-ajax#0.3.5, which depends on polymer#>=0.3.5), however bower is not able to find such configuration. Worse, it doesn't even try.
Am I doing something wrong? If not, is there some solution?

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

How run Polymer code example?

I have downloaded this example : PolymerElements/app-layout-templates
..and I can't make it work (whereas I was able to access this one : PolymerElements/polymer-starter-kit)
I ran the following lines in the terminal :
bower init
bower -save polymer
bower bower install –save Polymer/polymer-elements Polymer/polymer-ui-elements
bower update
...and then accessed the folder via a python server.
Do you have some tips to make it work ?
If you want to try out PolymerElements/app-layout-templates then that's what you need to install on bower. Bower will download all the required dependencies for app-layout-templates to work.
bower install --save PolymerElements/app-layout-templates
After this you can start python server on folders app-layout-template, app-layout-template/nav-view etc to see how it works.
Also the repositories Polymer/polymer-elements, Polymer/polymer-ui-elements are invalid. The polymer elements are available in github repository https://github.com/PolymerElements. So to download polymer elements try something like below
bower install --save PolymerElements/iron-elements
bower install --save PolymerElements/paper-elements
bower install --save PolymerElements/neon-elements
bower install --save PolymerElements/platinum-elements

devDependencies ignored in npm?

I am the author of two npm modules, both with devDependencies.
The first one is simpleDbLayer. Install it:
npm install simpledblayer
The downloaded package.js file has devDependencies matching what is in the git repository:
//...
"devDependencies": {
"simpleschema": "0.3.x"
},
//...
Unfortunately, nodeunit test.js will fail because simpleschema wasn't installed (as it should have been). From the manual:
By default, npm install will install all modules listed as dependencies. With the --production flag, npm will not install modules listed in devDependencies
Even weirder (and this is the really strange issue I am most affected by) is my other module, simpledblayer-mongo:
npm install simpledblayer-mongo
In he installed package.js file, I have:
"devDependencies": {},
Which doesn't match what was actually published, which contains:
"devDependencies": {
"simpleschema": "0.3.x",
"simpleschema-mongo": "0.3.x"
},
Needless to say simpleschema and simpleschema-mongo is not installed.
Am I missing something?
Yes, by default it will install the devDependencies but only for your project (devDependencies in your package.json), not for modules in the npm repository.
If you want the devDependencies of your dependencies, force it by passing --dev to the npm command:
npm install simpledblayer --dev
Also, when you have the environment variable NODE_ENV set to production, it won't install the devDependencies either (not even the ones in your package.json).

How can I use npm to download and update modules from a list in a package.json file?

I am using windows with node.js downloaded. I created this package.json.
{
"version": "0.0.0",
"name": "abc",
"devDependencies": {
"del": "^1.1.0",
"gulp-uglify": "^1.0.2",
"gulp-sourcemaps": "^1.2.8",
"gulp-typescript": "^2.3.0",
"less-plugin-clean-css": "^1.2.0",
"typescript": "^1.3.0"
}
}
Is there an npm command line task that I can run to fetch all of these modules and install / update these into a node_modules directory? If needed I can change my package.json so I would appreciate advice on that also.
Thanks
Doesn't
"npm install"
do the trick? (from your folder that contains the package.json)
It works on linux, haven't a window machine to try right now
try
npm install
npm update --save-dev
If you already had the package.json file (with dependencies entries), then you can use npm install to install dependencies on node_modules directory.
npm install
or you can update the dependencies to use latest version (will override currently installed dependencies on node_modules directory) using npm update
npm update
You don't have to put the dependency you want manually to package.json, you just use command npm install {package-name} with additional option like --save / --save-dev / --save-optional.
In example you want to add dependency of node-q to your application, you can do this:
npm install q --save
Juggling into different option --save-prefixed value will act as follows,
--save will add dependency to dependencies attribute of your package.json, it will be installed mainly for your application
--save-dev will add dependency to devDependencies attribute of your package.json, it will be installed for development phase of your application (usually it is testing dependencies)
--save-optional will installed for optional (nice to have) dependencies. I rarely used it for my applications or libraries anyway.
Don't forget you MUST run commands from your application directory (the one that node_modules directory resides).

What is the recommended manifest JSON format for Bower packages?

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.