cweagans/composer-patches

Packages are getting deleted and not reinstalled since Composer 2.1.0

mstrelan opened this issue · 22 comments

Since Composer 2.1.0 when running composer install we're sometimes seeing packages that need patches getting deleted and not reinstalled.

$ composer install
Gathering patches from patch file.
Removing package drupal/redis so that it can be re-installed and re-patched.
  - Removing drupal/redis (1.5.0)
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Deleting app/modules/contrib/redis - deleted

Running composer install a second time resolves the issue.

$ composer install
Gathering patches from patch file.
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 1 install, 0 updates, 0 removals
Gathering patches from patch file.
Gathering patches for dependencies. This might take a minute.
  - Installing drupal/redis (1.5.0): Extracting archive
  - Applying patches for drupal/redis
...

Looks the only change in API is composer/composer@7dd95a7

Used to try composer 2.1.0 and 2.1.1 and can't reproduce the issue on few projects

rfay commented

I'm going to do another release of ddev today that will have 2.1.1, will be interested to hear if this problem has been fixed by 2.1.1.

I'm seeing the same, and I wonder if this is related to the use of a separate patch file (as opposed to an integrated patches section in composer.json).

I was able to reproduce the problem, but I needed to make a change to the composer.patches.json file to trigger it @andypost. It did exactly what the OP from @mstrelan

rfay commented

@joelpittet does it happen with composer 2.1.1 as well?

@rfay Yes, sorry should have mentioned I just composer selfupdate so I'm at 2.1.1

Confirmed this is a problem on 2.1.0, it may be mitigated by only being triggered with composer patches changes. I'll try to track down how far back this goes...

Worked fine in 2.0.12 and 2.0.14. I'm testing by making a change to a patch in composer.patches.json that I'm reverting over and over again :)
cs-ext

I feel like I'm doing manual git bisect 😅 2.1.0-RC1 fails too

OH: May be relevant but noticed there is a new reinstall command in 2.1.0 which may simplify things... https://getcomposer.org/doc/03-cli.md#reinstall

rfay commented

And... does composer 2.1.2 change anything? https://github.com/composer/composer/releases/tag/2.1.2

@rfay nope, still same problem. I'm scouring this for clues git diff 2.0.14..2.1.0-RC1

Still broken in 2.1.2. I can reproduce in a clean project.

michael@michael-XPS-15-9500:~$ composer --version
Composer version 2.1.2 2021-06-07 16:03:06
michael@michael-XPS-15-9500:~$ composer create-project drupal/recommended-project --quiet
michael@michael-XPS-15-9500:~$ cd recommended-project/

Apply the first patch:

michael@michael-XPS-15-9500:~/recommended-project$ composer require cweagans/composer-patches --quiet
michael@michael-XPS-15-9500:~/recommended-project$ echo '{"patches": {"drupal/password_policy": {"Prevent PHP warning in event subscriber": "https://www.drupal.org/files/issues/2019-07-02/3065248-3.patch"}}}' > composer.patches.json
michael@michael-XPS-15-9500:~/recommended-project$ composer config extra.patches-file composer.patches.json
michael@michael-XPS-15-9500:~/recommended-project$ composer require drupal/password_policy:^3@beta
./composer.json has been updated
Running composer update drupal/password_policy
Gathering patches from patch file.
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
  - Locking drupal/ctools (3.6.0)
  - Locking drupal/password_policy (3.0.0-beta1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
Gathering patches from patch file.
Gathering patches for dependencies. This might take a minute.
  - Installing drupal/ctools (3.6.0): Extracting archive
  - Installing drupal/password_policy (3.0.0-beta1): Extracting archive
  - Applying patches for drupal/password_policy
    https://www.drupal.org/files/issues/2019-07-02/3065248-3.patch (Prevent PHP warning in event subscriber)

Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Generating autoload files
38 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Apply a second patch, this is when it breaks:

michael@michael-XPS-15-9500:~/recommended-project$ echo '{"patches": {"drupal/password_policy": {"Prevent PHP warning in event subscriber": "https://www.drupal.org/files/issues/2019-07-02/3065248-3.patch","Field field_last_password_reset is unknown while importing configuration on site without password_policy activated": "https://www.drupal.org/files/issues/2020-03-20/password-policy-2771129-110.patch"}}}' > composer.patches.json
michael@michael-XPS-15-9500:~/recommended-project$ composer install
Gathering patches from patch file.
Removing package drupal/password_policy so that it can be re-installed and re-patched.
  - Removing drupal/password_policy (3.0.0-beta1)
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Deleting web/modules/contrib/password_policy - deleted
Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Generating autoload files
38 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
  * Homepage: https://www.drupal.org/project/drupal
  * Support:
    * docs: https://www.drupal.org/docs/user_guide/en/index.html
    * chat: https://www.drupal.org/node/314178

And finally running composer install again:

michael@michael-XPS-15-9500:~/recommended-project$ composer install
Gathering patches from patch file.
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 1 install, 0 updates, 0 removals
Gathering patches from patch file.
Gathering patches for dependencies. This might take a minute.
  - Installing drupal/password_policy (3.0.0-beta1): Extracting archive
  - Applying patches for drupal/password_policy
    https://www.drupal.org/files/issues/2019-07-02/3065248-3.patch (Prevent PHP warning in event subscriber)
    https://www.drupal.org/files/issues/2020-03-20/password-policy-2771129-110.patch (Field field_last_password_reset is unknown while importing configuration on site without password_policy activated)

Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Generating autoload files
38 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
  * Homepage: https://www.drupal.org/project/drupal
  * Support:
    * docs: https://www.drupal.org/docs/user_guide/en/index.html
    * chat: https://www.drupal.org/node/314178

I have the same issue, reproduced with 2.1.2 and worked fine with 2.0.14 composer/composer#9952

Composer maintainer here. I believe this was caused by composer/composer#9618 - and this plugin not handling the returned Promise instance correctly.

Indeed

$installationManager->uninstall($localRepository, $uninstallOperation);
does not handle the return value at all.

I opened #364 which I believe fixes this, would be great if someone affected can check.

Hi all, I have merged @Seldaek 's pull requests. If you could, please try dev-1.x in your projects and let me know if things are working properly again. I'm guessing these PRs cleared everything up and if that's the case, I can tag a new release today.

I have tested with cweagans/composer-patches:1.x-dev (couldn't find dev-1.x) and can confirm this works with the steps in #363 (comment).

1.x-dev fixed my issue (composer/composer#9952)

I have same problem despite having composer-patches 1.7.1 installed, along with Composer 2.1.9 & Drupal 8. In my case the message was slightly different:
Removing drupal/core (8.9.19)
Deleting web/core - not deleted
However, core apparently had been deleted, but then not reinstalled, so the site would not load.
Rolling back composer to 2.0.14 fixed the problem for now.

@en-cc-org This is a different problem and is fixed by updating composer/installers to at least 1.10: composer/installers@5006d0c