node.js和npm v3:如何在package.json中添加Travistesting兼容的peerDependencies

通过package.json中的peerDependencies ,我可以确保用户在应用程序的rootfolder中有一个特定的模块:

module_a

var modB = require('module_b') ... 

module_a的package.json

 ... "peerDependencies": { "module_b": "^1.0.1" }, "dependencies": { }, ... 

my_app应用

 var modA = require('module_a') var modB = require('module_b') ... 

文件结构

使用npm v1 / v2这个configuration工作npm install module_a完美: npm install module_a module_a在根文件npm install module_a安装module_a和module_b:

 my_app node_modules module_a module_b 

太好了,那就是我想要的!

npm v3

但是在使用npm install module_a进行npm install module_a ,npm v2会显示以下警告:

 npm WARN peerDependencies The peer dependency module_b@^1.0.1 included from module_a will no longer be automatically installed to fulfill the peerDependency in npm 3+. Your application will need to depend on it explicitly. 

所以,npm v3不会自动安装peer dependency,为了达到同样的效果我必须手动安装my_app

问题

但是在使用npm v3的testing中呢?

npm v3不会安装peer dependency,所以travis会失败,因为找不到module_b 。 但是我不能将模块添加为常规依赖项,因为my_appmodule_a使用了不同的module_b的 “实例”

 my_app node_modules module_a node_modules module_b // used by module_a module_b // used by my_app 

这不是我想要的,因为module_a改变了module_b中的一些参数,但是这个改变在my_app中是不可见的。

我怎么能添加module_b作为(对等)依赖关系的根文件夹,而不会打破module_a的travistesting?

谢谢。

如果一个模块不在依赖关系列表中,但是需要运行testing,那么你应该把它列为devDependency(不pipe它是否也是peerDependency)。

我通过在travis'before_install钩子中安装对等体依赖关系来解决这个问题。
我的.travis.yml如下所示:

 language: node_js node_js: - "6.1" - "5.11" - "4.4" before_install: - "npm install peerDependency"