I have a deployed version 0.6 of Node.js with a considerable number of packages installed for various projects.
Is there a straight-forward way to check all of the packages that were installed using NPM to see if they support Node.js v 0.8.x?
I can see that the package.json files should say what version of Node they are for though I'm guessing that many will not include this - so I'm really only interested in packages that say they are definately not compatible with Node v 0.8.x
e.g. They have something like this in package.json:
"engines": {
"node": "<0.8.0"
},
or
"engines": {
"node": "=0.6.*"
},
I just want a simple list of packages that are incompatible.
Try this in the base directory of your application:
find . -name package.json -exec node -e 'var e = JSON.parse(require("fs").readFileSync(process.argv[1]))["engines"]; if (e && e.node) { var bad = false; if (e.node.match(/<\s*0\.[0-8]([^.]|\.0)/)) bad = true; if (e.node.match(/(^|[^>])=\s*0\.[^8]/)) bad = true; if (bad) console.log(process.argv[1], "appears no good (", e.node, ")") }' '{}' \;
Translation into normal style:
var fs = require("fs");
var contents = fs.readFileSync(process.argv[1]);
var package = JSON.parse(contents);
var engines = package.engines;
if (engines && engines.node) {
var node = engines.node,
bad = false;
if (node.match(/<\s*0\.[0-8]([^.]|\.0)/)) {
// Looks like "< 0.8.0" or "< 0.8" (but not "< 0.8.1").
bad = true;
}
if (node.match(/(^|[^>])=\s*0\.[^8]/)) {
// Looks like "= 0.7" or "= 0.9" (but not ">= 0.6").
bad = true;
}
if (bad) {
console.log(process.argv[1], "appears no good (", node, ")");
}
}
We then use find
to run this on every package.json
we can find.
Here's what I get when I run it over my express-template.coffee package:
./node_modules/jade/node_modules/commander/package.json appears no good ( >= 0.4.x < 0.8.0 )
./node_modules/mocha/node_modules/commander/package.json appears no good ( >= 0.4.x < 0.8.0 )
./node_modules/mocha/package.json appears no good ( >= 0.4.x < 0.8.0 )
It seems TJ has a thing against 0.8 ;-)