Alana Storm
Alana Storm

Reputation: 166076

Composer: Prefer VCS Repository over Packagist

I'd like to use the adldap/adldap library in my PHP based project. While the maintainer of this package has not added this package to packagist, they have included a composer.json file. So, normally, I'd just add the following my MY composer.json, and go about my day.

"repositories": [
{
    "type": "vcs",
    "url": "https://github.com/adldap/adLDAP"
}], 

"require": {
    /* my other packages */
    "adldap/adldap":"4.04"
},

However, this won't work, because adldap/adldap is already claimed by a different project in packagist, and composer always assumes I want the packagist package. (Making things even more complicated, the packagist package is a fork of the original project, and a fork that isn't accepting upstream changes).

Is there a way to tell composer to prefer the version from the configured VCS repository? Or am I stuck forking the package myself, changing its name, and pointing composer to my fork? (or one of the other forks maintained to work around this very issue?)

Upvotes: 2

Views: 1821

Answers (1)

Jens A. Koch
Jens A. Koch

Reputation: 41766

The problem with this package is that, the "v4.0.4" version branch doesn't contain a composer.json file. That means that Composer can't pick it up and will skip this branch.

You could probably use an require inline alias to get this working. https://getcomposer.org/doc/articles/aliases.md#require-inline-alias

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/adldap/adLDAP"
        }
    ],
    "require": {
        "adldap/adldap": "dev-master as 4.0.4-dev"
    }
}

That will fetch the dev-master version of adldap/adldap from GitHub and alias it to 4.0.4-dev.

I don't know if this is a good way, maybe too hackish, but it will work.

In the future: they should include the composer.json file in their next release, so that you can get rid of the inline alias and require the normal version.


The example above uses the same repo, but a different branch for aliasing. The next example uses a different repo, with a reference branch (called patch). This repo/branch is used "instead" of the original package. The "reference branch" means you pick a branch from the forked repo and prefix it with "dev-". After a composer install, you should get the forked repo of adldap/adldap instead of the one from packagist.

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/repo-of-the-fork/adldap"
        }
    ],
    "require": {
        "adldap/adldap": "dev-patch"
    }
}

While this might resolve standalone, it may not resolve, when other packages rely on a specific version of adldap. To solve this, you can use the "inline alias" trick again: dev-patch as 4.0.4-dev.

Upvotes: 5

Related Questions