gpt4 book ai didi

node.js 和 npm v3 : How to add Travis tests compatible peerDependencies in package. json

转载 作者:搜寻专家 更新时间:2023-10-31 22:20:37 26 4
gpt4 key购买 nike

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

module_a

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

module_a的package.json

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

我的应用

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

文件结构

对于 npm v1/v2,此配置完美运行:npm install module_a 在根文件夹中安装 module_amodule_b:

my_app
node_modules
module_a
module_b

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

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.

因此,npm v3 不会自动安装对等依赖项,我必须为 my_app 手动安装它才能达到相同的结果。

问题

但是在我使用 npm v3 的测试中呢?

npm v3 没有安装 peer 依赖,所以 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_a 的 travis 测试的情况下将 module_b 作为(对等)依赖项添加到根文件夹中?

谢谢。

最佳答案

如果模块不在依赖项列表中但需要运行测试,那么您应该将其列为 devDependency(无论它是否也是 peerDependency)。

关于node.js 和 npm v3 : How to add Travis tests compatible peerDependencies in package. json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33618987/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com