Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Composer: No Dev Mode that Sticks

When you install or update a project with composer, you can tell it to skip the development related dependencies (tests, build tools, etc.) with the --no-dev flag

composer.phar update --no-dev

Without this flag, composer will always download the extra dependencies.

Is there any way (programmatically or otherwise) to tell composer to always skip the development dependencies? That is, is there anything real code that matches the pseudo code

//File: composer.json
//...
"no-dev":"true"
//...
like image 397
Alan Storm Avatar asked May 25 '14 01:05

Alan Storm


People also ask

What is -- no dev in composer?

Both install or update support the --no-dev option that prevents dev dependencies from being installed. So running composer install will also download the development dependencies. The reason is actually quite simple.

Why is composer not installing?

Make sure you have no problems with your setup by running the installer's checks via curl -sS https://getcomposer.org/installer | php -- --check . Try clearing Composer's cache by running composer clear-cache . Ensure you're installing vendors straight from your composer.

How do I increase composer memory limit?

Use the format “128M” for megabyte or “2G” for gigabyte. You can use the value “-1” to ignore the memory limit completely. Another way would be to increase the PHP memory limit: php -d memory_limit=512M composer.


2 Answers

In short: no - not, yet.

Composer's default installation mode is to install development dependencies.

As far as i know, there is only the CLI option --no-dev and no config option.

It's possible to define a config section in the composer.json of a project, see https://getcomposer.org/doc/04-schema.md#config

But a quick glance at the source code revealed, that there is no configuration directive for this. https://github.com/composer/composer/blob/master/src/Composer/Config.php#L22

{
    "config": {
        "no-dev": "true"
    }
}

+1 for this idea. It could be a useful addition to the Config class.

like image 108
Jens A. Koch Avatar answered Oct 22 '22 02:10

Jens A. Koch


This was really annoying, so I finally wrote a simple bash script which asks about environment and run correct command:

#! /bin/bash

read -p "Which environment use to deploy: (P)roduction (T)est (D)ev? (p/t/d): " -n 1 -r
echo

if [[ $REPLY =~ ^[^PpTtDd]$ ]]; then
    echo "Incorrect environment";
    exit 1;
fi

# tasks to run before composer install (svn up/git pull)

if [[ $REPLY =~ ^[Pp]$ ]]; then
    composer install --prefer-dist --no-dev --classmap-authoritative
elif [[ $REPLY =~ ^[Tt]$ ]]; then
    composer install --prefer-dist --classmap-authoritative
elif [[ $REPLY =~ ^[Dd]$ ]]; then
    composer install
fi

# additional tasks after composer install (clear cache, migrations, etc.)

Saved it in bin/deploy in project and added execute permissions. So now I'm using bin/deploy instead of composer install:

console

I also put other common tasks there (pull changes from VCS, clear cache, run migrations, etc.), so I have even less things to do and remember during deployment :).

like image 39
rob006 Avatar answered Oct 22 '22 01:10

rob006