npm8中文文档
考虑这个依赖图:
foo
+-- blerg@1.2.5
+-- bar@1.2.3
| +-- blerg@1.x (latest=1.3.7)
| +-- baz@2.x
| | `-- quux@3.x
| | `-- bar@1.2.3 (cycle)
| `-- asdf@*
`-- baz@1.2.3
`-- quux@3.x
`-- bar
在这种情况下,我们可能期望这样的文件夹结构:
foo
+-- node_modules
+-- blerg (1.2.5) <---[A]
+-- bar (1.2.3) <---[B]
| `-- node_modules
| +-- baz (2.0.2) <---[C]
| | `-- node_modules
| | `-- quux (3.2.0)
| `-- asdf (2.3.4)
`-- baz (1.2.3) <---[D]
`-- node_modules
`-- quux (3.2.0) <---[E]
由于 foo 直接依赖于 bar@1.2.3
和 baz@1.2.3
,因此它们安装在 foo 的 node_modules
文件夹中。
尽管 blerg 的最新版本是 1.3.7,但 foo 对 1.2.5 版本有特定的依赖关系。所以,它被安装在[A]。由于blerg的父安装满足bar对blerg@1.x
的依赖,所以没有在[B]下安装另一个副本。
Bar [B] 也依赖于 baz 和 asdf,所以它们安装在 bar 的 node_modules
文件夹中。因为它依赖于baz@2.x
,所以它不能重复使用安装在父node_modules
文件夹[D]中的baz@1.2.3
,必须安装自己的副本[C]。
在条形下方,baz -> quux -> bar
依赖项创建了一个循环。但是,因为 bar 已经在 quux 的祖先 [B] 中,所以它不会将 bar 的另一个副本解压缩到该文件夹中。
在 foo -> baz
[D] 下面,quux 的 [E] 文件夹树是空的,因为它对 bar 的依赖由安装在 [B] 的父文件夹副本满足。
有关安装位置的图形细分,请使用 npm ls
。