8

I have to work on a project on symphony 2 without composer's config, but with folders vendor/* in the repository.

I want to re-install the composer and generate a configuration for an existing package. Is it possible?

Thanks!

matronator
  • 465
  • 6
  • 13
Dmitry
  • 551
  • 6
  • 19
  • Not sure if command for vendor -> composer.json exists. But you can list installed dependencies via `composer show --installed`. – Tomas Votruba Mar 02 '15 at 15:35
  • Does this answer your question? [How can I recreate composer.json from the content of the vendor directory?](https://stackoverflow.com/questions/45782095/how-can-i-recreate-composer-json-from-the-content-of-the-vendor-directory) – yivi Sep 23 '20 at 05:31

2 Answers2

14

You should create bare composer.json by hand or using command composer init.

And then you can list all the packages under the vendor folder by composer show --installed.

Then just generate require section for your composer.json with listed values. And you are done. You can use regular expressions to do it easier.

composer show --installed \
   | awk '{printf "\"%s\": \"^%s\",\n", $1, $2}' \
   | sed -r 's:\^v:^:g' \
   >> packages.list
Jacek Krysztofik
  • 1,266
  • 1
  • 13
  • 29
Michael Sivolobov
  • 12,388
  • 3
  • 43
  • 64
-1
 composer update
 Loading composer repositories with package information
 Updating dependencies (including require-dev)
 Package operations: 0 installs, 1 update, 8 removals       
   - Removing yiisoft/yii2-jui (2.0.7)
   - Removing bower-asset/jquery-ui (1.12.1)
   - Removing phpoffice/phpspreadsheet (1.0.0)
   - Removing psr/simple-cache (1.0.0)
   - Removing guzzlehttp/guzzle (5.0.0)
   - Removing guzzlehttp/ringphp (1.1.0)
   - Removing guzzlehttp/streams (3.0.0)
   - Removing react/promise (v2.5.1)
   - Updating swiftmailer/swiftmailer (v5.4.8 => v5.4.9): Downloading (100%)         
 Writing lock file
 Generating autoload files

I think you can execute composer update, it will show you all packages, and then composer install ... one by one

shengbin_xu
  • 128
  • 3
  • 14