Don't work require in Copmposer - composer-php

I have composer.json on project:
{
"repositories": [
{
"type": "vcs",
"url": "git#git.test.ua:bmp/composer.git"
}
],
"require": {
"pack/composer": "dev-master"
},
"minimum-stability": "dev"
}
git#git.test.ua:bmp/composer.git - it's my repo, that containe next composer.json file:
{
"name": "pack/composer",
"repositories": [
{
"type": "vcs",
"url": "git#git.test.ua:components/curl.git"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0",
"pack/curl": "dev-master"
},
"autoload": {
"psr-4": {
"pack\\composer\\": ""
}
}
}
git#git.test.ua:components/curl.git - also my repo, that containe next composer.json file:
{
"name": "pack/curl",
"autoload": {
"psr-4": {
"pack\\curl\\": ""
}
},
"minimum-stability": "dev"
}
When I try to do composer install on my project, I receive next error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for pack/composer dev-master -> satisfiable by pack/composer[dev-master].
- pack/composer dev-master requires pack/curl dev-master -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
I already add param:
"minimum-stability": "dev"
If I remove require section from the seckond composer.json file the no error any more.
"pack/curl": "dev-master"
How fix it, I need this require?
Update:
{
"repositories": [
{"type": "vcs", "url": "https://git.test.ua/components/composer.git"},
{"type": "vcs", "url": "https://git.test.ua/components/curl.git"}
],
"require-dev": {
"pack/composer": "dev-master"
},
"minimum-stability": "dev"
}
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing pack/composer (dev-master 886d220)
Cloning 886d22082d4aa341731ebd87f280ee0f5a05fe37
Writing lock file
Generating autoload files
Update2 composer.lock file
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is #generated automatically"
],
"hash": "cc5c1fc7000544f6cfd9ba03a3ee4567",
"packages": [],
"packages-dev": [
{
"name": "pack/composer",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://git.test.ua/components/composer.git",
"reference": "886d22082d4aa341731ebd87f280ee0f5a05fe37"
},
"require-dev": {
"pack/curl": "dev-master"
},
"type": "library",
"autoload": {
"psr-4": {
"pack\\composer\\": ""
}
},
"time": "2015-04-24 07:13:31"
}
],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"pack/composer": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}

Composer does not browse repositories recursively, i.e. ALL repositories that may contain software have to be mentioned in the root composer.json file.
You don't mention the repository of the pack/curl package there, so Composer cannot find this package.
I assume that "pack" is the vendor name you added partially in your question, because the error message still mentions "shkarbatov" as the vendor name.
Best way to avoid having to add hundreds of personal repositories everywhere is to have a packagist-like Composer repo that is mentioned everywhere and contains the metadata of all code repositories. Have a look at Satis.
Update:
Now after seeing your composer.lock file, the situation is clear: You are NOT using require to add your packages, but require-dev. This is for development dependencies (like adding PHPUnit or stuff needed to develop the package) of the root package only - any dev dependencies of packages added to the root package are NOT installed.
Change the dependencies of packages you need for production use to require all levels!

Related

How to get composer local package dependencies to install?

I have a global composer file for my user which contains references to local packages like:
{
"repositories": [
{
"type": "path",
"url": "/vendorA/projectA",
"options": {
"symlink": true
}
},
{
"type": "path",
"url": "/vendorA/projectB",
"options": {
"symlink": true
}
},
{
"type": "path",
"url": "/vendorA/projectC",
"options": {
"symlink": true
}
}
]
}
In project C, I have a composer.json file similar to:
{
"name": "Project C"
"require": {},
"require-dev": {
"vendorA/projectA": "#dev",
"vendorA/projectB": "#dev"
},
"prefer-stable": true
}
When I composer require --dev vendorA/projectC, it symlinks Project C's folder under the vendor folder but not the requirements defined in Project C's composer.json file. I tested installing Project A and B and they work fine so it is not a situation where composer is not able to find the packages, but Projects A and B don't install as well when project C is installed as a dependency of another project.
I also tried "minimum-stability": "dev" which did not work either.
Anyone know if I am missing something?

