3

I want to make my extension, say Easy Template Path Hints which is available on github(may be on bitbucket someday) installable via composer. Tried many variation but it's not working.

Here are some of my attempts

1. Using following series of composer commands

composer config repositories.magepsycho git https://github.com/MagePsycho/magento2-easy-template-path-hints.git
composer require magepsycho/magento2-easy-template-path-hints:1.0.0

This resulted in error

The requested package magepsycho/magento2-easy-template-path-hints could not be found in any version, there may be a typo in the package name.

2. Manually editing the composer.json

Added the following under "require" node

"magepsycho/magento2-easy-template-path-hints": "master"

And the following under "repositories" node

"magepsycho": {
    "type":"package",
    "package": {
        "name": "magepsycho/magento2-easy-template-path-hints",
        "version":"master",
        "source": {
            "url": "https://github.com/MagePsycho/magento2-easy-template-path-hints.git",
            "type": "git",
            "reference":"master"
        }
    }
}

And then

composer update

There was no any error and it successfully downloaded the extension under vendor folder. But was not installed in app/code folder

May be listing the module to packagist.org may help but I want it to be installable via git also.

Any Suggestions?

  • can you tell me how to make my module available in github – Jaisa Feb 15 at 12:52
2

I was able to fix the issue by using following commands:

composer config repositories.magesycho-magento2-easy-template-path-hints git git@github.com:MagePsycho/magento2-easy-template-path-hints.git
composer require magepsycho/magento2-easy-template-path-hints:dev-master

Explanation

Before I was using magepsycho/magento2-easy-template-path-hints:1.0.0 instead of magepsycho/magento2-easy-template-path-hints:dev-master.

If you are loading a package from VCS repository (git, svn etc.), version should be a branch name prefixed with dev-

Source: https://getcomposer.org/doc/05-repositories.md#vcs

  • 2
    Currently your repo does not have a tagged version. Once you add a tag, for example 0.5.0 or v0.5.0, you can just use composer require magepsycho/magento2-easy-template-path-hints and composer will install the last version for you. – Kristof at Fooman Jan 28 '16 at 7:23
  • Sounds interesting! Will give a try. – MagePsycho Jan 28 '16 at 7:24
  • You should remove this answer as it's really misinformation. You should not load a package from a VCS repository using a branch name if at all possible. – Navarr Jul 7 '17 at 14:04
  • @Navarr can you add the correct answer to this? – paj Jul 21 '17 at 14:21
  • @paj I have an answer at the top of the list? – Navarr Jul 21 '17 at 17:06
2

For a private repository, you would want to do what you've already done - which is create a repository directive in your composer.json and require it. You would then ideally use git tags to mark your versions.

For a public repository, like what you actually have - you have a few misconceptions about how Magento 2 and composer work together.

One big thing of note is that composer packages aren't in app/code, and you don't want them there. Instead, they install directly to the vendor/ directory and stay there. This allows any code in app/code/ to be specific to your environment and keeps your installation clean.

Looking at your repository, you have two composer.json files - I understand why, since your goal was to get the code copies into app/code, but with the information that you shouldn't be doing that, you can (and should) remove the composer.json from the src/ directory. You'll then need to change your base directory composer.json's file require directive to point to "src/registration.php" instead of just "registration.php"

Once you've done that, it should load in to vendor/ when required, and should be accessible for module:enable and in Magento itself.

The next step, since this appears to be a public extension - is to add it to Packagaist. Packagist is the default repository in composer, and adding it to Packagist allows its use without defining a new vcs repository type.

You can submit it to Packagist here: https://packagist.org/packages/submit - it will require an account, and if you read carefully packagist will help walk you through setting up your repository to automatically inform packagist of new versions.

1

Try adding this in in composer.json on the same level as repositories

extra": {
    "map": [
        [
            "*",
            "MagePsycho/EasyTemplatePathHints"
        ]
    ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.