Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if npm packages support Node.js v0.8.x?

Tags:

node.js

npm

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.

like image 787
Julian Knight Avatar asked Oct 07 '22 09:10

Julian Knight


2 Answers

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 ;-)

like image 133
Asherah Avatar answered Oct 13 '22 09:10

Asherah


npm view <packageName> engines

See the npm view documentation for more info.

For example:

npm view jest verson returns the latest version, in my case 27.1.0 npm view jest engines gives you:

{ node: '^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0' }

Which tells you the latest version of jest, v27, supports node 10.13, 12.13, 14.15, and 15.

npm view jest@25 engines however, tells you it supports anything over node 8.3:

[email protected] { node: '>= 8.3' }
[email protected] { node: '>= 8.3' }
[email protected] { node: '>= 8.3' }

(this response is to an old question, but it still come up on my Google search)

like image 41
Dmitri R117 Avatar answered Oct 13 '22 10:10

Dmitri R117