1

I am using the package teamtnt/laravel-scout-tntsearch-driver and I wish to make a very small change to one of the files within teamtnt/tntsearch which is one of the packages dependencies.

Usually I would:

  1. Create a fork of the package.
  2. Add the repository into my composer.json as follows:
  "repositories": [
    {"type": "vcs", "url": "https://github.com/user/packagefork"}
  ],
  1. Require/Upgrade the package to the correct version (usually dev-master) keeping the original name spacing and it all works fine.

However, with a dependency which is not directly included in my composer.json file, this does not seem to work. Do I need to fork both the base package, and the dependency package even though I do not need to change anything within the base?

I am hoping there is a simple way to do this, without having to fork each level.

1 Answer 1

4

This was actually quite simple. Not too sure why it did not work originally! Instructions below for anyone wondering:

  1. Fork the package (i.e. GitHub)
  2. Add the repo from your username, to your projects main composer.json as follows:
  "repositories": [
    {"type": "vcs", "url": "https://github.com/youruser/tntsearch"}
  ],
  1. Edit the composer.json file within the new fork you created in step 1 (youruser/tntsearch) and create/add to the extras key:
    "extra": {
        "branch-alias": {
            "dev-master": "2.0.x-dev"
        }
    }

This effectively allows you to install your dev-master version, but allow other packages where this is a dependency to request the 2.0 version (in this case). You do need to be careful in this case that you have forked the correct version and any upgrades are correctly managed later down the line, or things may break!

More info on composer alias here

  1. Require/Upgrade the package using original package namespace, at the dev-master version.
composer require teamtnt/tntsearch:dev-master

The name spacing and package versions will remain the same as before your fork, but the edits from your fork will be pulled into your project instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Amazing, thank you. 👊 One thing I don't understand though, is how the branch alias directive knows which repo this alias should be for. All of them? So you can't alias one package's dev-master to one branch in repo A, then another's dev-master to a different branch in repo B? The dev prefixes and suffixes are nebulous too. Composer is madness.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.