ChatGPT解决这个技术问题 Extra ChatGPT

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

我的 Composer 刚刚告诉我某个包 foo/bar 被放弃了。

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

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

例如,它可能会告诉我我的根 composer.json 需要 a/b,它需要 c/d,而 c/d 又需要有问题的 foo/bar。


P
Pᴇʜ
composer show --tree

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

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


这很好,但不完整。例如,我的作曲家告诉我“请求的包 foo/bar”存在约束问题,但“composer show --tree foo/bar”说找不到。
@joachim 这很奇怪,因为它应该列出所有已安装的软件包,包括。子包由于其文档。需要 foo/bar 的软件包是否有可能由于限制而未安装,因此不在树中?如果我们可以看到您的 composer.json 和完整的错误消息以及您尝试执行的操作说明,会更容易找到解决方案。
事实上,由于限制, foo/bar 不会安装。所以我想知道约束的层次结构是什么,这样我就可以解决这个问题。
此外,我尝试使用已安装的软件包进行此操作,这似乎与我所询问的相反:例如,'composer show --tree symfony-cmf/routing' 似乎向我展示了 symfony-cmf/routing 需要什么,而不是什么请求 symfony-cmf/routing。
然后看一下 prohibits command:它告诉您哪些软件包阻止了给定软件包的安装。
b
bishop

如果您有 deep 依赖项的包名称,并且想知道它属于哪个 root 依赖项,请使用 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) 

您对 another answer 的评论表明您正在尝试解决依赖问题。下面是使用 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)

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

然后我询问哪些包“依赖”于 composer/xdebug-handler 并发现 friendsofphp/php-cs-fixer 需要它(我知道那个包,它是根依赖的)。

然后我注意到 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

o
okey_on

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

示例:假设我想查看哪些包依赖于 doctrine/data-fixtures 包直到 _root_ 包的树结构。

composer depends --tree doctrine/data-fixtures

输出:

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)

R
Rolando Isidoro

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

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

作为别名,why 命令的行为与 depends 相同,并且上述两个选项仍然适用:

--recursive (-r):递归解析到根包;

--tree (-t):将结果打印为嵌套树,暗示 -r。


H
HappyDude

我不知道解决这个问题的好方法,但我遇到了同样的问题。我从未听说过的一个包裹被警告说它被放弃了。我的解决方案是在 composer.lock 文件中搜索废弃的包名称。它将出现在依赖它的包的 require 或 require-dev 中。

在我的情况下,它有几个级别,包 A 依赖于包 B,包 B 依赖于废弃的包 C。一旦我确定包 A 是什么,composer show --tree package/a 在树输出中显示废弃的包