Closed jjtroberts closed 7 years ago
Looking at the main Composer entry point, script config is processed very early before delegating to Symfony\Component\Console\Application
to process the command line arguments and choose the Command to execute. The current upstream implementation directly reads and parses the root composer.json
. I don't see any way to modify the Commands that are registered via a plugin.
It probably would be possible to call post-install/post-update actions that were declared in an included composer.json file. If nothing else, composer-merge-plugin could call such scripts itself when it is called for those events.
Thanks for taking a look at this. I really just need a way to call post-instal/post-update actions if they exist in an included composer.json file. Our default composer.json installs a base theme, and the included composer.json offers the ability to install a different version of that base theme. Having the means within composer to activate the included theme would be immensely helpful.
A reasonable first attempt at this feature would be to:
I don't have any time at the moment to work on adding this functionality, but I would be more than happy to review a pull request implementing it.
Making progress. I have a feature flag set to false by default, but when set to true it allows MergePlugin.php to retrieve a list of handlers registered in an included file (haven't tested recursive yet). I could use some advice at this point regarding what to do with the resulting array of scripts. How and where do I execute them?
The collected scripts would be executed from the corresponding event handler in MergePlugin. The logic to call a handler is in Composer's EventDispatcher class. You already have the Event to dispatch passed into the compsoer-merge-plugin handler.
The easiest thing to do might be to introduce a subclass of Composer\EventDispatcher\EventDispatcher
so you can get at the protected doDispatch
method. Then you'd just need to call addListener
for each of the callbacks you found and redeliver them locally available event.
Been so long since I've done OO programming. This is out of my league at the moment. I probably need to just allow Jenkins to do the automation and let composer do what it is good at.
This works for my use-case, but it is a hack: https://github.com/gd-jroberts/composer-merge-plugin/commit/de251a33308ccf12b0aa33ca5b4e37bd259a0210
At least partially handled by merge-scripts
(#135 & #136) and 586ae1edd4d9492eaaf8fb21ad8ad86306d02b3d where we started hooking Composer 1.1's INIT event.
Is there any way to execute scripts from composer.local.json? I trying to allow custom sites to add additional themes and ensure that theme is activated after install or update. Perhaps with an option to append or override scripts from the parent composer.json file?