我部署了 Node.js 的 0.6 版本,其中为各种项目安装了大量软件包。
有没有一种直接的方法来检查使用 NPM 安装的所有软件包,看看它们是否支持 Node.js v 0.8.x?
我可以看到 package.json 文件应该说明它们适用的 Node 版本,尽管我猜很多人不会包含这个 - 所以我真的只对那些说它们绝对不兼容 Node v 0.8 的包感兴趣。X
例如,他们在 package.json 中有这样的东西:
"engines": {
"node": "<0.8.0"
},
Run Code Online (Sandbox Code Playgroud)
或者
"engines": {
"node": "=0.6.*"
},
Run Code Online (Sandbox Code Playgroud)
我只想要一个不兼容的包的简单列表。
在应用程序的基目录中尝试以下操作:
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, ")") }' '{}' \;
Run Code Online (Sandbox Code Playgroud)
翻译成正常风格:
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, ")");
}
}
Run Code Online (Sandbox Code Playgroud)
然后我们find在所有package.json能找到的地方运行它。
这是我在express-template.coffee包上运行它时得到的结果:
./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 )
Run Code Online (Sandbox Code Playgroud)
看来TJ很反对 0.8 ;-)
| 归档时间: |
|
| 查看次数: |
349 次 |
| 最近记录: |