Install unstable fork

I maintain a project that uses an abandoned library with a bug that affects me. I'd like to install a fork that includes the bugfix. I can't find the way.
Relevant settings were this:
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"require": {
"php": "5.3 - 5.6",
"nuovo/spreadsheet-reader": "^0.5.11"
},
"config": {
"preferred-install": {
"*": "dist"
},
"vendor-dir": "Vendor/"
}
}
I've tried too many things to share but my latest iteration is:
{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/virtua-network/spreadsheet-reader"
}
],
"require": {
"php": "5.3 - 5.6",
"nuovo/spreadsheet-reader": "dev-master"
},
"config": {
"preferred-install": {
"*": "dist"
},
"vendor-dir": "Vendor/"
}
}
The package shows up in composer outdated:
PS D:\src> composer outdated
nuovo/spreadsheet-reader 0.5.11 dev-master f6bd49d Spreadsheet reader library for Excel, OpenOffice and structured text files
… but won't update:
PS D:\src> composer update nuovo/spreadsheet-reader
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
Also, f6bd49d hash is not latest fork revision but latest original package.
How can I install the fork with Composer?
You're using incorrect package name - in your fork package is named as virtua-network/spreadsheet-reader, but you're requesting nuovo/spreadsheet-reader. So your fork is not considered as a nuovo/spreadsheet-reader package, but as a virtua-network/spreadsheet-reader, so original package from Packagist is used. You should either revert name change in composer.json of your fork and leave it as nuovo/spreadsheet-reader, or use new name in require of composer.json in your app:
"virtua-network/spreadsheet-reader": "dev-master"

Laravel 5.6 composer doesn't install my package's dependencies

When i use "composer require x/y" command inside my custom package all done. Getting all dependencies perfectly.
But when i try to add to laravel project from bitbucket repository, only install my package without all dependencies.
I set my private repository to laravel composer.json file
"repositories": {
"hooks": {
"type":"package",
"package": {
"name": "x/y",
"version":"1.0.2",
"source": {
"url": "https://{username}#bitbucket.org/x/y.git",
"type": "git",
"reference": "master"
}
}
}
}
My custom repository composer.json
{
"name": "x/y",
"description": "Base Api System",
"license": "MIT",
"require": {
"php": "^7.2",
"tcg/voyager": "^1.1",
"predis/predis": "1.1",
"monarobase/country-list": "^2.0"
},
"require-dev": {
},
"autoload": {
"psr-4": {
"X\\Y\\": "src/"
}
},
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"X\\Y\\XYServiceProvider"
]
}
}
}
Composer require output
Using version ^1.0 for x/y
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing x/y (1.0.2): Cloning master from cache
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
You're using package type incorrectly. This type is for non-composer packages. Composer will not even look at composer.json file in such dependency, since it assumes that this file does not exist. All relevant information about package should be in package definition in repositories setting in composer.json of main (root) application.
But in your case you have repository with complete composer package (with correct composer.json file), so you should vcs or git type:
"repositories": [
{
"type":"git",
"url": "https://{username}#bitbucket.org/x/y.git"
}
]

Loading a composer package through a Github fork

