wikimedia / composer-merge-plugin

Merge one or more additional composer.json files at Composer runtime
MIT License
934 stars 159 forks source link

Double execution of script in post-update-cmd on first install #145

Closed batopa closed 7 years ago

batopa commented 7 years ago

In my scripts section of composer.json I hook two scripts to execute on first installation and on next updates.

{
    "scripts": {
        "post-update-cmd": "BEdita\\App\\Console\\Installer::postInstall"
    }
}

Before using composer-merge-plugin the script run one time on first composer install (no composer.lock present) and one time on next composer update command.

After required composer-merge-plugin I have an issue on first install (no composer.lock present). The script in post-update-cmd is executed two times but from composer doc it appears a wrong behavior:

post-update-cmd: occurs after the update command has been executed, or after the install command has been executed without a lock file present.

Here the console output

> BEdita\App\Console\Installer::postInstall
Set Folder Permissions ? (Default to Y) [Y,n]? No Security.salt placeholder to replace.
> BEdita\App\Console\Installer::postInstall
Set Folder Permissions ? (Default to Y) [Y,n]? 
No Security.salt placeholder to replace.

Another strange behavior is that after the first question (Set Folder Permissions ? (Default to Y) [Y,n]?) the process go ahead without waiting the answer while the secont time it stops rightly.

On next composer update command all seems right.

bd808 commented 7 years ago

Two firings of the post-update-cmd event on initial install is expected behavior. Composer-merge-plugin detects when it is initially installed and triggers a installer run. This is done so that the end state of the vendor directory reflects the composer-merge-plugin configuration for the deployment. If we did not do this, composer-merge-plugin would only be effective on a second manual run of composer install or composer update.

dynasource commented 7 years ago

@bd808, do those 2 firings also apply for post-install-cmd? I'm trying to figure out why all of the scripts in the composer scripts section are executed twice. This does not seem logical to be an expected behavior.

bd808 commented 7 years ago

do those 2 firings also apply for post-install-cmd?

It can happen for either update and install. The condition that causes this is the installation of the composer-merge-plugin library itself into the vendor repo and subsequent initialization by Composer. When composer-merge-plugin thinks that it has been installed for the first time it will cause a second install/update run of Composer so that it can have a chance to modify the dependency information that Composer uses to determine which packages to install. This "double run" should only happen when the plugin is first added to vendor.