欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

pom依赖各节点说明_节点模块中的对等依赖性是什么?

程序员文章站 2024-03-23 10:14:28
...

pom依赖各节点说明

In some package.json files, you might see a few lines like this:

在一些package.json文件中,您可能会看到几行这样的内容:

{
  //...
  "peerDependencies": {
    "libraryName": "1.x"
  }
}

You might have already seen dependencies and devDependencies, but not peerDependencies.

您可能已经看到了dependenciesdevDependencies ,但没有peerDependencies

dependencies are the packages your project depends on.

dependencies是项目所dependencies的包。

devDependencies are the packages that are needed during the development phase. Say a testing framework like Jest or other utilities like Babel or ESLint.

devDependencies是开发阶段所需的软件包。 说一个测试框架,例如Jest或其他实用程序,例如BabelESLint

In both cases, when you install a package, its dependencies and devDependencies are automatically installed by npm.

在这两种情况下,安装软件包时, npm都会自动安装其依赖项和devDependencies。

peerDependencies are different. They are not automatically installed.

peerDependencies不同。 它们不会自动安装。

When a dependency is listed in a package as a peerDependency, it is not automatically installed. Instead, the code that includes the package must include it as its dependency.

在包中将依赖项作为peerDependency列出时, 不会自动安装 。 而是,包含程序包的代码必须包含它作为其依赖项。

npm will warn you if you run npm install and it does not find this dependency.

如果您运行npm installnpm会警告您,并且找不到此依赖项。

Example: let’s say package a includes dependency b:

示例:假设包a包括依赖项b

a/package.json

a/package.json

{
  //...
  "dependencies": {
    "b": "1.x"
  }
}

Package b in turn wants package c as a peerDependency:

程序包b又希望程序包c作为peerDependency:

b/package.json

b/package.json

{
  //...
  "peerDependencies": {
    "c": "1.x"
  }
}

In package A, we must therefore add c as a dependency, otherwise when you install package b, npm will give you a warning (and the code will likely fail at runtime):

因此,在软件包A中,我们必须将c添加为依赖项,否则,在安装软件包b ,npm会向您发出警告(并且代码可能会在运行时失败):

a/package.json

a/package.json

{
  //...
  "dependencies": {
    "b": "1.x",
    "c": "1.x"
  }
}

The versions must be compatible, so if a peerDependency is listed as 2.x, you can’t install 1.x or another version. It all follows semantic versioning.

这些版本必须兼容,因此,如果peerDependency列为2.x ,则不能安装1.x或其他版本。 全部遵循语义版本控制

翻译自: https://flaviocopes.com/npm-peer-dependencies/

pom依赖各节点说明