查看依赖包 X 的本地 NPM 包 [英] View local NPM packages that depend on package X

查看:41
本文介绍了查看依赖包 X 的本地 NPM 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了一些针对特定 NPM 包的 node-gyp 警告,在这种情况下,该包是get-cursor-position".我想找出我本地 node_modules 目录中的哪些包依赖于这个包.(这可能不容易做到).

I am getting some node-gyp warnings for a particular NPM package, in this case the package is "get-cursor-position". I would like to find out which packages in my local node_modules directory depend on this package. (This might not be easy to do).

如果我跑:

$ 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 view 只会查找包的远程数据,我很高兴使用 NPM 上的聚合数据显示所有依赖于 get-cursor-position 的包,并且我可以在我这边做一些手动工作来与本地包进行比较.

I believe npm view will just look up the remote data for the package, I am happy to use the aggregate data on NPM showing all the packages that depend on get-cursor-position, and I can do some manual work on my end to compare with local packages.

我也试过:

npm ls foo

就我而言,我尝试过:

npm ls suman-events

它似乎没有达到我预期的效果.在我的情况下,我原以为它会选择suman-example-reporter"=>

and it didn't seem to pick up what I expected it to pick up. I would have expected it to pick up "suman-example-reporter" in my case =>

如下图所示,suman-example-reporter"是我项目中的直接依赖项(位于 package.json 中),而 suman-example-reporter 依赖于suman-events"(和suman-events"也在 package.json 中,因为它也是我项目的直接依赖项).

As you can see in the image below, "suman-example-reporter" is a direct dependency in my project (it's in package.json) and suman-example-reporter depends on "suman-events" (and "suman-events" is in package.json as well, because it's also a direct dependency of my project).

有人知道怎么做吗?

推荐答案

正如 Ryan 在评论中建议的那样,npm ls 将显示与指定包相关的依赖树,因此您可以看到哪些包直接/间接需要它.

As Ryan suggested in the comments, npm ls <package> will show the dependency tree relating to the specified package, so you can see which packages directly/indirectly require it.

例如,如果你安装了 rimrafonce 是一个依赖,你可以查看是哪个包导致它被安装:

For example, if you install rimraf, once is a dependency, and you can view which package causes it to be installed with:

$ 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.

Hence, you can see that once was installed because glob requires it, and rimraf (which I specified in my package.json) depended on glob.

如果需要扩展信息,请使用 npm ls --long(或者它的速记语法,npm la/npm ll).扩展输出还将包括模块描述、Git repo链接、自述文件,并且肯定会包括树中的每个模块(有些可能会被基本的npm跳过ls).

Where extended information is needed, use npm ls --long (or it's shorthand syntax, npm la / npm ll). The extended output will also include the module description, Git repo link, README and will definitely include every module in the tree (some may be skipped with the basic npm ls).

这篇关于查看依赖包 X 的本地 NPM 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