如何从供应商目录的内容重新创建composer.json? [英] How can I recreate composer.json from the content of the vendor directory?
问题描述
我有一个项目正在使用 composer
。
I have a project where I am using composer
.
但是,我丢失了 composer.json
。
是否有一种方法可以从供应商<>的内容重新创建
composer.json
/ code>目录?
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
- 直接和
- 间接
依赖项。
直接依赖项是在
<$ c $中明确列出的依赖项c> require 和 require-dev
部分。
Direct dependencies are dependencies that are explicitly listed in the
require
and require-dev
sections.
间接依赖关系是您的依赖关系直接依赖项。
Indirect dependencies are dependencies of your direct dependencies.
也就是说,尽管您可以通过编程方式p屁股 installed.json
和
收集其中列出的依赖项,您需要自己为
决定是直接依赖项还是间接依赖项,还是其他
个字,无论您是否要明确地,都需要
composer.json
中的这些依赖项。
That is, while you could programmatically parse installed.json
and
collect the dependencies listed therein, you will need to decide for
yourself whether these are direct or indirect dependencies, or in other
words, whether you want to explicitly require these dependencies in
composer.json
.
installed.json
列出全部已安装依赖项,即取决于
是否运行
installed.json
lists all installed dependencies, that is, depending
on whether you ran
$ composer install
或
$composer install --no-dev
, installed.json
将包含
直接和间接依赖项,列在
before you lost your composer.json
, installed.json
will contain
direct and indirect dependencies listed in
- $中b $ b
-
require
和require-dev
或 -
require
require
andrequire-dev
orrequire
个部分。
也就是说,您需要自己确定这些是否是
依赖项,这些依赖项应在
That is, you will need to decide for yourself whether these are dependencies which should be listed in the
-
要求
或 -
require-dev
require
orrequire-dev
部分。
请参见
- https://getcomposer.org/doc/ 04-schema.md#require
- https://getcomposer.org/doc/04-schema.md#require-dev
- https://getcomposer.org/doc/03-cli.md#install
- 使用 require-dev在作曲家中安装软件包
- https://getcomposer.org/doc/04-schema.md#require
- https://getcomposer.org/doc/04-schema.md#require-dev
- https://getcomposer.org/doc/03-cli.md#install
- Using "require-dev" to install packages in composer
,以了解有关
部分的目的和区别的更多信息。
to find out more about the purpose and the differences between these sections.
installed.json
列表 all 安装了 exact
版本的依赖项。
installed.json
lists all installed dependencies with the exact
versions installed.
但是,您丢失的composer.json
并没有列出具有确切版本的
依赖项,而是使用了多种可能性
之一来指定版本约束。
However, the composer.json
you lost in all likelihood did not list
dependencies with exact versions, but using one of the many possibilities
for 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
-
〜
运算符 -
^
运营商 - 等。
- the
~
operator - the
^
operator - etc.
请参见
- https://getcomposer.org/doc/articles/versions.md#writing-version-constraints
了解有关版本的更多信息约束。
to find out more about version constraints.
这篇关于如何从供应商目录的内容重新创建composer.json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!