问题描述
我有一个项目,我正在使用 composer
.
I have a project where I am using composer
.
但是,我丢失了我的 composer.json
.
However, I have lost my composer.json
.
有没有办法从vendor
目录的内容重新创建composer.json
?
Is there a way to recreate composer.json
from the content of the vendor
directory?
推荐答案
识别安装的依赖可以通过检查轻松实现
Identifying the installed dependencies can be easily achieved by inspecting
vendor
└── composer
└── installed.json
但是,您将面临以下问题:
However, you will be faced with the following problems:
installed.json
列出所有已安装的依赖,即两者都
installed.json
lists all installed dependencies, that is, both
- 直接和
- 间接
依赖关系.
直接依赖项是在require
和 require-dev
部分.
Direct dependencies are dependencies that are explicitly listed in therequire
and require-dev
sections.
间接依赖是你直接依赖的依赖.
Indirect dependencies are dependencies of your direct dependencies.
也就是说,虽然您可以以编程方式解析 installed.json
和收集其中列出的依赖项,您需要决定无论这些是直接或间接依赖,还是在其他换句话说,你是否想要明确需要这些依赖composer.json
.
That is, while you could programmatically parse installed.json
andcollect the dependencies listed therein, you will need to decide foryourself whether these are direct or indirect dependencies, or in otherwords, whether you want to explicitly require these dependencies incomposer.json
.
installed.json
列出所有 已安装的依赖项,即依赖关于你是否跑步
installed.json
lists all installed dependencies, that is, dependingon whether you ran
$ composer install
或
$composer install --no-dev
在您丢失 composer.json
之前,installed.json
将包含
before you lost your composer.json
, installed.json
will containdirect and indirect dependencies listed in
require
和require-dev
或要求
部分,分别.
也就是说,您需要自己决定这些是否应该在
That is, you will need to decide for yourself whether these aredependencies which should be listed in the
要求
或需要开发
部分.
见
- https://getcomposer.org/doc/04-schema.md#require
- https://getcomposer.org/doc/04-schema.md#需要开发
- https://getcomposer.org/doc/03-cli.md#install
- 使用require-dev"在 composer 中安装包
了解更多关于目的和它们之间的区别部分.
to find out more about the purpose and the differences between thesesections.
installed.json
列出 all 已安装的依赖项,exact安装的版本.
installed.json
lists all installed dependencies with the exactversions installed.
但是,您丢失的 composer.json
很可能没有列出具有确切版本的依赖项,但使用多种可能性之一用于指定版本约束.
However, the composer.json
you lost in all likelihood did not listdependencies with exact versions, but using one of the many possibilitiesfor specifying version constraints.
也就是说,您需要自己决定是要使用精确的版本,还是放宽约束,例如,使用
That is, you will need to decide for yourself whether you want to use exact versions, or relax the constraints, for example, by using
~
运算符^
运算符- 等等
见
了解有关版本限制的更多信息.
to find out more about version constraints.
这篇关于如何从供应商目录的内容中重新创建 composer.json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!