0
votes

I have this simple composer.json file. When I run "composer install" I expect it to run post-install-cmd script but nothing happens. If I change it to post-update-cmd it works as expected. Am i missing something? Doesn't it have to run post-install-cmd instead of post-update-cmd?

{
    "name": "vendorName/packageName",
    "description": "Some description",
    "type": "library",
    "require": {
        "psr/log": "^1.1"
    },
    "scripts": {
        "post-install-cmd": "$SHELL script.sh"
    }
}
1
post-install-cmd: occurs after the install command has been executed with a lock file present. Do you have a .lock file? - Felippe Duarte
It doesn't exist the first time I run "composer install". I'm using "composer init" to create composer.json file. I answered no to the question "Would you like to install dependencies now? And because of that I have no composer.lock file until I issue "composer install". Thanks for the hint. - mrdolichenus

1 Answers

1
votes

The (pre|post)-update-cmd is invoked when running composer install if you don't have a lock-file (composer.lock) in your project's root directory.

The composer install command is meant to install the dependencies in the lock-file.

If there is no composer.lock it will run composer update internally to resolve the dependencies and generate the lock-file for you.

From the documentation of the install command:

If there is no composer.lock file, Composer will create one after dependency resolution.