2016-11-27 127 views
1

查看本地NPM包我得到一个特定NPM包一些node-gyp警告,在这种情况下,这个包是“获取光标位置”。我想知道我的本地node_modules目录中的哪些软件包取决于此软件包。 (这可能是不是很容易做到)。依赖于包X

如果我运行:

$ 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 <[email protected]>' ], 
    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 <[email protected]>', 
    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汇总数据显示所有依赖于get-cursor-position的软件包,并且我可以在我的结尾做一些手动工作以与本地软件包进行比较。

我也试过:

npm ls foo 

在我的情况,我想:

npm ls suman-events 

,它似乎并没有拿起我的预期是回暖。我希望它能在我的案例中找到“suman-example-reporter”=>

正如您在下图中看到的,“suman-example-reporter”是我项目中的一个直接依赖项(它在的package.json)和苏曼 - 例如,记者取决于“苏曼的事件”(和“苏曼事件”是的package.json为好,因为它也是我的项目的直接依赖关系)。

enter image description here

任何人都知道如何做到这一点吗?

+1

https://www.npmjs.com/browse/depended/get-cursor-position – thgaskell

+2

'npm ls get-cursor-position'是否工作?我不记得了。 – Ryan

回答

2

瑞安在评论中建议,npm ls <package>将显示有关指定软件包的依赖关系树,所以你可以看到,直接/间接地要求它的包。

例如,如果安装rimrafonce是一个依赖,并且可以查看哪个包使其与被安装:

$ npm ls once 
[email protected] /path/to/pkg 
└─┬ [email protected] 
    └─┬ [email protected] 
    └── [email protected] 

因此,可以看到,once安装因为glob需要它和(我在我的package.json指定)rimraf取决于glob

在需要扩展的信息,请使用npm ls --long(或者它的简写语法,npm la/npm ll)。 扩展输出也将包含模块描述,Git repo链接,README,并且肯定会在树中包含每个模块(有些可能会跳过基本的npm ls)。

+1

让我试一试,以确保它的工作将接受答案后,我验证 –

+0

这是好的,但它似乎并没有很好地工作,我已经看到了一些实验中,它没有拿起它的实例它可能应该 –

+0

好吧,所以它看起来像你真的想要“npm la once”,这将显示一个扩展列表 –

0

的页面上npmjs.com列出了所有的依赖包。在这种情况下,只有5个。

+1

OP似乎已经知道了这一点,他们并不真正需要它 - 他们想在本地为*他们的package.json做这件事。 – Aurora0001

+0

对,如果这是一个程序化的解决方案,更喜欢 –

1

npm ls <options>命令绝对是你想要的。

@极光的答案基本上是正确的

以下是该命令的文档:

https://docs.npmjs.com/cli/ls

它说

“当为L1或La运行,它显示扩展信息默认情况下。“

因此,要获得在您的项目依赖于x的依赖性的完整列表,请尝试:

$ npm la x 

,而不是

$ npm ls x