作曲家展示开发包和非开发包

时间:2019-03-28 20:54:58

标签: php composer-php

是否有办法知道在使用--no-dev标志时将会/不会自动加载哪些软件包?

我继承了一些使用composer的代码,我不确定生产版本中包含哪些软件包,而开发版本中仅包含哪些软件包。

由于composer dump-autoload --no-dev给我带来了有关缺少类的错误,我怀疑某些软件包在不应该包含的情况下被标记为仅供开发人员使用,因此我试图对其进行跟踪。

我没有在作曲家文档中找到任何可以帮助我做到这一点的东西。

3 个答案:

答案 0 :(得分:2)

检查哪些软件包是仅开发包的最简单方法是运行composer install(这将安装所有依赖关系,包括仅开发包),然后运行composer install --no-dev(这将删除仅开发包的依赖关系) 。最后一个命令将为您提供已删除的依赖项列表-这些是生产版本中不可用的软件包,您不应依赖它们(或将其移至require中的composer.json部分)。

示例:

$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 56 installs, 0 updates, 0 removals
  - Installing yiisoft/yii2-composer (2.0.7): Loading from cache
  - Installing bower-asset/jquery (3.3.1): Loading from cache
  - Installing bower-asset/bootstrap (v3.4.1): Loading from cache
  - Installing bower-asset/inputmask (3.3.11): Loading from cache
  - Installing bower-asset/punycode (v1.3.2): Loading from cache
  - Installing bower-asset/yii2-pjax (2.0.7.1): Loading from cache
  - Installing cebe/markdown (1.2.1): Loading from cache
  - Installing ezyang/htmlpurifier (v4.10.0): Loading from cache
  - Installing yiisoft/yii2 (2.0.17): Loading from cache
  - Installing swiftmailer/swiftmailer (v5.4.12): Loading from cache
  - Installing yiisoft/yii2-swiftmailer (2.0.7): Loading from cache
  - Installing symfony/polyfill-ctype (v1.11.0): Loading from cache
  - Installing symfony/yaml (v2.8.49): Loading from cache
  - Installing symfony/finder (v2.8.49): Loading from cache
  - Installing symfony/event-dispatcher (v2.8.49): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.11.0): Loading from cache
  - Installing symfony/dom-crawler (v2.8.49): Loading from cache
  - Installing symfony/css-selector (v2.8.49): Loading from cache
  - Installing psr/log (1.1.0): Loading from cache
  - Installing symfony/debug (v2.8.49): Loading from cache
  - Installing symfony/console (v2.8.49): Loading from cache
  - Installing symfony/browser-kit (v2.8.49): Loading from cache
  - Installing ralouphie/getallheaders (2.0.5): Loading from cache
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing guzzlehttp/psr7 (1.5.2): Loading from cache
  - Installing sebastian/recursion-context (1.0.5): Loading from cache
  - Installing sebastian/exporter (1.2.2): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Loading from cache
  - Installing doctrine/instantiator (1.0.5): Loading from cache
  - Installing phpunit/phpunit-mock-objects (2.3.8): Loading from cache
  - Installing codeception/stub (1.0.4): Loading from cache
  - Installing sebastian/diff (1.4.3): Loading from cache
  - Installing sebastian/comparator (1.2.4): Loading from cache
  - Installing sebastian/version (1.0.6): Loading from cache
  - Installing sebastian/global-state (1.1.1): Loading from cache
  - Installing sebastian/environment (1.3.8): Loading from cache
  - Installing phpunit/php-timer (1.0.9): Loading from cache
  - Installing phpunit/php-file-iterator (1.4.5): Loading from cache
  - Installing phpunit/php-token-stream (1.4.12): Loading from cache
  - Installing phpunit/php-code-coverage (2.2.4): Loading from cache
  - Installing phpdocumentor/reflection-docblock (2.0.5): Loading from cache
  - Installing phpspec/prophecy (1.8.0): Loading from cache
  - Installing phpunit/phpunit (4.8.36): Loading from cache
  - Installing codeception/phpunit-wrapper (6.0.10): Loading from cache
  - Installing behat/gherkin (v4.6.0): Loading from cache
  - Installing codeception/base (2.4.1): Loading from cache
  - Installing myclabs/deep-copy (1.6.1): Loading from cache
  - Installing codeception/specify (0.4.6): Loading from cache
  - Installing codeception/verify (0.3.3): Loading from cache
  - Installing yiisoft/yii2-bootstrap (2.0.9): Loading from cache
  - Installing yiisoft/yii2-debug (2.0.14): Loading from cache
  - Installing fzaninotto/faker (v1.8.0): Loading from cache
  - Installing yiisoft/yii2-faker (2.0.4): Loading from cache
  - Installing phpspec/php-diff (v1.1.0): Loading from cache
  - Installing bower-asset/typeahead.js (v0.11.1): Loading from cache
  - Installing yiisoft/yii2-gii (2.0.8): Loading from cache
Generating autoload files

然后列出仅开发人员依赖项:

