Composer: remove a package, clean up dependencies, don't update other packages

后端 未结 5 943
礼貌的吻别
礼貌的吻别 2021-01-30 19:46

The situation

Let\'s say I have a project with two packages installed by Composer:

php composer.phar require \'squizlabs/php_codesniffer:~2.0\' \'phpmd         


        
相关标签:
5条回答
  • 2021-01-30 20:35

    I found this answer here,

    1. Manually remove the package from composer.json.
    2. Manually delete vendor folder.
    3. Run composer install (from inside your project folder).

    Composer re-installs the packages listed in composer.json.

    0 讨论(0)
  • 2021-01-30 20:38

    I do not believe this to currently be possible. This is the sort of thing that you may wish to submit as a feature request to Composer.

    Meanwhile, I think your best bet is to go with option #1: php composer.phar remove phpmd/phpmd

    It will remove the package from your explicit dependencies without forcing you to update anything. The obsolete dependencies from your removed library will remain until you next run composer update, which is something you should be doing periodically anyway. Most of the files from the old dependencies should be set to autoload one way or another, so you shouldn't have any real penalties for keeping those files around other than the space they use on disk.

    0 讨论(0)
  • 2021-01-30 20:39

    Remove the entry from composer.json then run composer update phpmd/phpmd.

    As to why that is the solution that works. I have no idea but that is what is required to remove a package totally from composer.lock and /vendor and allow you to install a new/replacement/conflicting package.

    0 讨论(0)
  • 2021-01-30 20:42

    Do this:

    php composer.phar remove phpmd/phpmd
    

    Modify the composer.json file so it contains the following require section.

    {
        "require": {
            "squizlabs/php_codesniffer": "2.0.*",
        }
    }
    

    Now run composer.phar update. That should get you where you want to be.

    Note: You could also pin the php_codesniffer package to a specific version e.g. 2.0.0. More information about how composer does versioning can be found on here.

    0 讨论(0)
  • 2021-01-30 20:44

    To remove package from .json and .lock files you have to remove package as follows:

    composer remove package-name
    
    0 讨论(0)
提交回复
热议问题