0
votes

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:

  1. I have a private git repository that I am attempting to add as a dependency for a project.
  2. 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?

1

1 Answers

4
votes

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