5

I'm currently working on a package (cms), which has a dev-dependency to a certain package (code-generator) to create code. This package is not needed in production.

However, when creating a website that uses the cms package, dev-dependencies (including the code-generator) are not installed (which is correct composer behavior btw).

But while developing the website, the code-generator is required.

Is there any way to force a certain dev-dependency to also install when the package is installed?

5
  • 2
    If you need this code generator package, you should add it to your composer.json. Commented May 11, 2018 at 11:41
  • You can run composer install --dev getcomposer.org/doc/03-cli.md#install Commented May 11, 2018 at 11:43
  • @rob006 yes I could do that, but that means I would need to do that for every site i'm using the package with, plus all the other people that would want to use this package. This is exactly what I want to prevent. Commented May 11, 2018 at 11:49
  • @DenzylDick That only installs packages defined in the root, not of dependent packages Commented May 11, 2018 at 11:50
  • See github.com/composer/composer/issues/1763 Commented May 11, 2018 at 15:00

1 Answer 1

4

This is not possible. Dependency can either be required for the package to work properly (then it should be in require section and it is always installed), or required only for development of this package (then it should be in require-dev section and is installed only when package repository is root). There is nothing in between. If this code-generator dependency is required by your package to work it clearly fails into first category (require section).

Usually in this case the best solution is to split this package into 2 packages: regular package and dev package with all tools used only during development process. So it should be installed by 2 commands:

composer require myvendor/mypackage
composer require myvendor/mypackage-dev --dev

This will still require everyone to install two packages instead of one, but it should not be a big problem if it is properly documented. Result should is more clear (it should be quite obvious what is the purpose of myvendor/mypackage-dev package) and gives more control to package owner (he can easily add new dependencies for dev package) and end user (he can always skip installing myvendor/mypackage-dev if he don't want to use this code generator).

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

Comments

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.