I forked a library on Github and now want to load my fork into the project without adding the forked library into packagist. I get the following error after adding the repository and require to my composer.json:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package cnizzardini/ssl-certificate could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Here is my full composer.json
{
"name": "cakephp/app",
"description": "CakePHP skeleton app",
"homepage": "http://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
"php": ">=5.5.9",
"cakephp/cakephp": "~3.4",
"mobiledetect/mobiledetectlib": "2.*",
"cakephp/migrations": "~1.0",
"cakephp/plugin-installer": "*",
"guzzlehttp/guzzle": "^6.2",
"donatj/phpuseragentparser": "^0.7.0",
"cnizzardini/ssl-certificate": "dev-master"
},
"require-dev": {
"psy/psysh": "#stable",
"cakephp/debug_kit": "~3.2",
"cakephp/bake": "~1.1",
"phpunit/phpunit": "^5.5"
},
"suggest": {
"phpunit/phpunit": "Allows automated tests to be run without system-wide install.",
"cakephp/cakephp-codesniffer": "Allows to check the code against the coding standards used in CakePHP."
},
"autoload": {
"psr-4": {
"App\\": "src",
"Api\\": "./plugins/Api/src",
"Channel\\": "./plugins/Channel/src",
"System\\": "./plugins/System/src",
"Admin\\": "./plugins/Admin/src"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests",
"Api\\Test\\": "./plugins/Api/tests",
"Channel\\Test\\": "./plugins/Channel/tests",
"System\\Test\\": "./plugins/System/tests",
"Admin\\Test\\": "./plugins/Admin/tests"
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-create-project-cmd": "App\\Console\\Installer::postInstall",
"post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/cnizzardini/ssl-certificate.git"
}
],
"minimum-stability": "stable",
"prefer-stable": true
}
I have tried adding https://github.com/cnizzardini/ssl-certificate with and without the .git. I have also tried setting minimum-stability to dev and prefer-stable to false.
Nothing works :-(
The composer.json file on your fork still calls the package "spatie/ssl-certificate", so that's the name of the package you need to require.
This should work:
{
...
"require": {
...
"spatie/ssl-certificate": "dev-master"
},
...
"repositories": [
{
"type": "vcs",
"url": "https://github.com/cnizzardini/ssl-certificate.git"
}
],
...
}
If it doesn't, you can rename the package on your own fork by changing the name property in its composer.json file:
{
"name": "cnizzardini/ssl-certificate",
"description": "A class to easily query the properties of an ssl certificate ",
...
}

How to make Satis package dependencies install from packagist

I've successfully set up Satis on my own server and am able to pull in packages from it.
However, dependencies that are required in those private packages are constantly being cloned at their bleeding edge version instead of the specified version constraint. I think that Satis is creating a local mirror of the latest dev-version. However I do not want to have a local mirror, I just need them to install directly from Packagist.
So how do I need to setup the project / package / Satis to have the dependencies in those private packages installed from Packagist?
Thanks.
This is my Satis build file:
{
"name": "Package Server",
"homepage": "http://packages.URL",
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:USERNAME/REPO.git",
"options": {
"ssh2": {
"username": "USERNAME",
"pubkey_file": "PUBFILE",
"privkey_file": "PRIVATEFILE"
}
}
}
],
"require-all": true
}
And this is the composer.json file of the project requiring the private package (package has no tagged releases):
{
"name": "Test Project",
"description": "",
"require": {
"php": ">=5.4.0",
"USERNAME/REPO": "*"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.URL"
}
],
"minimum-stability": "dev"
}
And this is the private package's composer.json:
{
"name": "USERNAME/RPO",
"description": "",
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.0.*",
"vinkla/hashids": "~1.0"
},
"minimum-stability": "dev"
}
In your Satis config you defined "require-all": true.
This is default and selects all versions of all packages in the repository you defined.
You could try to remove "require-all": true in favor of a require section.
This means that Satis will only contain these specific packages and their versions, like so:
"require": {
"company/packageA": "*",
"company/packageB": "1.2.3",
"company/packageC": "2.0.0"
}
It's package cherry picking on Satis
So if I understand correctly I need to add the private packages that are available in the specified private repository in the require key and their own dependencies will then install from Packagist?
Add require-dependencies - this tells Satis to mirror not only the packages specified in the "require" section, but also all their dependencies.
See https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md#resolving-dependencies
Is it possible to have multiple packages resided in one defined repository or does every single package need their own repository url entry in Satis?
I think it's not possible to have multiple packages in one "type": "vcs" repository.
With "type": "composer" and a cloned packagist you can store multiple repos.
Think of http://drupal-composer.org with http://packagist.drupal-composer.org/.
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/somewhere/packageA" },
{ "type": "composer", "url": "https://packagist.org" }
],
"require": {
"package/packageA": "somewhere-dev",
"phpunit/phpunit": "*"
},
"require-dependencies": true
}

Resources