1

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.

2
  • composer require (version)?
    – Kevin
    May 20, 2020 at 11:20
  • 2
    If you mean 'is there a way to automated this?' the answer is no. But you can follow the releases of the module and update when it's released. Note that by using a dev version though, it may at any given time be broken. That's how DEV works.
    – Jaypan
    May 20, 2020 at 14:19

1 Answer 1

4

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": {
            "<patch1 information>": "<patch1 file path>",
            "<patch2 information>": "<patch2 file path>"
        }
     }
}

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.