composer / composer

Dependency Manager for PHP
https://getcomposer.org/
MIT License
28.52k stars 4.53k forks source link

How to exclude `require-dev` from `check-platform-reqs` command #7314

Closed eidng8 closed 6 years ago

eidng8 commented 6 years ago

My composer.json:

{
  "require": {
    "php": ">=7.1",
    "ext-apcu": "*",
    "ext-imap": "*",
    "ext-intl": "*",
    "ext-json": "*",
    "ext-mbstring": "*",
    "ext-openssl": "*",
    "ext-PDO": "*",
    "ext-zip": "*",
    "alcohol/iso4217": "^3.1",
    "guzzlehttp/guzzle": "^6.3",
    "laravel/framework": "5.6.*",
    "laravel/tinker": "~1.0",
    "league/iso3166": "^2.1",
    "spatie/laravel-permission": "^2.11",
    "aws/aws-sdk-php": "^3.43",
    "webklex/laravel-imap": "^1.0"
  },
  "require-dev": {
    "ext-xdebug": "*",
    "barryvdh/laravel-debugbar": "^3.1",
    "barryvdh/laravel-ide-helper": "^2.4",
    "doctrine/dbal": "^2.5",
    "fzaninotto/faker": "~1.7",
    "justinrainbow/json-schema": "^5.2",
    "laravel/dusk": "~3.0",
    "mockery/mockery": "^1.0",
    "phpunit/phpunit": "~7.0",
    "squizlabs/php_codesniffer": "^3.2"
  },
  "autoload": {
    "files": [
      "app/helpers.php"
    ],
    "classmap": [
      "database"
    ],
    "psr-4": {
      "SomeApp\\": "app/"
    },
    "exclude-from-classmap": [
      "/tests/"
    ]
  },
  "autoload-dev": {
    "psr-4": {
      "Tests\\": "tests/"
    }
  },
  "scripts": {
    "post-root-package-install": [
      "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
      "php artisan key:generate"
    ],
    "post-install-cmd": [
      "Illuminate\\Foundation\\ComposerScripts::postInstall"
    ],
    "post-update-cmd": [
      "Illuminate\\Foundation\\ComposerScripts::postUpdate",
      "php artisan ide-helper:generate",
      "php artisan ide-helper:meta"
    ]
  },
  "config": {
    "preferred-install": "dist",
    "sort-packages": true,
    "optimize-autoloader": true,
    "secure-http": false
  }
}

Output of composer diagnose:

Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.6.5
PHP version: 7.1.17
PHP binary path: /opt/remi/php71/root/usr/bin/php

When I run this command:

composer check-platform-reqs

I get the following output:

ext-apcu       5.1.11                                                             success
ext-intl       1.1.0                                                              success
ext-json       1.5.0                                                              success
ext-mbstring   7.1.17                                                             success
ext-openssl    7.1.17                                                             success
ext-PDO        7.1.17                                                             success
ext-tokenizer  7.1.17                                                             success
ext-xdebug     n/a     SomeApp requires (for development) ext-xdebug (*)  missing
ext-zip        1.15.2                                                             success
php            7.1.17                                                             success

And I expected ext-xdebug not to be checked, because it's on production environment. Then I've tried to execute:

composer check-platform-reqs --no-dev

but got this:


  [Symfony\Component\Console\Exception\RuntimeException]
  The "--no-dev" option does not exist.

check-platform-reqs

Is there a way to exclude require-dev from check-platform-reqs command?

alcohol commented 6 years ago

No, check-platform-reqs does not exclude require-dev because they are clearly part of your requirements.

Seems like a non-issue either way. You should not even run composer on your production environment.

tyranron commented 6 years ago

@alcohol no, that's not right in every case.

The basic example is testing production runtime Docker image:

  1. We build runtime Docker image with built project and --no-dev deps.
  2. We want to test that runtime Docker image has all required PHP extensions.
  3. We mount Composer bin and spec into container and run composer check-platform-reqs.

However, a this point check-platform-reqs requires from us PHP extensions of require-dev deps to be present inside image while we do not need them there at all. We only want to check platform requirements of require deps.

Currently we're using composer install --no-interaction --no-dev --dry-run workaround, but it plays quite bad when config.platform section is used in composer.json.

So, being able to run composer check-platform-reqs with --no-dev flag will be a desired and useful feature.

alcohol commented 6 years ago

I can see how it might be a desired feature. It is quite simple to implement, so PRs are welcome.

But I should caution that while this might make it possible to run check-platform-reqs without require-dev requirements, the dependency solving process will always take them into consideration. This could lead to somewhat confusing scenarios where a check-platform-reqs --no-dev could pass as being successful, while composer install --no-dev could fail on missing platform extensions (since it merely does not install dev requirements, but it still uses them during dependency solving).