Skip to content

Instantly share code, notes, and snippets.

@evaleries
Last active August 24, 2020 00:10
Show Gist options
  • Save evaleries/29004fda5c254af1d05cc81802770621 to your computer and use it in GitHub Desktop.
Save evaleries/29004fda5c254af1d05cc81802770621 to your computer and use it in GitHub Desktop.
Recover composer.json

Recover Missing composer.json

If you ever missing composer.json but the packages are already installed, there are many ways to recover.

1. Parsing vendor/composer/installed.json

You can parse json from this file, then grab the package name or version.

2. Using composer show --installed then RegEx

Run the recover.py and customize as you like.

askvortsov/flarum-copy-links v0.1.1 Copy Discussion and Post links in Flarum
askvortsov/flarum-help-tags v0.1.4 Allow members to post in a tag, but only see discuss...
askvortsov/flarum-pwa v1.0.3 Turn your flarum site into a progressive web app!
axy/backtrace 1.0.7 Tracing in PHP
axy/codecs-base64vlq 1.0.1 Codec for VLQ (variable-length quantity) Base64 algo...
axy/errors 1.0.5 Exceptions in PHP
axy/sourcemap 0.1.5 Work with JavaScript/CSS Source Map
components/font-awesome 5.9.0 Font Awesome, the iconic SVG, font, and CSS framework.
dflydev/fig-cookies v1.0.2 Cookies for PSR-7 HTTP Message Interface.
doctrine/cache 1.10.2 PHP Doctrine Cache library is a popular cache implem...
import re
composer_string = open('list-installed-packages.txt', 'r')
for installed in composer_string:
package = re.search("^[a-z0-9]+(?:/[a-z0-9-.]+)", installed)
version = re.search("(\d+\.)(\d+\.)(\d+)", installed)
if package and version:
print(package.group(), end=" ")
# print(package.group(), version.group())
# print([package.group(), version.group()])
# print('"{}": "^{}"'.format(package.group(), version.group()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment