How do I move some dependecies from require to require-dev with composer?

I would do:

composer require --dev drupal/devel

or for your example

composer require --dev meenie/javascript-packer: 1.1

which makes composer do all the heavy lifting and moves those dependencies into the require-dev section.


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


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

The following are the steps I have done.

Old composer.json

{
  "require": {
    "meenie/javascript-packer": "1.1"
  }
}

$ composer install

Saved 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 have updated Composer as the output above suggested:

$ 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 looked at the differences between the 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 can see that the changes are actually applied after running composer update.