Skip to content
Advertisement

Is there a way to interactively install suggested composer packages?

I would like to offer users of my composer package an interface to select and install any of the suggested packages. There seems to be no command line option, and in the API I can only find a getSuggests() method that lists the suggested packages.

Is there any way (native or with a third party installer), to give the user the choice to select suggested packages?

Advertisement

Answer

As far as I know, there is no way to achieve this with common composer functionality.

You can write your own scripts to be executed at post-package-install. But Scripts are only executed if defined in the root package’s composer.json (more information on how to use scripts see here). Scripts defined in dependencies are not executed for security concerns (there was a discussion on the github some time ago about this).

But maybe a composer-plugin fits your needs. Plugins are used to expand composer’s functionality (more information about plugins see here).

As a simple alternative way, I suggest to define a suggested package message like, if you need XY functionality run: php composer.phar require vendor/package:2.* and the user then can use this command to install it. Not as comfortable as you requested but still easy enough for most users I think.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement