npm列表如何知道哪些是直接依赖关系?
在input以下三个命令之后直接进入一个新的命令:
npm install underscore npm install lodash npm install express
我得到一个包含许多软件包的node_modules
目录:
$ ls node_modules accepts cookie-signature encodeurl forwarded lodash mime-db parseurl send underscore array-flatten debug escape-html fresh media-typer mime-types path-to-regexp serve-static unpipe content-disposition depd etag http-errors merge-descriptors ms proxy-addr setprototypeof utils-merge content-type destroy express inherits methods negotiator qs statuses vary cookie ee-first finalhandler ipaddr.js mime on-finished range-parser type-is
在使用npm list
,我可以得到一个树结构:
$ npm list /tmp/play/npm ├─┬ express@4.14.0 │ ├─┬ accepts@1.3.3 │ │ ├─┬ mime-types@2.1.13 │ │ │ └── mime-db@1.25.0 │ │ └── negotiator@0.6.1 │ ├── array-flatten@1.1.1 │ ├── content-disposition@0.5.1 │ ├── content-type@1.0.2 │ ├── cookie@0.3.1 │ ├── cookie-signature@1.0.6 │ ├─┬ debug@2.2.0 │ │ └── ms@0.7.1 │ ├── depd@1.1.0 │ ├── encodeurl@1.0.1 │ ├── escape-html@1.0.3 │ ├── etag@1.7.0 │ ├─┬ finalhandler@0.5.0 │ │ ├── statuses@1.3.1 │ │ └── unpipe@1.0.0 │ ├── fresh@0.3.0 │ ├── merge-descriptors@1.0.1 │ ├── methods@1.1.2 │ ├─┬ on-finished@2.3.0 │ │ └── ee-first@1.1.1 │ ├── parseurl@1.3.1 │ ├── path-to-regexp@0.1.7 │ ├─┬ proxy-addr@1.1.2 │ │ ├── forwarded@0.1.0 │ │ └── ipaddr.js@1.1.1 │ ├── qs@6.2.0 │ ├── range-parser@1.2.0 │ ├─┬ send@0.14.1 │ │ ├── destroy@1.0.4 │ │ ├─┬ http-errors@1.5.1 │ │ │ ├── inherits@2.0.3 │ │ │ └── setprototypeof@1.0.2 │ │ └── mime@1.3.4 │ ├── serve-static@1.11.1 │ ├─┬ type-is@1.6.14 │ │ └── media-typer@0.3.0 │ ├── utils-merge@1.0.0 │ └── vary@1.1.0 ├── lodash@4.17.2 └── underscore@1.8.3
我的问题是: 从所有这些依赖关系中, npm list
如何知道哪些是我的直接依赖关系,比如说undersocre
, lodash
和express
?
注意:我没有package.json
文件。
它根据模块的依赖关系build立列表。 模块的dependencies
在dependencies
字段中的每个模块的package.json
中指定。 当你安装一个模块时, npm
在模块的package.json
增加了一些额外的字段,其中一个是_requiredBy
字段,用于在另一个方向上存储依赖链接。 如果运行npm list
命令,它将遍历所有模块,并读取每个模块的package.json
中的_requiredBy
字段。
如果直接安装模块而不保存到package.json
, npm
将#USER
添加到_requiredBy
字段,以表示您手动安装了该模块,而不仅仅是其他模块的依赖关系。 然后, npm list
也在树的根部显示该模块。
npm list
命令将打印出标准输出所安装的所有版本的软件包以及它们的依赖关系。
所以你只安装了三个软件包
npm install underscore npm install lodash npm install express
所有其他的软件包是express
包装的依赖