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

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"
}
]

Related

satis composer package not found

I'm trying to create custom composer packages in order use/update some custom wordpress plugins across all my projects.
I decided on using satis, following this article: https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md
I've installed satis, and successfully generated the webview and deployed it. It shows the two composer packages (git repositories) that were linked with satis.
Problem
When I create a new project and include my custom composer package in my package.json, running composer update returns an error.
Error
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package namespace/test 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.
- It's a private package and you forgot to add a custom repository to find it
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
My package composer.json file:
{
"name": "name",
"type": "project",
"license": "MIT",
"description": "desc",
"authors": [],
"keywords": ["bedrock", "wp"],
"config": {
"preferred-install": "dist"
},
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org"
},
{
"type": "composer",
"url": "https://packages.namespace.tld"
}
],
"require": {
"php": ">=5.6",
"composer/installers": "^1.4",
"vlucas/phpdotenv": "^2.0.1",
"johnpbloch/wordpress": "^5.0.2",
"oscarotero/env": "^1.1.0",
"roots/wp-password-bcrypt": "1.0.0",
"roots/wp-config": "1.0.0",
"wpackagist-plugin/contact-form-7": "*",
"namespace/test": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0.2",
"roave/security-advisories": "dev-master"
},
"extra": {
"installer-paths": {
"www/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
"www/app/plugins/{$name}/": ["type:wordpress-plugin"],
"www/app/themes/{$name}/": ["type:wordpress-theme"]
},
"wordpress-install-dir": "www/wp"
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"test": [
"phpcs"
]
}
}

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"

Delegating to Local composer.json

With my clean Laravel 5.3 installation, I can run composer install to install the dependent packages.
Now, I've an internal package with its own composer.json, like below:
{
"name": "bar/foo",
"description": "A package for handling foo",
"licence": "MIT",
"authors": [
{
"name": "A. Foo",
"email": "a#foo.bar"
}],
"minimum-stability": "dev",
"require": {},
"autoload": {
"psr-4": {
"Foo\\Bar\\": "packages/foo/Bar/src"
}
}
}
So I prefer to autoload from the package itself, instead of autoloading from the main composer.json.
My questions:
Running composer dumpa from packages/foo/Bar doesn't take effect for autoloading. After Generating autoload files, Laravel doesn't know namespace Foo\Bar
Is there a way to run composer dumpa for all recursive composer.jsons?
You need to add the following section to your global composer.json
"repositories": [
{
"type": "path",
"url": "packages/*/*"
}
]
You also need to add the packages to the require object in composer.json

Don't work require in Copmposer

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!

Laravel 4 package from private repository: ServiceProvider not found

I created a package for Laravel 4 that worked properly when used in development in workbench but when I install it with Composer it keeps returning me the error Class 'Myvendor\Mypackage\MypackageServiceProvider' not found.
There is a particularity with my package which is that the name of my classes sources are different from the name of my package. Usually they are the same.
vendor/
Houle/
laravel-dynamite/
src/
Fhoule/
Dynamite/
DynamiteServiceProvider.php
I know that it can work because Laravel work's this way too.
vendor/
laravel/
framework/
src/
Illuminate/
And the property PSR-0 of my package composer.json seems to be properly configured:
"name": "Houle/laravel-dynamite",
...
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x"
},
"autoload": {
"classmap": [
"src/migrations",
"src/controllers",
"src/models"
],
"psr-0": {
"Fhoule\\Dynamite": "src/"
}
},
...
How I created my package:
Created the package with Artisan.
Maked it work properly in workbench directory
Pushed to private Bitbucket repo
Installed new instance of Laravel
Changed composer.json configuration to install my package (from private repository)
"name": "laravel/laravel",
...
"require": {
"laravel/framework": "4.0.*",
"Houle/laravel-dynamite": "2.0.1"
},
"repositories": [{
"type": "package",
"package": {
"name": "Houle/laravel-dynamite",
"version": "2.0.1",
"source": {
"url": "git#bitbucket.org:Houle/laravel-dynamite.git",
"type": "git",
"reference": "v2.0.1"
}
}
}],
...
Added my package Service Provider to app/config/app.php:
'providers' => array(
'Fhoule\Dynamite\DynamiteServiceProvider',
)
That's where my application return the error Class 'Fhoule\Dynamite\DynamiteServiceProvider' not found.
What could be my issue?
I found my problem, it hadn't nothing to do with the way I named my vendor, package and classes.
It was that in my composer.json (root of the project), I set my repository type to package but like the Composer documentation states the type package is for packages that don't support Composer. That's why Composer wasn't updating my autoload_classmap.php file.
So if you want to use a private repository (like at Bitbucket or GitHub) you need to set the type of the repository to git:
{
"name": "laravel/laravel",
...
"require": {
"laravel/framework": "4.0.*",
"houle/laravel-dynamite": "dev-master"
},
"repositories": [{
"type": "git",
"url": "git#bitbucket.org:Houle/laravel-dynamite.git"
}],
...
}
Hope it helps someone.
The composer.json in your package (Package found in BitBucket) needs to specify the PSR-0 Autoloading component, rather than the composer.json file in your top-level Laravel project.
Can you show us the composer.json file for your repo in the private repository?

Resources