-1

I create my own package located in the root folder named /ECommerce.

This directory contains composer.json and my package code.

When I want to add a new package to ECommerce/composer.json, which is necessary for the package to work, after calling the $ composer update/install command, that package is not installed.

If I add the desired package to the root composer.json it is installed.

Is there any possibility to merge these two composer.json files or do I have to copy composer.json from the root folder to the package folder at the end of the project

Example:

Structure: / - app - Ecommerce - ... - composer.json - resources - vendor - composer.json - .... 

I add composer require nwidart/laravel-modules in Ecommerce and that is not installed.

If I add in root composer.json, then it becomes installed.

4
  • 1
    Did you require your Ecommerce package in the root composer.json ? if not you could look at that answer : stackoverflow.com/a/29995226/8126784 Commented Oct 9, 2023 at 8:43
  • Only in autoload PSR-4 Commented Oct 9, 2023 at 8:47
  • It's hard to understand what you want to accomplish. Why do you have a package in a separate directory, with its own composer.json file? Why don't you install this package with composer, and declare it in the project's composer.json file? Commented Oct 9, 2023 at 9:40
  • Ivan, have you seen my answer below, and my comment above? Any feedback at all? Commented Oct 11, 2023 at 5:42

1 Answer 1

0

Simply, composer does not support multiple, nested or otherwise, composer.json files, aside from the ones that come from the managed dependencies.

There is a single composer.json per project, declaring that project's dependencies.

Then each project has their own composer.json file to declare their dependencies, and the whole thing is resolved when executing update, install, require, etc.

Having a package installed manually in a separate directory, when that project has more Composer dependencies, is a Bad Idea. If that package is actually a composer package and declare its own dependencies, then install it as a project package (require your/package), and let Composer deal with dependencies when appropriate. If you add/change/remove dependencies in your/package, then you composer update the root project, and you let Composer install/change whatever else is needed.

Note: there is a 3rd party plugin that appears to support merging multiple composer.json files.

https://github.com/wikimedia/composer-merge-plugin

Haven't used it myself; and while there is might be the occasional use for such structure, it's not a built-in capability, and more often than not you'd be better off doing things the "usual" way.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.