cweagans / composer-patches

Simple patches plugin for Composer
https://www.cweagans.net/project/composer-patches
BSD 3-Clause "New" or "Revised" License
1.53k stars 240 forks source link

Command patches-relock does not exclude patches from ignore-dependency-patches #596

Closed GoZOo closed 1 month ago

GoZOo commented 1 month ago

Verification

What were you trying to do (and why)?

To understand : Machine cannot access to web, so cannot download patches. Patches are downloaded manually and stored in local. A package (drupal/ui_styles) embed patch url in its composer.json, so I ignore this module with ignore-dependency-patches. I download manually this patch and define it in patches. During composer install, everything is fine, patch apply and i have no curl error (composer does not try to download patch from composer.json package).

What's wrong I previously had a patch named 14.patch for module default_content. I rename it to default_content--2698425-14.patch to be more relevant. File patches.lock.json is still referencing 14.patch.

I try to update patches.lock.json with composer patches-relock, but command fails because it tries to download patch defined by composer.json in sabberworm/php-css-parser package, even if it's marked as ignored.

What happened? What did you expect to happen?

composer patches-relock
dgfip Detected drupal major version: 10
  - Resolving patches from root package.
  - Resolving patches from dependencies.
[08-Oct-2024 08:16:38 UTC] Unhandled promise rejection with Composer\Downloader\TransportException: curl error 6 while downloading https://www.drupal.org/files/issues/2024-08-08/sabberworm-php-css-parser-202.patch: Could not resolve host: www.drupal.org in /home/www-data/.composer/vendor/composer/composer/src/Composer/Util/Http/CurlDownloader.php:371
Stack trace:
#0 /home/www-data/.composer/vendor/composer/composer/src/Composer/Util/HttpDownloader.php(392): Composer\Util\Http\CurlDownloader->tick()
#1 /home/www-data/.composer/vendor/composer/composer/src/Composer/Util/HttpDownloader.php(363): Composer\Util\HttpDownloader->countActiveJobs()
#2 /home/www-data/.composer/vendor/composer/composer/src/Composer/Util/HttpDownloader.php(157): Composer\Util\HttpDownloader->wait()
#3 /var/www/html/vendor/cweagans/composer-patches/src/Downloader/ComposerDownloader.php(32): Composer\Util\HttpDownloader->copy()
#4 /var/www/html/vendor/cweagans/composer-patches/src/Downloader.php(65): cweagans\Composer\Downloader\ComposerDownloader->download()
#5 /var/www/html/vendor/cweagans/composer-patches/src/Plugin/Patches.php(247): cweagans\Composer\Downloader->downloadPatch()
#6 /var/www/html/vendor/cweagans/composer-patches/src/Plugin/Patches.php(210): cweagans\Composer\Plugin\Patches->download()
#7 /var/www/html/vendor/cweagans/composer-patches/src/Command/RelockCommand.php(31): cweagans\Composer\Plugin\Patches->createNewPatchesLock()
#8 /home/www-data/.composer/vendor/symfony/console/Command/Command.php(326): cweagans\Composer\Command\RelockCommand->execute()
#9 /home/www-data/.composer/vendor/symfony/console/Application.php(1078): Symfony\Component\Console\Command\Command->run()
#10 /home/www-data/.composer/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#11 /home/www-data/.composer/vendor/composer/composer/src/Composer/Console/Application.php(394): Symfony\Component\Console\Application->doRun()
#12 /home/www-data/.composer/vendor/symfony/console/Application.php(175): Composer\Console\Application->doRun()
#13 /home/www-data/.composer/vendor/composer/composer/src/Composer/Console/Application.php(148): Symfony\Component\Console\Application->run()
#14 /home/www-data/.composer/vendor/composer/composer/bin/composer(94): Composer\Console\Application->run()
#15 /home/www-data/.composer/vendor/bin/composer(119): include('...')
#16 {main}

I expect that patches-relock command take care of ignore-dependency-patches config in composer.json and does not try to download patches definied in the composer.json of listed packaged, but still apply local patches defined in the main composer.json.

Full contents of composer.json

