I'm trying to use jq to edit a composer.json file between development and production.
I've got to the point where I can select the items that I want to remove, but I can't figure out how to turn that into a delete statement.
Also - the only way I could get the select working is to use to_entries, which then breaks the structure of the require selection.
Any help would be appreciated!
composer.json (trimmed for a shorter post):
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.0",
"kreait/laravel-firebase": "^4.1",
"laravel/cashier-paddle": "^1.5",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/socialite": "^5.5",
"laravel/tinker": "^2.5",
"livewire/livewire": "^2.5",
"lorisleiva/laravel-actions": "^2.4",
"owenvoke/blade-fontawesome": "*",
"protonemedia/laravel-verify-new-email": "^1.5",
"pusher/pusher-php-server": "^7.0",
"rapidstatic/rapidstatic": "dev-master",
"rapidstatic/scraper": "dev-master",
"razorui/blade-application-ui": "^0.3.0"
}
}
jq:
jq '.require | to_entries | map(select(.key | contains("rapidstatic")))' composer.json
output:
[
{
"key": "rapidstatic/rapidstatic",
"value": "dev-master"
},
{
"key": "rapidstatic/scraper",
"value": "dev-master"
}
]
You could use del and provide the key names as follows:
jq '.require |= del(.[keys[] | select(contains("rapidstatic"))])' composer.json
Demo
Or you could generate an array of path expressions and use delpaths on them:
jq '.require |= delpaths([keys[] | select(contains("rapidstatic")) | [.]])' composer.json
Demo
Output:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^8.0",
"kreait/laravel-firebase": "^4.1",
"laravel/cashier-paddle": "^1.5",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/socialite": "^5.5",
"laravel/tinker": "^2.5",
"livewire/livewire": "^2.5",
"lorisleiva/laravel-actions": "^2.4",
"owenvoke/blade-fontawesome": "*",
"protonemedia/laravel-verify-new-email": "^1.5",
"pusher/pusher-php-server": "^7.0",
"razorui/blade-application-ui": "^0.3.0"
}
}
Related
This has just randomly started happening and i've never seen this so i'm not sure how to fix it. I came to reinstall all the plugins for a bedrock install from wpackagist and instead of going into web/app/plugins they are all installing in the vendor folder. They weren't doing this last time i installed them, here is composer.json, nothing has changed so i don't know what is going on:
{
"name": "roots/bedrock",
"type": "project",
"license": "MIT",
"description": "WordPress boilerplate with modern development tools, easier configuration, and an improved folder structure",
"homepage": "https://roots.io/bedrock/",
"authors": [
{
"name": "Scott Walkinshaw",
"email": "scott.walkinshaw#gmail.com",
"homepage": "https://github.com/swalkinshaw"
},
{
"name": "Ben Word",
"email": "ben#benword.com",
"homepage": "https://github.com/retlehs"
}
],
"keywords": [
"bedrock", "composer", "roots", "wordpress", "wp", "wp-config"
],
"support": {
"issues": "https://github.com/roots/bedrock/issues",
"forum": "https://discourse.roots.io/category/bedrock"
},
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org",
"only": ["wpackagist-plugin/*", "wpackagist-theme/*"]
},
{
"type": "vcs",
"url": "git#github.com:clickds/save-share-cart.git"
},
{
"type": "vcs",
"url" : "git#github.com:clickds/woocommerce-additional-variation-images.git"
}
],
"require": {
"php": ">=7.1",
"composer/installers": "^1.11",
"vlucas/phpdotenv": "^5.3",
"oscarotero/env": "^2.1",
"roots/bedrock-autoloader": "^1.0",
"roots/bedrock-disallow-indexing": "^2.0",
"roots/wordpress": "5.8",
"roots/wp-config": "1.0.0",
"roots/wp-password-bcrypt": "1.0.0",
"wpackagist-plugin/woocommerce": "^5.7",
"wpackagist-plugin/disable-gutenberg": "^2.5",
"wpackagist-plugin/custom-field-builder": "^1.2",
"clickds/save-share-cart" : "^1.0.4",
"wpackagist-plugin/woocommerce-gateway-stripe": "^5.8",
"wpackagist-plugin/all-in-one-wp-security-and-firewall": "^4.4",
"wpackagist-plugin/w3-total-cache": "^2.1",
"wpackagist-plugin/woocommerce-gateway-paypal-express-checkout": "^2.1",
"wpackagist-plugin/simple-taxonomy-ordering": "^2.3",
"wpackagist-plugin/wp-mail-smtp": "^3.2",
"glenelkins84/woocommerce-additional-variation-images" : "^1.9.2",
"wpackagist-plugin/import-xml-feed": "^2.1",
"wpackagist-plugin/woo-variation-swatches": "^1.1",
"wpackagist-plugin/woo-custom-related-products": "^1.3",
"wpackagist-plugin/purchase-orders-for-woocommerce": "^1.8"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.6.0",
"roave/security-advisories": "dev-master"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"allow-plugins": {
"composer/installers": false,
"roots/wordpress-core-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"installer-paths": {
"web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
"web/app/plugins/{$name}/": ["type:wordpress-plugin"],
"web/app/themes/{$name}/": ["type:wordpress-theme"]
},
"wordpress-install-dir": "web/wp"
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"test": [
"phpcs"
]
}
}
It seems "WordPress boilerplate" works separately from WordPress core.
Generally, using composer, the installed packages are stored in the vendor folder and can be called by requiring autoload.php file in your project.
I have downgraded a Symfony 5.2 app template to use Symfony 4.4 in order to allow the use of some libraries that require an older version of Symfony. The problem is that when I do composer install, I get this error near the end of the installation:
sh: symfony-cmd: command not found
It seems that the installations are mostly successful, as my vendor folder is created and populated. But I'm worried about the error.
What does this error mean? How do I fix it?
====
Edit: Here's my composer.json file:
{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.4.0",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"composer/package-versions-deprecated": "1.11.99.1",
"cweagans/composer-patches": "^1.7",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^2.9",
"phpdocumentor/reflection-docblock": "*",
"sensio/framework-extra-bundle": "*",
"symfony/framework-bundle": "4.4.*",
"symfony/http-client": "*",
"symfony/intl": "*",
"symfony/mailer": "*",
"symfony/mime": "*",
"symfony/monolog-bundle": "^3.1",
"symfony/notifier": "*",
"symfony/process": "*",
"symfony/property-access": "*",
"symfony/property-info": "*",
"symfony/proxy-manager-bridge": "*",
"symfony/security-bundle": "*",
"symfony/serializer": "*",
"symfony/string": "*",
"symfony/translation": "*",
"symfony/twig-bundle": "*",
"symfony/validator": "*",
"symfony/web-link": "*",
"symfony/yaml": "*",
"twig/extra-bundle": "*",
"twig/twig": "*"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4",
"roave/security-advisories": "dev-master",
"symfony/browser-kit": "*",
"symfony/css-selector": "*",
"symfony/debug-bundle": "*",
"symfony/maker-bundle": "*",
"symfony/phpunit-bridge": "*",
"symfony/stopwatch": "*",
"symfony/var-dumper": "*",
"symfony/web-profiler-bundle": "*",
"vimeo/psalm": "^4.9"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.2.*"
},
"patches": {
"symfony/maker-bundle": {
"Provide flag to force annotation in make entity command": "https://raw.githubusercontent.com/vklux/maker-bundle-force-annotation/master/maker-force-annotation-flag.patch"
}
}
}
}
For those who have the symfony/flex package installed and are still getting the error, make sure the symfony/flex package is allowed to execute code when running composer.
This is because since Composer 2.2.0 the allow-plugins option adds a layer of security that allows you to restrict which Composer plugins can execute code at startup time.
So make sure you have the appropriate line in the allow-plugins config in your composer.json file
"config": {
// other config...
"allow-plugins": {
"symfony/flex": true
}
},
symfony-cmd is a part of Symfony Flex. Your composer.json does not contain any requirement for Flex, so running composer require symfony/flex might resolve that problem.
While adding symfony/flex to the project is one solution, keep in mind that Flex is optional. If you want to get rid of the error without installing Flex, simply remove the symfony-cmd command references from your composer.json.
Before:
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
After:
"scripts": {
"auto-scripts": {},
"post-install-cmd": [],
"post-update-cmd": []
},
I ran into a special case were an old deploy script added --no-plugins to my composer command. Removing that solved my issue with using deployer v6.
set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');
Apparently you need plugins for flex to work, and I'm assuming since the scripts block has some commands you need that too. So having no script/plugins will break your installation.
I have a package in a private github repository.
When I run composer require my_vendor/my_package the package gets added to composer.json and shows up in the vendor directory.
When I run composer remove my_vendor/my_package it gives me a warning:
Package "my_vendor/my_package" listed for update is not installed.
Ignoring.
So when I run composer prohibits my_vendor/my_package it says
Could not find package "my_vendor/my_package" in your project
If I run composer show (after requiring the package) it is not displayed in the list.
This package has a dependency (lexik/authenticationbundle) which is correctly installed, removed and show in list of installed packages (but not listed in the tree view since it is a dependency of a non existent package)...
I have no clue on what could explain this behavior.
Any suggestion?
edit (adding composer.json content)
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/api-pack": "^1.1",
"composer/composer": "^1.6",
"symfony/console": "^4.1",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.1",
"symfony/lts": "^4#dev",
"symfony/orm-pack": "^1.0",
"symfony/web-server-bundle": "^4.1",
"symfony/yaml": "^4.1"
},
"require-dev": {
"symfony/dotenv": "^4.1"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/my_repo/my_package.git"
}
],
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"assets:install %PUBLIC_DIR%": "symfony-cmd",
"cache:clear": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-package-install": [
"App\\Utility\\Bootstrap\\Setup::execute",
"#auto-scripts"
],
"pre-package-uninstall": [
"App\\Utility\\Bootstrap\\Demolish::execute",
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"id": "01C1K60FQVPP7FCAC3YB6639RZ",
"allow-contrib": true
}
}
}
Furthermore, creating a new project and requiring the package correctly adds it to the list of installed packages, thus removing it works fine. Then I tried to delete lock file and running a composer update and eventually I tried to require/remove it but with no luck.
It appears that what was preventing composer to correctly configure required package was a die() in the post-package-install script.
Removing the statement solved the issue.
I'm working on a Symfony 4 project with PhpStorm 2018.1
It has become common for me to see the use declarations highlighted as if they haven't been installed with composer.
The class belongs to a package which is not directly required in your
composer.json. Please add the package into your composer.json.
The following are installed and show in my composer.json file:
stof/doctrine-extensions-bundle
symfony/orm-pack
Am I missing something here or is this a PhpStorm issue?
composer.json
{
"type": "project",
"license": "proprietary",
"platform": {
"php": "7.1"
},
"require": {
"php": "^7.1",
"ext-iconv": "*",
"sensio/framework-extra-bundle": "^5.1",
"stof/doctrine-extensions-bundle": "^1.3",
"symfony/asset": "^4.1",
"symfony/console": "^4.1",
"symfony/expression-language": "^4.1",
"symfony/flex": "^1.0",
"symfony/form": "^4.1",
"symfony/framework-bundle": "^4.1",
"symfony/lts": "^4#dev",
"symfony/maker-bundle": "^1.5",
"symfony/monolog-bundle": "^3.3",
"symfony/orm-pack": "^1.0",
"symfony/process": "^4.1",
"symfony/profiler-pack": "^1.0",
"symfony/security-bundle": "^4.1",
"symfony/security-guard": "^4.1",
"symfony/serializer-pack": "*",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/twig-bundle": "^4.1",
"symfony/validator": "^4.1",
"symfony/var-dumper": "^4.1",
"symfony/web-link": "^4.1",
"symfony/webpack-encore-pack": "^1.0",
"symfony/yaml": "^4.1"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0",
"symfony/debug-pack": "*",
"symfony/dotenv": "^4.1",
"symfony/test-pack": "^1.0",
"symfony/web-server-bundle": "^4.1"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": true
}
}
}
What this message is telling you is that the highlighted classes are only available because the packages containing them have been installed as dependencies of some other packages you require (in this case it's probably because of the symfony/orm-pack package). Generally, relying on such transitive dependencies is not something I would do. Though for the Symfony pack that's something acceptable IMO.
If you are still concerned about this message, you can get rid of it by unpacking symfony/orm-pack (see also http://fabien.potencier.org/symfony4-unpack-the-packs.html):
$ composer unpack symfony/orm-pack
Your import path is correct, your composer.json looks good also.
Try to delete the vendor directory then try to launch composer install.
Try to install Symfony Plugin in your PHPStorm.
EDIT
Do you have the line below in your config/bundles.php ?
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
I made a tiny bundle that saves a lot of time when you want to create a restfull api on symfony2 using FosRestBundle and jmsSerializer.
I would like to share this bundle in my projects, but when i add it to its destination, composers returns "Your requirements could not be resolved to an installable set of packages."
I guess i made something wrong but can not find out what
I created a repo on git ( https://github.com/LeniM/apiGenericBundle )
Added the composer.json :
{
"name": "lenim/api-generic-bundle",
"type": "symfony-bundle",
"description": "Rest Api creation helper",
"keywords": ["Api", "RestApi"],
"homepage": "http://friendsofsymfony.github.com",
"license": "MIT",
"minimum-stability" : "dev",
"target-dir": "LeniM/ApiGenericBundle",
"authors": [
{
"name": "Martin Leni",
"role" : "Developer"
}
],
"require": {
"php": ">=5.3.3",
"symfony/framework-bundle": "~2.3|~3.0",
"doctrine/orm": "^2.5",
"friendsofsymfony/rest-bundle": "^1.7",
"jms/serializer-bundle": "^1.1"
},
"require-dev": {
"symfony/console": "~2.3|~3.0",
"symfony/phpunit-bridge": "~2.7|~3.0",
"symfony/validator": "~2.3|~3.0",
"symfony/yaml": "~2.3|~3.0",
"willdurand/propel-typehintable-behavior": "~1.0"
},
"suggest": {
"nelmio/NelmioApiDocBundle": "More than recommanded to keep your api well documentated"
},
"autoload": {
"psr-4": { "LeniM\\ApiGenericBundle\\": "" }
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"support": {
"docs": "https://github.com/LeniM/apiGenericBundle/readme.md"
}
}
required it with its name : lenim/api-generic-bundle
Is there something else to do to register your thrid part bundle to composer ?
Thanks :)
You have to either publish this package on packagist.org or specify target repository path in particular project's composer.json file: https://getcomposer.org/doc/05-repositories.md#vcs