查看依赖于软件包X的本地NPM软件包
我得到了一些特定NPM包的node-gyp
警告,在这种情况下,包是“get-cursor-position”。 我想找出我的本地node_modules目录中的哪些包取决于这个包。 (这可能不容易)。
如果我运行:
$ npm view get-cursor-position
我得到:
{ name: 'get-cursor-position', description: 'Get the cursor\'s current position in your terminal.', 'dist-tags': { latest: '1.0.3' }, versions: [ '0.0.1', '0.0.2', '0.0.4', '0.0.5', '1.0.0', '1.0.1', '1.0.2', '1.0.3' ], maintainers: [ 'bubkoo <bubkoo@163.com>' ], time: { modified: '2016-11-01T02:36:07.728Z', created: '2016-03-05T03:42:31.517Z', '0.0.1': '2016-03-05T03:42:31.517Z', '0.0.2': '2016-03-07T00:35:36.627Z', '0.0.4': '2016-03-10T07:21:21.364Z', '0.0.5': '2016-03-10T07:25:04.846Z', '1.0.0': '2016-04-16T08:11:34.546Z', '1.0.1': '2016-06-03T15:57:55.767Z', '1.0.2': '2016-06-13T14:19:32.966Z', '1.0.3': '2016-11-01T02:36:07.728Z' }, homepage: 'https://github.com/bubkoo/get-cursor-position', keywords: [ 'terminal', 'console', 'cursor', 'position', 'ansi', 'escape' ], repository: { type: 'git', url: 'git+https://github.com/bubkoo/get-cursor-position.git' }, author: 'bubkoo <bubkoo.wy@gmail.com>', bugs: { url: 'https://github.com/bubkoo/get-cursor-position/issues' }, license: 'MIT', readmeFilename: 'README.md', version: '1.0.3', main: 'index.js', scripts: { test: 'echo "Error: no test specified" && exit 1', install: 'node-gyp rebuild' }, gypfile: true, gitHead: '56d403bb0e554532d17c403c47421ce8d2db2dec', dist: { shasum: '0e41d60343b705836a528d69a5e099e2c5108d63', tarball: 'https://registry.npmjs.org/get-cursor-position/-/get-cursor-position-1.0.3.tgz' }, directories: {} }
我相信npm视图只会查找包的远程数据,我很高兴使用NPM上的聚合数据显示依赖于get-cursor-position
所有包,我可以在我的一端做一些手动工作来比较与本地包。
我也试过:
npm ls foo
就我而言,我尝试过:
npm ls suman-events
它似乎没有拿起我期望它拿起。 我本来期望它能在我的案例中find“suman-example-reporter”=>
正如你在下面的图片中看到的,“suman-example-reporter”是我的项目中的一个直接依赖项(在package.json中),suman-example-reporter依赖于“suman-events”(和“suman-events”也在package.json中,因为它也是我的项目的直接依赖)。
任何人都知道如何做到这一点?
正如Ryan在注释中所build议的那样, npm ls <package>
将显示与指定包相关的依赖关系树,因此您可以看到哪些包直接/间接需要它。
例如,如果您安装了rimraf
,则once
是依赖项,并且您可以查看哪个程序包导致它被安装:
$ npm ls once yourpackage@1.0.0 /path/to/pkg └─┬ rimraf@2.5.4 └─┬ glob@7.1.1 └── once@1.4.0
因此,你可以看到once
被安装,因为glob
需要它, rimraf
(我在package.json
指定)依赖于glob
。
在需要扩展信息的地方,使用npm ls --long
(或者简写语法npm la
/ npm ll
)。 扩展输出还将包含模块描述,Git repo链接,README,并且肯定会包含树中的每个模块 (有些可能会跳过基本的npm ls
)。
npm ls <options>
命令绝对是你想要的。
@极光的答案基本上是对的
以下是该命令的文档:
它说
“按照ll或la运行时,默认显示扩展信息。”
因此,要获取项目中依赖x的完整依赖列表,请尝试:
$ npm la x
代替
$ npm ls x
npmjs.com上的页面列出了所有相关的软件包。 在这种情况下,只有5个。