PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 20, 2022

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

 May 20, 2022     composer-php, php     No comments   

Issue

Some dependencies were mistakenly added to require instead of require-dev. I tried manually changing composer.json and running composer install, but composer.lock wasn't changed. So my guess is, that it ignored changes in composer.json, and just ensured that what's installed reflects what's in composer.lock file. Am I wrong here? If not wrong, how do I do that? I'd like to preserve versions of packages in composer.lock file as they are now as much as possible.


Solution

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.



Answered By - Ruslan Osmanov
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing