Load composer dependencies of private git repository - composer-php

I've been a bit confused how Composer loads dependencies of a private repository project. I have found this link but I am not sure if this comment is referring to nested repositories or simply any dependency of a repository. To clarify my situation:
I have a private git repository that I am attempting to add as a dependency for a project.
The private git repository is also a composer project, which contains a composer.json which requires publicly available packages.
I have the following code in my composer.json for the project.
"repositories": [
{
"type": "package",
"package": {
"name": "{vendor}/{package-name}",
"version": "{arbitrary-version}",
"type": "package",
"source": {
"url": "git#github.com:{github-username}/{github-repository}.git",
"type": "git",
}
}
}
]
"require": {
"{vendor}/{package-name}": "^0.0.1"
}
So if I were to do composer update on the project after these changes it will successfully download my package from the private repository, but it does not trigger a check/update on the composer.json of the private repository - so no vendor folder is created and critical dependencies are not installed. The private repository composer.json is below:
{
"name": "{vendor}/{package-name}",
"description": "{removed}",
"type": "library",
"require": {
"illuminate/database": "^5.6",
"chumper/zipper": "1.0.x",
"symfony/debug": "^4.0",
"vlucas/phpdotenv": "^2.4"
},
}
So my question is, is what I want to do achievable with a private repository via composer and if so does anybody know where I am going wrong?

package type is for non-composer dependencies. If you use this type, Composer will not even look for composer.json file inside of defined package source, you need to include all required information about package inside of the package declaration in your project composer.json:
"repositories": [
{
"type": "package",
"package": {
"name": "{vendor}/{package-name}",
"description": "{removed}",
"type": "library",
"require": {
"illuminate/database": "^5.6",
"chumper/zipper": "1.0.x",
"symfony/debug": "^4.0",
"vlucas/phpdotenv": "^2.4"
},
"version": "{arbitrary-version}",
"source": {
"url": "git#github.com:{github-username}/{github-repository}.git",
"type": "git",
}
}
}
]
But in your case (you have a package with proper composer.json) you should use vcs type:
"repositories": [
{
"type": "git",
"url": "git#github.com:{github-username}/{github-repository}.git"
}
]

Related

How to install github package in laravel 7

I am new in laravel 7. i want ask how to install github package into my laravel project.
(https://github.com/lomotech/jajahan) this package i want to install to my laravel but not instruction in this package.
If a package is missing a composer.json, you can add the following to your project's composer.json:
"repositories": [
{
"type": "package",
"package": {
"name": "lomotech/jajahan",
"version": "v2.2018.01",
"source": {
"url": "https://github.com/lomotech/jajahan",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"lomotech/jajahan": "*"
},
"autoload": {
"psr-4": {
"Lomotech\\Jajahan\\": "vendor/lomotech/jajahan/"
}
},
The autoload entry allows composer to generate the vendor classmaps so you can use the package in your code by:
use Lomotech\Jajahan\SomeClassFile;
Finally, run composer install/update.

Install private repositories on sub-repositories

I have two private repositories, let's call them RepoA and RepoB. RepoA is required by the RepoB and they are both private repos on gitlab with the port 620.
Here are the composer.json in both repo:
Repo A
{
"name": "namespace/repoA",
"description": "My repository A.",
"require": {
"php": ">=5.4"
}
}
Repo B
{
"name": "namespace/repoB",
"description": "My repository B.",
"repositories": [
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoA.git"
}
],
"require": {
"namespace/repoA": "dev-master"
}
}
Now let's say I have a project (ProjectA), which I want to install RepoB.
Project A
{
"repositories": [
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoB.git"
}
],
"require": {
"namespace/repoB": "dev-master"
}
}
However, when I run my composer install, I get the following error:
Problem 1
- Installation request for namespace/repoB dev-master -> satisfiable by namespace/repoB[dev-master].
- namespace/repoB dev-master requires namespace/repoA dev-master -> no matching package found.
I understand that it's unable to find the package since it's a private repository, but since it's inside the repositories of the repoB, why is it not fetching it?
I thought it would work if I added the repositories to the Project A:
{
"repositories": [
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoA.git"
},
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoB.git"
}
],
"require": {
"namespace/repoB": "dev-master"
}
}
But it still does not work until I add it into my require of my Project Aas well:
{
"repositories": [
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoA.git"
},
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoB.git"
}
],
"require": {
"namespace/repoB": "dev-master",
"namespace/repoA": "dev-master"
}
}
Now my question is... How can I make composer install my repoA by specifying only my repoB?
You cannot and here is an explanation: Why can't Composer load repositories recursively?

composer installs own TYPO3 extension in wrong path

