General Redneck
General Redneck

Reputation: 1345

How do I use a package in composer that has the same name as another package?

I have a rare case where I have two packagists in play here because I'm working on a Drupal Project. I have https://packagist.org and http://packagist.drupal-composer.org/.

The problem here is that they both define the package drupal/coder. One of them respects the composer.json, and the other does not, but generates one. I'm fixing to go create an issue over here that tells them to respect the composer.json is one is available.

I would like to use the package from packagist.org, but since I define packagist.drupal-composer.org, I'm not able to.

Is there a way to identify a package from a specific source, or to redefine a repository that already has a package.

I tried to add

{
  "type": "vcs",
  "url": "http://git.drupal.org/project/coder.git"
}

in my repositories to no avail. Doing a composer update; composer show simply shows me the package from packagist.drupal-composer.org. Additionally, defining:

{
  "type": "composer",
  "url": "http://packagist.org"
}

Provides me with the same results.

My last thought is to define a "package" and point it at the repository with a different name but seems like a lame work around because then I have to maintain "versions".

Upvotes: 1

Views: 1502

Answers (2)

Jens A. Koch
Jens A. Koch

Reputation: 41756

  1. You define Drupal's packagist as Composer type repo.
  2. You define a git repo for the drupal/coder repo.

Both definitions go into the repository section.

Now: all packages are fetched from http://packagist.drupal-composer.org/, except drupal/coder.

Here you go:

{
    "type": "project",
    "repositories": [
        {
            "type": "git",
            "url": "http://git.drupal.org/project/coder.git"
        },
        {
            "type": "composer",
            "url": "packagist.drupal-composer.org"
        }
    ],
    "require": {
        "drupal/coder": "8.2.1"
    }
}

Upvotes: 2

webflo
webflo

Reputation: 146

Yes thats definitely a problem. But here is a workaround, just the package definition above packagist.drupal-composer.org to your composer.json.


"repositories": [
    {
        "type": "composer",
        "url": "https://packagist.org/p/drupal/coder.json"
    },
    {
        "type": "composer",
        "url": "http://packagist.drupal-composer.org"
    }
]

Upvotes: 3

Related Questions