php Composer:删除一个包,清理依赖,不更新其他包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27944795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:37:56  来源:igfitidea点击:

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

phpcomposer-php

提问by TachyonVortex

The situation

情况

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

假设我有一个项目,其中包含 Composer 安装的两个包:

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

The autogenerated composer.jsonfile looks like this:

自动生成的composer.json文件如下所示:

{
    "require": {
        "squizlabs/php_codesniffer": "~2.0",
        "phpmd/phpmd": "~2.1"
    }
}

In the autogenerated composer.lockfile, there are the two requested packages:

在自动生成的composer.lock文件中,有两个请求的包:

  • 2.0.0 squizlabs/php_codesniffer
  • 2.1.3 phpmd/phpmd
  • 2.0.0 squizlabs/php_codesniffer
  • 2.1.3 phpmd/phpmd

and also four dependencies of phpmd/phpmd:

以及以下四个依赖项phpmd/phpmd

  • 2.0.4 pdepend/pdepend
  • 2.5.9 symfony/config
  • 2.5.9 symfony/dependency-injection
  • 2.5.9 symfony/filesystem
  • 2.0.4 pdepend/pdepend
  • 2.5.9 symfony/config
  • 2.5.9 symfony/dependency-injection
  • 2.5.9 symfony/filesystem

A few days later, squizlabs/php_codesnifferversion 2.1.0is released, but I don't want to run updateyet. I want to stay on version 2.0.0for now, and maybe I'll run updatein a few days.

几天后,squizlabs/php_codesniffer版本2.1.0发布,但我还不想运行update。我现在想留在版本2.0.0上,也许update几天后我会运行。



The question

问题

I now want to remove phpmd/phpmdfrom my project. I want to achieve the following points:

我现在想phpmd/phpmd从我的项目中删除。我想达到以下几点:

  1. Delete phpmd/phpmdfrom composer.json
  2. Delete phpmd/phpmdfrom composer.lock
  3. Delete phpmd/phpmdfrom the vendorfolder
  4. Delete all the dependencies of phpmd/phpmdfrom composer.lock
  5. Delete all the dependencies of phpmd/phpmdfrom the vendorfolder
  6. Do not update squizlabs/php_codesnifferto version 2.1.0
  1. 删除phpmd/phpmdcomposer.json
  2. 删除phpmd/phpmdcomposer.lock
  3. phpmd/phpmdvendor文件夹中删除
  4. 删除phpmd/phpmdfrom 的所有依赖composer.lock
  5. phpmd/phpmdvendor文件夹中删除所有依赖项
  6. 不要更新squizlabs/php_codesniffer到版本2.1.0

Edit:I'd prefer a solution which doesn't require changing the version constraint of squizlabs/php_codesnifferin composer.json

编辑:我更喜欢不需要更改squizlabs/php_codesnifferin的版本约束的解决方案composer.json



What I've tried

我试过的

If I run:

如果我运行:

php composer.phar remove phpmd/phpmd

this achieves points 1, 2, 3, 6, but does not achieve points 4, 5.

这实现点1,2,3,6,但不达到点4,5

The dependencies of phpmd/phpmdremain in composer.lockand the vendorfolder.

phpmd/phpmd保留在composer.lockvendor文件夹中的依赖项。

If I run:

如果我运行:

php composer.phar remove phpmd/phpmd
php composer.phar update

this achieves points 1, 2, 3, 4, 5, but does not achieve point 6.

这达到了第1、2、3、4、5点,但没有达到第6点。

squizlabs/php_codesniffergets updated to version 2.1.0.

squizlabs/php_codesniffer更新到 version 2.1.0

回答by kzap

Remove the entry from composer.jsonthen run composer update phpmd/phpmd.

删除条目composer.json然后运行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.lockand /vendorand allow you to install a new/replacement/conflicting package.

至于为什么这是有效的解决方案。我不知道,但是这就是需要从完全删除软件包composer.lock/vendor,并允许你安装一个新的/更换/冲突的包。

回答by Kevin G.

Do this:

做这个:

php composer.phar remove phpmd/phpmd

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

修改 composer.json 文件,使其包含以下 require 部分。

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

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

现在运行composer.phar update。这应该可以让你到达你想去的地方。

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.

注意:您还可以将 php_codesniffer 包固定到特定版本,例如2.0.0. 可以在此处找到有关 composer 如何进行版本控制的更多信息。

回答by JimB814

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).
  1. 从 composer.json 手动删除包。
  2. 手动删除供应商文件夹。
  3. 运行composer install(从您的项目文件夹中)。

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

Composer 重新安装在 composer.json 中列出的包。

回答by Michael Cordingley

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

我不相信这目前是可能的。您可能希望将这种内容作为功能请求提交给 Composer。

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

同时,我认为你最好的选择是选择 #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.

它将从您的显式依赖项中删除包,而不会强迫您更新任何内容。已删除库中过时的依赖项将一直保留到您下次运行composer update,无论如何您都应该定期执行此操作。旧依赖项中的大多数文件应该设置为以一种或另一种方式自动加载,因此除了它们在磁盘上使用的空间之外,保留这些文件不应该有任何真正的惩罚。

回答by Lauris Kuznecovs

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

要从 .json 和 .lock 文件中删除包,您必须按如下方式删除包:

composer remove package-name