-1

I've forked a composer package so I can fix an issue with it and submit a PR to the maintainer.

Meanwhile, while it doesn't get merged, I want to use my version of the package in my projects. I've tried adding the repository information on composer.json but it always uses the regular package.

How can I force it to use my version? Do I have to rename the package?

Thanks in advance.

Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36
Gonçalo Marrafa
  • 2,013
  • 4
  • 27
  • 34
  • 1
    Please share what exactly you've changed – Nico Haase Oct 23 '19 at 08:50
  • I've changed some package code... Don't really think the source code influences this behavior. – Gonçalo Marrafa Oct 23 '19 at 09:14
  • No, you should share how you've changed the `composer.json` such that others can check these changes for an error – Nico Haase Oct 23 '19 at 09:38
  • I haven't made any changes in `composer.json`. I just added a repository definition in the `composer.json` file of projects that use the package. My question is exactly that: do I have to change the package name in the package's `composer.json` so it can be installed? – Gonçalo Marrafa Oct 23 '19 at 09:42
  • @GonçaloMarrafa You have to amend the package name if you want to publish it on packagist. For example `marrafa/mypackage`. Or - epxlictly define the fork as a repo in the `composer.json` where you want to use the package. – madflow Oct 23 '19 at 09:48
  • If you don't change anything in your `composer.json`, how should Composer know about that new package? – Nico Haase Oct 23 '19 at 09:52
  • 1
    Possible duplicate of [Loading a composer package through a Github fork](https://stackoverflow.com/questions/45377221/loading-a-composer-package-through-a-github-fork) – Nico Haase Oct 23 '19 at 09:52
  • @NicoHaase I added a repo in `composer.json` like @madflow suggested. Shouldn't composer be aware of it? – Gonçalo Marrafa Oct 23 '19 at 10:02
  • Well, that depends on **how** you've done that. As long as we cannot see how **exactly** you've changed the configuration, we can only guess – Nico Haase Oct 23 '19 at 10:09

2 Answers2

1

I've figured it out! I had a constraint on stable versions so it would not install a dev version and that was why it wouldn't read my fork.

Btw, no changes are required on the package's composer.json file. It treats it as the regular upstream package.

Gonçalo Marrafa
  • 2,013
  • 4
  • 27
  • 34
0

so, your forked package is on github for example. so, just use it:

composer.json:

"require": {
    "mygithub/blabla": 1.0
},
"repositories": [
        {
            "type": "vcs",
            "url": "git@github.com:mygithub/blabla.git"
        }
]

more info can be found here

myxaxa
  • 1,391
  • 1
  • 8
  • 7
  • Thanks for your answer. The thing is... it's not "my package". It's a fork of `foo/package`. The package already exists in packagist. I just want to use my version of it. – Gonçalo Marrafa Oct 23 '19 at 09:39