I have a own TYPO3 extension hosted on bitbucket. Getting this via composer works (see here for input). The extension is downloaded into my vendor folder. Being there i cannot install the extension via extension-manager.
How can I getting my ext into typo3conf/ext (ensuring autoloading will work)?
The extensions coming via
{
"type": "composer",
"url": "http://composer.typo3.org/"
}
are going to (as expected):
web/typo3config/ext
here is my project composer.json:
{
"repositories": [
{
"type": "composer",
"url": "http://composer.typo3.org/"
},
{
"type": "package",
"package": {
"name": "metaxos/exaibbrplus",
"version": "dev-2016",
"source": {
"url": "https://metaxos#bitbucket.org/metaxos/exaibbrplus.git",
"type": "git",
"reference": "release/2016"
}
}
}
],
"name": "Metaxos/ibbrating2016",
"require": {
"typo3/cms": "7.6.2",
"bk2k/bootstrap-package" : "dev-master",
"typo3-ter/compatibility6" : "7.6.0",
"typo3-ter/extension-builder" : "7.6.0",
"metaxos/exaibbrplus": "dev-2016"
},
"extra": {
"typo3/cms": {
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": "web"
}
}
}
here is my extension composer.json:
{
"name": "metaxos/exaibbrplus",
"description": "custom ext for typo3",
"type": "typo3-cms-extension",
"version": "0.0.1",
"require": {
"typo3/cms-core": ">=7.6.0,<8.0"
},
"replace": {
"extkey": "self.version",
"typo3-ter/extkey": "self.version"
},
"autoload": {
"psr-4": {
"Metaxos\\Exaibbrplus\\": "Classes/"
}
},
"keywords": ["custom", "ext"],
"homepage": "http://www.blah.ch"
}
For Composer to install the package in web/typo3conf/ext, the package needs to have the type typo3-cms-extension. In your extension's composer.json this type is actually declared, however Composer will not respect it because you explicitly declare the package configuration in your project-level composer.json:
"repositories": [
# ...
{
"type": "package",
"package": {
"name": "metaxos/exaibbrplus",
"version": "dev-2016",
"source": {
"url": "https://metaxos#bitbucket.org/metaxos/exaibbrplus.git",
"type": "git",
"reference": "release/2016"
}
}
}
]
As you're using "type": "package" for your own repository, I suspect that Composer ignores the composer.json from that package. As you already have a Git repository that contains a composer.json, I'd suggest adding the repository using the vcs type instead:
"repositories": [
{
"type": "vcs",
"url": "https://metaxos#bitbucket.org/metaxos/exaibbrplus.git"
}
]
When doing that, Composer should use the composer.json from that repository, recognize the correct package type (typo3-cms-extension) and install the package in the correct directory.
You need to add the type key with the value typo3-cms-extension to the root composer.json. This will place your extension in web/typo3conf/ext instead of vendor/$vendor/$package which in turn will make it available to the cms.
It is important, to know that if you redefine the package in the root composer.json as repository type package, nothing from the extensions' composer.json file will be taken into account and you need to define any concerns about that package in the root composer.json.
So-applying the rules I mentioned above, your root composer.json will look like that:
{
"repositories": [
{
"type": "composer",
"url": "http://composer.typo3.org/"
},
{
"type": "package",
"package": {
"name": "metaxos/exaibbrplus",
"version": "dev-2016",
"type": "typo3-cms-extension",
"source": {
"url": "https://metaxos#bitbucket.org/metaxos/exaibbrplus.git",
"type": "git",
"reference": "release/2016"
},
"autoload": {
"psr-4": {
"Metaxos\\Exaibbrplus\\": "Classes/"
}
},
}
}
],
"name": "Metaxos/ibbrating2016",
"require": {
"typo3/cms": "7.6.2",
"bk2k/bootstrap-package" : "dev-master",
"typo3-ter/compatibility6" : "7.6.0",
"typo3-ter/extension-builder" : "7.6.0",
"metaxos/exaibbrplus": "dev-2016"
},
"extra": {
"typo3/cms": {
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": "web"
}
}
}
As mentioned above by #helmbert, you are either left with completely redefining the package or using another repository type. You may want to consider using satis or a URL repository.
try to add
"replace": {
"exaibbrplus": "self.version",
"typo3-ter/exaibbrplus": "self.version"
},
And use only "Metaxos\\Exaibbrplus\\": "Classes/" in the autoloader.

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
}

Composer dependencies in local package

I use a local repository ("depA") within my projects composer.json:
"repositories": [
{
"type": "package",
"package": {
"name": "marc/depA",
"version": "dev-master",
"source": {
"url": "/Users/Marc/Sites/depA",
"type": "git",
"reference": "develop"
}
}
}
],
"require": {
"marc/depA": "dev-master",
This works like a charm but it won't resolve dependencies from "depA". This means since "depA" requires "depB" (in composer.json of "depA") -> "depB" wont be installed.
Is this even possible with local packages?
Thanks,
Marc
You are defining the package inline so if you do it like this you must redefine all the requires etc inline as well. That's really not the best way to go at it. If it's a git repo and it has a composer.json you'd better use a vcs repository e.g.:
{
"repositories": [
{
"type": "vcs",
"url": "/Users/Marc/Sites/depA"
}
],
"require": {
"marc/depA": "dev-master",
}
}

Resources