作曲家删除(卸载)所有已安装的软件包(作曲家安装回滚)

发布于 2025-01-14 11:04:05 字数 1438 浏览 4 评论 0原文

我有一个带有 composer.lock 文件的项目。 我使用以下命令安装了软件包:

composer install

现在我想将 composer install 命令回滚到运行之前的状态。

如何删除所有包而不影响 composer.lock 文件? 是否有任何单个 composer 命令可以做到这一点?

我尝试过:

composer remove *

但我得到了:

[意外值异常]
“LICENSE”不是有效的别名。

我尝试过:

composer remove */*

但后来我得到了一堆打印信息,例如:

您的composer.json中不需要bin/console,并且尚未删除
列出的更新包“bin/console”未锁定。

为什么 composer remove * 根本不起作用? AFAIK 包名称为 VendorName/PackageName 是 Packagist 的常见约定,但不是必须的(如果您使用私有存储库),那么如何删除所有名为 IdontHaveAnySlash 立即等等?

我可能会使用类似于以下内容的命令:

for package in $(composer show | awk '{print $1}'); do composer remove --no-interaction --dev --no-install "$package"; done

但这不是一个简单且单一的composer命令。 此外,composer 经常抱怨一个包是另一个包的一部分(依赖项),因此 Composer 不会卸载它。

删除失败,学说/注释仍然存在,另一个包可能需要它。请参阅composer 为什么采用学说/注释

因为我的目的是回滚到未安装任何软件包而仅安装文件的状态: composer.lock 和可能的 composer.json 我真的不关心任何依赖项、包版本、下载存储库的 URL 等。

我只想拥有一个没有像以前那样安装任何依赖项的项目。

是否有任何单个 composer 命令可以做到这一点?

我的:

composer --version

是:

版本2.2.7 2022-02-25 11:12:27

I have a project with the composer.lock file.
I installed packages with the command:

composer install

Now I would like to roll back that composer install command to the state as it was before running it.

How to remove all packages without affecting composer.lock file?
Is there any single composer command to do that?

I tried:

composer remove *

but I got:

[UnexpectedValueException]
"LICENSE" is not a valid alias.

I tried:

composer remove */*

But then I get bunch of print like:

bin/console is not required in your composer.json and has not been removed
Package "bin/console" listed for update is not locked.

Why composer remove * did not work at all? AFAIK the package name as VendorName/PackageName is a common convention for Packagist but not a must (if you use private repos) so how one would be able to remove all packages named IdontHaveAnySlash etc. at once?

I may use someting similar to:

for package in $(composer show | awk '{print $1}'); do composer remove --no-interaction --dev --no-install "$package"; done

But that is not a simple and single composer command.
Also composer often complains about a package being a part (dependency) of another one so composer does not uninstall it.

Removal failed, doctrine/annotations is still present, it may be required by another package. See composer why doctrine/annotations.

As my intention is to rollback to the state that did not have any package installed but only files: composer.lock and potentially composer.json I really don't care about any dependencies, packages versions, downloading repositories' urls etc.

I just want to have a project without any installed dependencies as it was before.

Is there any single composer command to do that?

My:

composer --version

is:

version 2.2.7 2022-02-25 11:12:27

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2025-01-21 11:04:05
rm -rf vendor

在任何情况下,install 都不应该对锁定文件进行任何更改,因此不应该从 install 中“恢复”任何内容,但是删除已安装的文件。

如果锁文件最初不存在,则会创建它。

如果其他一些插件(例如 Symfony Flex)在此过程中对您现有的文件进行了更改,您最好将项目置于版本控制系统之上,在这种情况下,恢复由 VCS 管理,而不是由 Composer 管理。

因为我的目的是回滚到未安装任何软件包而仅安装文件的状态:composer.lock 和可能的composer.json

为了能够运行 composer install ,您需要至少存在 composer.jsoninstall 从锁文件 (composer.lock) 中读取,但要求 JSON 配置文件也存在。如果锁文件不存在,则将运行 update 并创建锁文件。

我尝试了composer删除

removerequire 相反。它从 composer.json 中删除包,因为 require 添加它们。与安装相反。没有安装的反义词,因为它没有太多概念意义。如果需要删除已安装的项目...总是可以这样做。

rm -rf vendor

In any case, install should not make any changes to a lockfile, so there shouldn't be anything to "revert" from an install but deleting the installed files.

If the lockfile does not originally exist, then it will be created.

If some other plugin (e.g Symfony Flex) makes changes to your existing files during the process, you'd better have the project on top of a version control system, in which case reverting is managed by VCS, not of composer.

As my intention is to rollback to the state that did not have any package installed but only files: composer.lock and potentially composer.json

For you to be able to run composer install at all, you need at the very least composer.json to exist. install reads from the lockfile (composer.lock), but requires the JSON configuration file to exist as well. If the lockfile does not exist, update will be run instead and the lockfile will be created.

I tried composer remove

remove is the opposite from require. It removes packages from composer.json, as require adds them. Not the opposite of install. There is no opposite of install, as it does not make much conceptual sense. If one needs to delete the installed project... one can always do so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文