{
    "name": "drupal/starterkit",
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": ">=8.2",
        "cweagans/composer-patches": "^2.0",
        "drupal/core-composer-scaffold": "^10",
        "drupal/core-recommended": "^10",
        "drupal/default_content": "^2",
        "drupal/ui_patterns_field_formatters": "^2.0",
        "drupal/ui_patterns_layout_builder": "^1.2",
        "drupal/ui_patterns_settings": "^2.2@alpha",
        "sabberworm/php-css-parser": "^8.6"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "optimize-autoloader": true,
        "sort-packages": true,
        "preferred-install": {
            "*": "dist"
        },
        "discard-changes": true,
        "platform": {
            "php": "8.2"
        }
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "autoload": {
        "psr-4": {
            "PHPStan\\": "deps/phpstan-junit/src/"
        }
    },
    "extra": {
        "dgfip": {
            "ignore-verifications": false,
            "ignore-safe-composer-autocompletion": false
        },
        "phpstan/extension-installer": {
          "ignore": [
            "composer/composer",
            "phpstan/phpstan-deprecation-rules",
            "mglaman/phpstan-drupal",
            "phpstan/phpstan-phpunit"
          ]
        },
        "installer-types": [
            "drupal-library-plugin-ckeditor",
            "npm-asset",
            "bower-asset",
            "bower-asset-library",
            "npm-asset-library",
            "drupal-library"
        ],
        "installer-paths": {
            "web/core": [
                "type:drupal-core"
            ],
            "web/libraries/ckeditor/plugins/{$name}": [
                "vendor:ckeditor-plugin"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "web/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ],
            "web/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "web/libraries/dsfr": [
                "npm-asset/gouvfr--dsfr"
            ],
            "web/libraries/{$name}": [
                "type:drupal-library",
                "vendor:npm-asset",
                "vendor:bower-asset",
                "type:npm-asset",
                "type:bower-asset"
            ]
        },
        "drupal-scaffold": {
            "locations": {
                "web-root": "./web/"
            },
            "file-mapping": {
                "[project-root]/.editorconfig": false,
                "[project-root]/.gitattributes": false,
                "[web-root]/example.gitignore": false,
                "[web-root]/INSTALL.txt": false,
                "[web-root]/README.txt": false,
                "[web-root]/README.md": false,
                "[web-root]/update.php": false,
                "[web-root]/web.config": false,
                "[web-root]/sites/README.txt": false,
                "[web-root]/sites/development.services.yml": false,
                "[web-root]/sites/example.settings.local.php": false,
                "[web-root]/modules/README.txt": false,
                "[web-root]/profiles/README.txt": false,
                "[web-root]/themes/README.txt": false
            }
        },
        "composer-exit-on-patch-failure": true,
        "ignore-dependency-patches": [
            "drupal/ui_styles"
        ],
        "patches": {
            "drupal/default_content": {
                "https://www.drupal.org/project/default_content/issues/2698425": "patch/default_content--2698425-14.patch"
            },
            "sabberworm/php-css-parser": {
                "1 - Fix/css4 rgb parsing - https://www.drupal.org/project/ui_styles/issues/3453784#comment-15719087": "patch/ui_styles--sabberworm-php-css-parser-202.patch"
            }
        }
    }
}

Full contents of patches.lock.json

{
    "_hash": "49ffe03d0d9faf5a738942ded49addf59d52a7dda83d46fe94c94d32fc1bea48",
    "patches": {
        "drupal/default_content": [
            {
                "package": "drupal/default_content",
                "description": "https://www.drupal.org/project/default_content/issues/2698425",
                "url": "patch/14.patch",
                "sha256": "be750858286c09c472f71f1d7c22cc7a4f86de0a5f1efdb6722ae97ac2b2461c",
                "depth": 1,
                "extra": {
                    "provenance": "root"
                }
            }
        ],
        "sabberworm/php-css-parser": [
            {
                "package": "sabberworm/php-css-parser",
                "description": "1 - Fix/css4 rgb parsing - https://www.drupal.org/project/ui_styles/issues/3453784#comment-15719087",
                "url": "patch/ui_styles--sabberworm-php-css-parser-202.patch",
                "sha256": "1b5e64505d109281dbf54ca9e4c4ad2d198398885f6009bb1c713f4c0b9a9772",
                "depth": 1,
                "extra": {
                    "provenance": "root"
                }
            }
        ]
    }
}

Full output of composer patches-doctor

System information
================================================================================
Composer version:                                                          2.7.7
PHP version:                                                              8.2.21

