Композитор показывает пакеты dev и не пакеты dev

Есть ли способ узнать, какие пакеты будет/не будет будут автоматически загружены при использовании флага --no-dev?

Я унаследовал некоторый код, который использует композитор, и я не уверен, какие пакеты включены в производственную сборку, а какие включены только в сборку разработки.

Поскольку выполнение composer dump-autoload --no-dev дает мне ошибки в отношении отсутствующих классов, я подозреваю, что некоторые пакеты помечены как предназначенные только для разработчиков, когда они не должны этого делать, и я пытаюсь их отследить.

Я не нашел ничего в документах композитора, чтобы помочь мне сделать это.

Стоит ли изучать PHP в 2026-2027 годах?
Стоит ли изучать PHP в 2026-2027 годах?
Привет всем, сегодня я хочу высказать свои соображения по поводу вопроса, который я уже много раз получал в своем сообществе: "Стоит ли изучать PHP в...
Symfony Station Communiqué - 7 июля 2023 г
Symfony Station Communiqué - 7 июля 2023 г
Это коммюнике первоначально появилось на Symfony Station .
Оживление вашего приложения Laravel: Понимание режима обслуживания
Оживление вашего приложения Laravel: Понимание режима обслуживания
Здравствуйте, разработчики! В сегодняшней статье мы рассмотрим важный аспект управления приложениями, который часто упускается из виду в суете...
Установка и настройка Nginx и PHP на Ubuntu-сервере
Установка и настройка Nginx и PHP на Ubuntu-сервере
В этот раз я сделаю руководство по установке и настройке nginx и php на Ubuntu OS.
Коллекции в Laravel более простым способом
Коллекции в Laravel более простым способом
Привет, читатели, сегодня мы узнаем о коллекциях. В Laravel коллекции - это способ манипулировать массивами и играть с массивами данных. Благодаря...
Как установить PHP на Mac
Как установить PHP на Mac
PHP - это популярный язык программирования, который используется для разработки веб-приложений. Если вы используете Mac и хотите разрабатывать...
1
0
453
3
Перейти к ответу Данный вопрос помечен как решенный

Ответы 3

По сути, любой пакет (и его зависимости) в разделе require-dev вашего файла composer.json не будет автоматически загружаться при использовании composer dump-autoload --no-dev. К сожалению, я не думаю, что есть команда для отображения этих пакетов вместе с их зависимостями в виде единого списка.

Что вы можете сделать, так это попробовать переместить каждый из пакетов из раздела require-dev в require, повторно запустить composer update и composer dump-autoload --no-dev, чтобы увидеть, когда ваша ошибка исчезнет.

Ответ принят как подходящий

Самый простой способ проверить, какие пакеты предназначены только для разработчиков, — запустить 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.

Я только что обнаружил, что вы можете показать все корневые пакеты, используя 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

Другие вопросы по теме