如何在Composer中显示需要包的内容

joa*_*him 26 composer-php

我的作曲家刚刚告诉我,某个包foo/bar被放弃了.

但是,它没有在我的列表中列出composer.json,因此其他一些包将其作为依赖项.

我怎样才能让Composer向我展示这个?

例如,它可能告诉我,我的root composer.json需要一个/ b,这需要c/d,这反过来需要令人讨厌的foo/bar.

oke*_*_on 27

composer depends--tree选项一起使用。

例子:说我想看什么包依赖doctrine/data-fixtures包到_root_包的树状结构。

composer depends --tree doctrine/data-fixtures
Run Code Online (Sandbox Code Playgroud)

输出:

doctrine/data-fixtures 1.4.0 Data Fixtures for all Doctrine Object Managers
???doctrine/doctrine-fixtures-bundle 3.3.0 (requires doctrine/data-fixtures ^1.3)
   ???__root__ (requires (for development) doctrine/doctrine-fixtures-bundle ^3.3)
Run Code Online (Sandbox Code Playgroud)


Pᴇʜ*_*Pᴇʜ 23

composer show --tree
Run Code Online (Sandbox Code Playgroud)

将您的依赖项列为树.如果传递包名称,它将显示该包的依赖关系树.

有关更多信息,请参阅文档:https://getcomposer.org/doc/03-cli.md#show

  • 此外,我尝试使用已安装的软件包,这似乎与我所询问的情况相反:例如,'composer show --tree symfony-cmf/routing'似乎向我展示了symfony-cmf/routing需要什么,而不是请求symfony-cmf/routing. (2认同)

bis*_*hop 15

如果您具有深度依赖的包名称,并且您想知道它依赖于哪个依赖,请使用composer depends.

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 0 updates, 0 removals
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Writing lock file
Generating autoload files

$ composer depends guzzle/guzzle
aws/aws-sdk-php  2.8.31  requires  guzzle/guzzle (~3.7) 
Run Code Online (Sandbox Code Playgroud)

您对另一个答案的评论表明您试图解决依赖问题.以下是使用此示例的示例depends:

$ composer require phan/phan
Using version ^1.1 for phan/phan
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for composer/xdebug-handler (locked at 1.1.0) -> satisfiable by composer/xdebug-handler[1.1.0].
    - phan/phan 1.1.0 requires composer/xdebug-handler ^1.3 -> satisfiable by composer/xdebug-handler[1.3.0].
    - phan/phan 1.1.1 requires composer/xdebug-handler ^1.3 -> satisfiable by composer/xdebug-handler[1.3.0].
    - phan/phan 1.1.2 requires composer/xdebug-handler ^1.3 -> satisfiable by composer/xdebug-handler[1.3.0].
    - phan/phan 1.1.3 requires composer/xdebug-handler ^1.3 -> satisfiable by composer/xdebug-handler[1.3.0].
    - phan/phan 1.1.4 requires composer/xdebug-handler ^1.3 -> satisfiable by composer/xdebug-handler[1.3.0].
    - Conclusion: don't install composer/xdebug-handler 1.3.0
    - Installation request for phan/phan ^1.1 -> satisfiable by phan/phan[1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4].

Installation failed, reverting ./composer.json to its original content.

$ composer depends composer/xdebug-handler
friendsofphp/php-cs-fixer  v2.12.1  requires  composer/xdebug-handler (^1.0)
Run Code Online (Sandbox Code Playgroud)

所以,我想phan/phan,但由于版本问题而失败composer/xdebug-handler,这不是我曾经明确要求的软件包.

然后我问什么包"依赖" composer/xdebug-handler并发现它friendsofphp/php-cs-fixer需要它(我知道那个包,它依赖于root).

然后我注意到phan/phan希望composer/xdebug-handler:^1.3 (从依赖)friendsofphp/php-cs-fixer 允许我有1.3版本.所以现在我只是做一个更新:

$ composer update composer/xdebug-handler
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating composer/xdebug-handler (1.1.0 => 1.3.0): Loading from cache
Writing lock file
Generating autoload files

$ composer require phan/phan
Using version ^1.1 for phan/phan
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
  - Installing sabre/event (5.0.3): Loading from cache
  - Installing microsoft/tolerant-php-parser (v0.0.15): Loading from cache
  - Installing netresearch/jsonmapper (v1.4.0): Loading from cache
  - Installing felixfbecker/advanced-json-rpc (v3.0.3): Loading from cache
  - Installing phan/phan (1.1.4): Loading from cache
phan/phan suggests installing ext-ast (Needed for parsing ASTs (unless --use-fallback-parser is used). php-ast ^0.1.5|^1.0.0 is needed.)
Writing lock file
Generating autoload files
Run Code Online (Sandbox Code Playgroud)


Rol*_*oro 9

这个问题已经得到了回答,但在我看来,Composer 提供了一种更雄辩的方式,之前没有提到过:depends命令别名why

composer why旨在回答“为什么安装这个包?” 问题,而不是“哪些包依赖于这个包?” ,我觉得这更容易记住。

作为别名,该why命令的行为depends与上述两个选项相同:

  • --recursive (-r):递归解析到根包;
  • --tree (-t):将结果打印为嵌套树,暗示 -r。