Available patchers
================================================================================
cweagans\Composer\Patcher\GitPatcher usable:                                 yes
cweagans\Composer\Patcher\GitInitPatcher usable:                             yes
cweagans\Composer\Patcher\FreeformPatcher usable:                            yes
Has usable patchers:                                                         yes

Common configuration issues
================================================================================
has plain http patch URLs:                                                    no

Full output of relevant Composer command with the -vvv flag added

Running 2.7.7 (2024-06-10 22:11:12) with PHP 8.2.21 on Linux / 5.4.0-146-generic
  - Resolving patches from root package.
    Using compact definition format for package drupal/default_content
    Using compact definition format for package sabberworm/php-css-parser
Reading ./composer.lock (/var/www/html/composer.lock)
  - Resolving patches from dependencies.
    Using compact definition format for package sabberworm/php-css-parser
Reading patch/default_content--2698425-14.patch
Reading patch/ui_styles--sabberworm-php-css-parser-202.patch
Downloading https://www.drupal.org/files/issues/2024-08-08/sabberworm-php-css-parser-202.patch
Retrying (1) https://www.drupal.org/files/issues/2024-08-08/sabberworm-php-css-parser-202.patch due to curl error 6
Retrying (2) https://www.drupal.org/files/issues/2024-08-08/sabberworm-php-css-parser-202.patch due to curl error 6
Retrying (3) https://www.drupal.org/files/issues/2024-08-08/sabberworm-php-css-parser-202.patch due to curl error 6
[08-Oct-2024 08:26:43 UTC] Unhandled promise rejection with Composer\Downloader\TransportException: curl error 6 while downloading https://www.drupal.org/files/issues/2024-08-08/sabberworm-php-css-parser-202.patch: Could not resolve host: www.drupal.org in /home/www-data/.composer/vendor/composer/composer/src/Composer/Util/Http/CurlDownloader.php:371
Stack trace:
#0 /home/www-data/.composer/vendor/composer/composer/src/Composer/Util/HttpDownloader.php(392): Composer\Util\Http\CurlDownloader->tick()
#1 /home/www-data/.composer/vendor/composer/composer/src/Composer/Util/HttpDownloader.php(363): Composer\Util\HttpDownloader->countActiveJobs()
#2 /home/www-data/.composer/vendor/composer/composer/src/Composer/Util/HttpDownloader.php(157): Composer\Util\HttpDownloader->wait()
#3 /var/www/html/vendor/cweagans/composer-patches/src/Downloader/ComposerDownloader.php(32): Composer\Util\HttpDownloader->copy()
#4 /var/www/html/vendor/cweagans/composer-patches/src/Downloader.php(65): cweagans\Composer\Downloader\ComposerDownloader->download()
#5 /var/www/html/vendor/cweagans/composer-patches/src/Plugin/Patches.php(247): cweagans\Composer\Downloader->downloadPatch()
#6 /var/www/html/vendor/cweagans/composer-patches/src/Plugin/Patches.php(210): cweagans\Composer\Plugin\Patches->download()
#7 /var/www/html/vendor/cweagans/composer-patches/src/Command/RelockCommand.php(31): cweagans\Composer\Plugin\Patches->createNewPatchesLock()
#8 /home/www-data/.composer/vendor/symfony/console/Command/Command.php(326): cweagans\Composer\Command\RelockCommand->execute()
#9 /home/www-data/.composer/vendor/symfony/console/Application.php(1078): Symfony\Component\Console\Command\Command->run()
#10 /home/www-data/.composer/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#11 /home/www-data/.composer/vendor/composer/composer/src/Composer/Console/Application.php(394): Symfony\Component\Console\Application->doRun()
#12 /home/www-data/.composer/vendor/symfony/console/Application.php(175): Composer\Console\Application->doRun()
#13 /home/www-data/.composer/vendor/composer/composer/src/Composer/Console/Application.php(148): Symfony\Component\Console\Application->run()
#14 /home/www-data/.composer/vendor/composer/composer/bin/composer(94): Composer\Console\Application->run()
#15 /home/www-data/.composer/vendor/bin/composer(119): include('...')
#16 {main}
GoZOo commented 1 month ago

My bad, declaration of ignore-dependency-patches is wrong.

Here is the good one found on https://docs.cweagans.net/composer-patches/usage/configuration/ :

`{

[...],

"extra": {

    "composer-patches": {

        "ignore-dependency-patches": [

            "some/package",

        ]

    }

}

}`