4

Im developing an extension and would want to use some composer extensions in it. So I have a composer.json file in app/code/Vendor/Extension/ path.

Do I simply run composer update in the extension directory? This will put the vendor directory into the extension right? Is there a way I can have magento pick up the composer.json of my extension when I run a update from root?

Also most importantly what is the best practice in this?

6
  • ` app/code/Vendor/Extension/` ?!! Are you sure ? the vendor folder is not supposed to be located at the root of the project: /path/to/magento/vendor? Any required package for your extension should be located into a require directive see getcomposer.org/doc/04-schema.md#require. When you will do composer.phar update into magento root folder, the extension will be installed into the vendor folder and thanks to autoloader from composer, your own extension will get access to it Jul 14, 2016 at 18:37
  • Yeah there is a vendor in the root thats created by magento. What I mean is that I need to package this extension and at that time how does magento pickup my extensions composer.json
    – Prasanth
    Jul 14, 2016 at 18:39
  • Use my composer.json as example: https://github.com/diglin/Diglin_Username2 then push it to github and submit your repo on packagist. After that you can trigger this command on magento to install your extension via composer into the vendor folder: composer.phar require namespace/modulename. namespace/modulename = name of the extension in composer.json Jul 14, 2016 at 19:27
  • 1
    I dont want to publish it to the ourside world. I would want to deploy to some magento installation myself and would like to just run a composer install to download the dependent packages. Is that possible?
    – Prasanth
    Jul 14, 2016 at 19:31
  • You can use https://github.com/composer/satis to create something similar to packagist but for your intern purpose. I didn't configured myself but it is possible to set access rights here getcomposer.org/doc/articles/… Jul 15, 2016 at 1:25

1 Answer 1

4

There are two options here:

  1. Described in the comments: create a package or a repository from your extension. If you don't want to push it to the world, you can create a Git repo locally. The repo should contain just your extension and composer.json in the root. Then link your extension's repository as a package to the Magento project in Magento's composer.json (see an example in https://getcomposer.org/doc/04-schema.md#repositories). Use "dev-xxx" version, where xxx is the branch name in your repo - then Composer will always be fetching the latest commit. Then, when you run composer update your package will be loaded with all its dependencies.

  2. Leave file structure as is and duplicate all dependencies, autoload and any other deployment-specific information from your extension's composer.json you the Magento's root composer.json. Then when running composer update (in Magento root) all dependencies of your extension will be deployed.

6
  • So what would be the deployment procedure when I deploy the extension to my customer? Edit the root composer.json and add the dependencies and run an update? Isn't there a better way to do that without touching the root magento installation.
    – Prasanth
    Jul 15, 2016 at 6:11
  • Yes, this is a way. Why does it look bad for you? In the customer's project you should use Composer-based installation, created via composer create-project command. In this case your customer's project owns the root composer.json, so it's OK to modify it.
    – BuskaMuza
    Jul 28, 2016 at 21:19
  • Its bad as you you can just drop in the extension and let magento take care of the rest. You will have to edit the composer.json and do the rest. Ideally the composer.json should reside in extensions own directory and it should be somehow merged.
    – Prasanth
    Aug 1, 2016 at 10:55
  • Yes, for production. If the extension is deployed by Composer, all its dependencies will be deployed automatically. If you just includes code of the extension in your project, it's not a dependency considered by Composer, so Composer doesn't care about it. Use option #1, if you want Composer to handle the extension's dependencies.
    – BuskaMuza
    Aug 1, 2016 at 16:20
  • Maybe I'm confusing you... For the customer, Composer will handle the chain of dependencies. I thought your question was about development. Duplication of dependencies is needed for development only, if you go with option #2
    – BuskaMuza
    Aug 1, 2016 at 16:21

Your Answer

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

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