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?
Best Answer
There are two options here:
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'scomposer.json
(see an example in https://getcomposer.org/doc/04-schema.md#repositories). Use "dev-xxx" version, wherexxx
is the branch name in your repo - then Composer will always be fetching the latest commit. Then, when you runcomposer update
your package will be loaded with all its dependencies.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 rootcomposer.json
. Then when runningcomposer update
(in Magento root) all dependencies of your extension will be deployed.