node.js和npm v3:如何在package.json中添加与Travis测试兼容的peerDependencies

use*_*778 8 node.js npm

使用package.json中的peerDependencies,我可以确保用户在应用程序根文件夹中有一个特定的模块:

module_a

var modB = require('module_b')
...
Run Code Online (Sandbox Code Playgroud)

module_a的package.json

...
"peerDependencies": {
  "module_b": "^1.0.1"
},
"dependencies": {
},
...
Run Code Online (Sandbox Code Playgroud)

my_app应用

var modA = require('module_a')
var modB = require('module_b')
...
Run Code Online (Sandbox Code Playgroud)

文件结构

使用npm v1/v2,这个配置非常完美:在rootfoldernpm install module_a安装module_a和module_b:

my_app
  node_modules
    module_a
    module_b
Run Code Online (Sandbox Code Playgroud)

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

npm v3

但在安装时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.
Run Code Online (Sandbox Code Playgroud)

所以,npm v3不会自动安装对等依赖项,我必须手动为my_app安装它才能达到相同的效果.

问题

但是在我的测试中使用npm v3怎么样?

npm v3没有安装对等依赖项,因此travis将失败,因为它找不到module_b.但我可以在模块不能添加作为常规的依赖,因为比my_app应用module_a使用不同的"实例" module_b:

my_app
  node_modules
    module_a
      node_modules
        module_b         // used by module_a
    module_b             // used by my_app
Run Code Online (Sandbox Code Playgroud)

这不是我想要的,因为module_a改变某些参数module_b,但这种变化是不可见的my_app应用.

如何在不破坏module_a的travis测试的情况下,在rootfolder中添加module_b作为(对等)依赖

谢谢.

sty*_*uxx 3

我通过在 travis 的before_install挂钩中安装对等依赖项解决了这个问题。
我的.travis.yml看起来像这样:

language: node_js
node_js:
  - "6.1"
  - "5.11"
  - "4.4"
before_install:
  - "npm install peerDependency"
Run Code Online (Sandbox Code Playgroud)