Composer: require dev branch then go back to stable once current dev is stable Let's say you need a patch in a Drupal module (or core) only included in the dev version yet.

It's already commited and should normaly be included in the next stable release. 

So I'd like composer to grab the dev version for now but switch back to stable as soon as the next release is out.

If I do this for ex.: 

composer require drupal/bootstrap:3.x-dev


It'll continue to update to the dev version even after the patch I need is included to stable, wich I'd like to avoid...

Is there a way to achive this ?

For ex. a way to tell composer "I want a version of this module that has to include that commit be it dev or stable, but I'd prefere stable if available".

So I can patch my module and forget about it.
You should better use a patch.

You will ask composer to download and install the required patch on top of the current stable release. 

Once the patch will be inside the stable release, the patch won't be applied anymore (a patch is basically a diff file, so when there's no diff, there's not patch)

Install https://github.com/cweagans/composer-patches this is a dependencies that will allow to use a section in the composer.json to declare the patch. It will install it automatically. 

composer require cweagans/composer-patches

Then add an extra section in your composer.json

"extra": {
    "enable-patching": true,
    "patches": {
        "drupal/module_to_be_patched": {
            "&lt;patch1 information&gt;": "&lt;patch1 file path&gt;",
            "&lt;patch2 information&gt;": "&lt;patch2 file path&gt;"
        }
     }
}


You will find the patch file path on the module tracker, on the repository of the module, for an issue

For exemple, successive patches for a drupal/webform issue : https://www.drupal.org/project/webform/issues/3137981

Then simply 

composer install


You will see the patch is being installed right in your terminal.

Reference : https://groups.drupal.org/node/518975

Patching : https://www.drupal.org/patch/apply