Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post-outdated-cmd and pre-outdated-cmd events #11818

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented Jan 28, 2024

I use a root composer.json inside my monorepository and forward commands to run in all subpackages. Beside install and update, I would like todo that also for the outdated command here: https://github.com/schranz-search/schranz-search/blob/6e84eb2692ea257397d9ebe7b67fce1753cdba98/composer.json#L15

So I thought I could add new events to achieve this.

Example Usage:

{
    "type": "project",
    "license": "MIT",
    "require-dev": {
        "schranz/mono": "^2.0.1"
    },
    "scripts": {
        "post-outdated-cmd": "@php vendor/bin/mono run composer outdated"
    }
}

Let me know what you think about this new events?

@alexander-schranz alexander-schranz marked this pull request as draft January 28, 2024 14:15
Comment on lines +119 to +121
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'outdated', $input, $output);
$eventDispatcher = $composer->getEventDispatcher();
$eventDispatcher->dispatch($commandEvent->getName(), $commandEvent);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I orientated by the ArchiveCommand not sure if this additional dispatch is expected or the dispatchScript is enough to be added.

Seldaek added a commit that referenced this pull request Feb 7, 2024
@Seldaek
Copy link
Member

Seldaek commented Feb 7, 2024

Why not use just the PluginEvents::COMMAND event which fires for every command run?

$ COMPOSER_DEBUG_EVENTS=1 c outdated
Dispatching init event
Dispatching pre-command-run (outdated) event
Dispatching pre-command-run (show) event
Dispatching command (show) event

pre-command-run or command event should do no?

@Seldaek Seldaek added this to the 2.7 milestone Feb 7, 2024
@alexander-schranz
Copy link
Contributor Author

@Seldaek wanted that it works in all cases the same and is transparent in the composer.json what is happening. As I already use the following post commands already:

        "post-install-cmd": "@php vendor/bin/mono run composer install",
        "post-update-cmd": "@php vendor/bin/mono run composer update",

@Seldaek
Copy link
Member

Seldaek commented Feb 7, 2024

OK but then it sounds to me like we'd need a more generic solution like the pre-command-run, a post-command-run that fires always after the end of the command? Otherwise you'll add these to every command eventually? :D

@alexander-schranz
Copy link
Contributor Author

If you have an idea how to implement a general solution I'm also open for that :) The only thing is that we may then not have constants for the pre and post commands if somebody uses them?

@Seldaek
Copy link
Member

Seldaek commented Feb 7, 2024

Well have a look where pre-command-run is dispatched in BaseCommand, we could dispatch a post-command-run there as well IMO before returning?

@Seldaek Seldaek modified the milestones: 2.7, 2.8 Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants