I have a project where I am using composer
.
However, I have lost my composer.json
.
Is there a way to recreate composer.json
from the content of the vendor
directory?
I have a project where I am using composer
.
However, I have lost my 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
lists all installed dependencies, that is, both
dependencies.
Direct dependencies are dependencies that are explicitly listed in the
require
and require-dev
sections.
Indirect dependencies are dependencies of your direct dependencies.
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
lists all installed dependencies, that is, depending
on whether you ran
$ composer install
or
$composer install --no-dev
before you lost your composer.json
, installed.json
will contain
direct and indirect dependencies listed in
require
and require-dev
orrequire
sections, respectively.
That is, you will need to decide for yourself whether these are dependencies which should be listed in the
require
orrequire-dev
sections.
See
to find out more about the purpose and the differences between these sections.
installed.json
lists all installed dependencies with the exact
versions installed.
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
~
operator^
operatorSee
to find out more about version constraints.
Hoppe!!
I had a similar problem with a Laravel project
In order to solve it:
installed.json
path, this will return the require
and require-dev
of the project composer.json
. In case of working with Laravel, be careful not to affect the require brought from the base app.