$ composer install --no-dev
Loading composer repositories with package information
Installing dependencies from lock file
Package operations: 0 installs, 0 updates, 44 removals
  - Removing yiisoft/yii2-gii (2.0.8)
  - Removing yiisoft/yii2-faker (2.0.4)
  - Removing yiisoft/yii2-debug (2.0.14)
  - Removing symfony/yaml (v2.8.49)
  - Removing symfony/polyfill-mbstring (v1.11.0)
  - Removing symfony/polyfill-ctype (v1.11.0)
  - Removing symfony/finder (v2.8.49)
  - Removing symfony/event-dispatcher (v2.8.49)
  - Removing symfony/dom-crawler (v2.8.49)
  - Removing symfony/debug (v2.8.49)
  - Removing symfony/css-selector (v2.8.49)
  - Removing symfony/console (v2.8.49)
  - Removing symfony/browser-kit (v2.8.49)
  - Removing sebastian/version (1.0.6)
  - Removing sebastian/recursion-context (1.0.5)
  - Removing sebastian/global-state (1.1.1)
  - Removing sebastian/exporter (1.2.2)
  - Removing sebastian/environment (1.3.8)
  - Removing sebastian/diff (1.4.3)
  - Removing sebastian/comparator (1.2.4)
  - Removing ralouphie/getallheaders (2.0.5)
  - Removing psr/log (1.1.0)
  - Removing psr/http-message (1.0.1)
  - Removing phpunit/phpunit-mock-objects (2.3.8)
  - Removing phpunit/phpunit (4.8.36)
  - Removing phpunit/php-token-stream (1.4.12)
  - Removing phpunit/php-timer (1.0.9)
  - Removing phpunit/php-text-template (1.2.1)
  - Removing phpunit/php-file-iterator (1.4.5)
  - Removing phpunit/php-code-coverage (2.2.4)
  - Removing phpspec/prophecy (1.8.0)
  - Removing phpspec/php-diff (v1.1.0)
  - Removing phpdocumentor/reflection-docblock (2.0.5)
  - Removing myclabs/deep-copy (1.6.1)
  - Removing guzzlehttp/psr7 (1.5.2)
  - Removing fzaninotto/faker (v1.8.0)
  - Removing doctrine/instantiator (1.0.5)
  - Removing codeception/verify (0.3.3)
  - Removing codeception/stub (1.0.4)
  - Removing codeception/specify (0.4.6)
  - Removing codeception/phpunit-wrapper (6.0.10)
  - Removing codeception/base (2.4.1)
  - Removing bower-asset/typeahead.js (v0.11.1)
  - Removing behat/gherkin (v4.6.0)
Generating autoload files

还有一个maglnet/composer-require-checker,可能对于检测require部分未列出的库的使用很有用。

答案 1 :(得分:1)

基本上,当您使用require-dev时,composer.json文件的composer dump-autoload --no-dev部分中的任何软件包(及其依赖项)都不会自动加载。可悲的是,我认为没有命令将这些软件包及其依赖项显示为单个列表。

您可以做的是尝试将每个软件包从require-dev部分移至require,重新运行composer updatecomposer dump-autoload --no-dev,以查看错误何时消失。

答案 2 :(得分:0)

我刚刚发现您可以使用 composer show -s 显示所有根包:

name     : roots/bedrock
descrip. : WordPress boilerplate with modern development tools, easier configuration, and an improved folder structure
keywords : bedrock, roots, wordpress, stack, composer, vagrant, wp
versions : * dev-update-and-apply-aq-changes
type     : project
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://roots.io/bedrock/
source   : []  412b5d6779300e49762ed2402d0f87ca50475f2f
dist     : []  412b5d6779300e49762ed2402d0f87ca50475f2f
path     : 
names    : roots/bedrock

support
issues : https://github.com/roots/bedrock/issues
forum : https://discourse.roots.io/category/bedrock

requires
php >=7.0
composer/installers ^1.11
oscarotero/env ^1.2.0
roots/wordpress 5.7.2
roots/wp-password-bcrypt 1.0.0
roots/wp-config 1.0.0
advanced-custom-fields/advanced-custom-fields-pro *
wpackagist-plugin/wordpress-seo ^16.1

requires (dev)
squizlabs/php_codesniffer ^3.0.2
dealerdirect/phpcodesniffer-composer-installer *
wp-coding-standards/wpcs *
wpackagist-plugin/query-monitor ^3.7
roave/security-advisories dev-master

然后您可以使用 requires (dev)

剪掉 composer show -s | sed -n '/requires (dev)$/,/^$/p' 部分
requires (dev)
squizlabs/php_codesniffer ^3.0.2
dealerdirect/phpcodesniffer-composer-installer *
wp-coding-standards/wpcs *
wpackagist-plugin/query-monitor ^3.7
roave/security-advisories dev-master

然后你可以使用 composer show -s | sed -n '/requires (dev)$/,/^$/p' | grep -v 'requires (dev)'

去掉标题
squizlabs/php_codesniffer ^3.0.2
dealerdirect/phpcodesniffer-composer-installer *
wp-coding-standards/wpcs *
wpackagist-plugin/query-monitor ^3.7
roave/security-advisories dev-master

然后您可以使用 composer show -s | sed -n '/requires (dev)$/,/^$/p' | grep -v 'requires (dev)' | cut -d ' ' -f1

删除该版本
squizlabs/php_codesniffer
dealerdirect/phpcodesniffer-composer-installer
wp-coding-standards/wpcs
wpackagist-plugin/query-monitor
roave/security-advisories