且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从供应商目录的内容中重新创建 composer.json?

更新时间:2023-11-16 23:36:04

识别安装的依赖可以通过检查轻松实现

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

  • 直接
  • 间接

依赖关系.

直接依赖项是在requirerequire-dev 部分.

Direct dependencies are dependencies that are explicitly listed in the require 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 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

在您丢失 composer.json 之前,installed.json 将包含

before you lost your composer.json, installed.json will contain direct and indirect dependencies listed in

  • requirerequire-dev
  • 要求

部分,分别.

也就是说,您需要自己决定这些是否应该在

That is, you will need to decide for yourself whether these are dependencies which should be listed in the

  • 要求
  • 需要开发

部分.

了解更多关于目的和它们之间的区别部分.

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

  • ~ 运算符
  • ^ 运算符
  • 等等

了解有关版本限制的更多信息.

to find out more about version constraints.