How to move some dependencies to require to require-dev using composer?

Some dependencies were mistakenly added to require instead of require-dev . I tried to manually modify composer.json and run composer install , but composer.lock not changed. Therefore, I assume that he ignored the changes in composer.json and simply ensured that what was installed reflected what was in the composer.lock file. Am I wrong here? If not, how should I do this? I would like to save the versions of packages in the composer.lock file, since they are now as large as possible.

+10
source share
3 answers

I reproduced your problem and found a simple solution: composer update .

Below are the steps that I followed.

Old composer.json

 { "require": { "meenie/javascript-packer": "1.1" } } $ composer install 

Saving a backup for composer.lock for further comparison:

 $ cp composer.lock composer.lock-prev 

New composer.json

 { "require-dev": { "meenie/javascript-packer": "1.1" } } $ composer install Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them. Nothing to install or update 

I updated Composer as the output suggested above:

 $ composer update Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Writing lock file Generating autoload files 

Then we examined the differences between old and new versions of composer.lock :

 $ diff -Nau composer.lock-prev composer.lock --- composer.lock-prev 2016-10-29 19:05:51.331588329 +0700 +++ composer.lock 2016-10-29 19:06:05.639809116 +0700 @@ -4,9 +4,10 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "f092e6d1418a7bb0db55b75f1099b4eb", - "content-hash": "774f074021977667a459f207616edfe2", - "packages": [ + "hash": "0c81c48f9845635d47821bc0e965e4fe", + "content-hash": "cb194309c2a3fda3b07a46ed7ef36bdd", + "packages": [], + "packages-dev": [ { "name": "meenie/javascript-packer", "version": "1.1", @@ -45,7 +46,6 @@ "time": "2013-03-25 21:54:33" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], 

We see that the changes really apply after running composer update .

+3
source

It seems that composer update --lock might solve your problem.

+2
source

I just need composer require --dev drupal/devel or for your example composer require --dev meenie/javascript-packer: 1.1 which forces the composer to do all the hard work.

0
source

Source: https://habr.com/ru/post/1011843/


All Articles