首页 > 解决方案 > Is it possible to tell Composer not to uninstall already installed dependencies when using the composer command?

问题描述

I am using https://github.com/tonix-tuft/grunt-hub-automator (a repo I have created on GitHub) which lets me set up a daemon which runs the following command whenever I change my composer.json or composer.lock file:

composer self-update && composer install --no-dev && composer update --lock

This way I can move across different branches and the daemon keeps the dependencies in vendor synchronized with composer.json.

However, if after adding new dependencies on new_branch I checkout old_branch which doesn't have those dependencies defined in composer.json because I have added them only on new_branch, the daemon fires the command and removes the dependencies on the old branch to keep everything in sync.

The problem of this approach is that if at that point I checkout again new_branch before the composer command has finished its work on old_branch (it's running in the background thanks to the daemon), I end up with an unsynced vendor folder because Composer is removing the dependencies as it thinks I am still on old_branch.

Is there a way to tell Composer not to remove already installed dependencies from vendor when they are not defined in composer.json?

Basically, I would like Composer to install missing dependencies or update those which are defined in composer.json every time composer.json changes without removing eventual dependencies which were already installed in vendor but now are not defined in composer.json anymore.

Is it possible?

I hope I was clear.

Thank you for your attention.

标签: phpcomposer-php

解决方案


推荐阅读