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
Composer: remove a package, clean up dependencies, don't update other packages
提问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.json
file looks like this:
自动生成的composer.json
文件如下所示:
{
"require": {
"squizlabs/php_codesniffer": "~2.0",
"phpmd/phpmd": "~2.1"
}
}
In the autogenerated composer.lock
file, 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_codesniffer
version 2.1.0
is released, but I don't want
to run update
yet. I want to stay on version 2.0.0
for now, and maybe I'll run update
in a few days.
几天后,squizlabs/php_codesniffer
版本2.1.0
发布,但我还不想运行update
。我现在想留在版本2.0.0
上,也许update
几天后我会运行。
The question
问题
I now want to remove phpmd/phpmd
from my project. I want to achieve the following points:
我现在想phpmd/phpmd
从我的项目中删除。我想达到以下几点:
- Delete
phpmd/phpmd
fromcomposer.json
- Delete
phpmd/phpmd
fromcomposer.lock
- Delete
phpmd/phpmd
from thevendor
folder - Delete all the dependencies of
phpmd/phpmd
fromcomposer.lock
- Delete all the dependencies of
phpmd/phpmd
from thevendor
folder - Do not update
squizlabs/php_codesniffer
to version2.1.0
- 删除
phpmd/phpmd
自composer.json
- 删除
phpmd/phpmd
自composer.lock
phpmd/phpmd
从vendor
文件夹中删除- 删除
phpmd/phpmd
from 的所有依赖composer.lock
phpmd/phpmd
从vendor
文件夹中删除所有依赖项- 不要更新
squizlabs/php_codesniffer
到版本2.1.0
Edit:I'd prefer a solution which doesn't require changing the
version constraint of squizlabs/php_codesniffer
in composer.json
编辑:我更喜欢不需要更改squizlabs/php_codesniffer
in的版本约束的解决方案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/phpmd
remain in composer.lock
and the vendor
folder.
phpmd/phpmd
保留在composer.lock
和vendor
文件夹中的依赖项。
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_codesniffer
gets updated to version 2.1.0
.
squizlabs/php_codesniffer
更新到 version 2.1.0
。
回答by kzap
Remove the entry from composer.json
then 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.lock
and /vendor
and 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,
我在这里找到了这个答案,
- Manually remove the package from composer.json.
- Manually delete vendor folder.
- Run
composer install
(from inside your project folder).
- 从 composer.json 手动删除包。
- 手动删除供应商文件夹。
- 运行
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