composer-patches icon indicating copy to clipboard operation
composer-patches copied to clipboard

Nested composer dependency patches don't patch in composer update

Open adam-delaney opened this issue 3 years ago • 3 comments

If you define a composer dependency and within that composer dependency you define a patch for another dependency, when running composer update I'm not seeing that project removed and re-added with a patch applied. Seems like if you update the package itself it willIs this expected behavior? App root composer.json

 "require": {
        "vendor/my-package": "^1.9",
}

Dependency vendor/my-package composer.json

"patches": {
      "drupal/project": {
        "My patch": "https://vendor.com/path-to-my-patch.patch"
      },
}

Run composer update.

I'd expect that drupal/project would be removed and re-installed to patch.

adam-delaney avatar Jun 21 '22 21:06 adam-delaney

I think this is a duplicate of https://github.com/cweagans/composer-patches/issues/376 but there's possibly an older issue tracking this too. It's kind of known that generally doing a composer update --lock after the first composer update will then trigger the patched dependency to be re-downloaded.

davereid-pfg avatar Jun 29 '22 17:06 davereid-pfg

After more investigation it seems that re-applying patches won't occur for nested composer dependencies that don't explicitly have an update even if the composer.lock file has been updated. It seems that vendor/composer/installed.json may be used to track what may need to be patched. Removing this file before running and update resolves this issue.

adam-delaney avatar Jul 08 '22 15:07 adam-delaney

Got the same issue. It seems like patches in the part specific to dependency in file vendor/composer/installed.json do not get updated at all. If you delete it or change its content to match your updated patches configuration, yes it works but it's not convenient...

Eventually I end up using vaimo/composer-patches instead which looks more versatile. If you still define your patches in composer.json of your dependency, you will get the same problem. You should use a separate patches.json file that composer.json will refer to (see docs). Every time you update your patches configuration, use the command composer patch:apply that will update installed.json itself :

"target/package": {
    "extra": {
        "patches_applied": {
            "my/package::::patches/my_patch.patch": "A very interesting title, md5:..."
        }
    },
}

furtivesock avatar Aug 31 '22 13:08 furtivesock

main doesn't resolve patches from dependencies anymore.

cweagans avatar Feb 07 '23 22:02 cweagans

main doesn't resolve patches from dependencies anymore.

Can you clarify this comment? Does this mean that, in a future relase, all patches must be defined in the root composer.json file? Can you point to the documentation about the rationale for this change? (I looked and wasn't able to find it.)

markfullmer avatar Feb 20 '23 18:02 markfullmer

main doesn't resolve patches from dependencies anymore.

Yeah this is not expected behavior from a laymans perspective. Can you elaborate if this is intended behavior or just a current gap in the featureset?

nicksantamaria avatar Mar 02 '23 22:03 nicksantamaria

I removed it intentionally at the time. Please see https://github.com/cweagans/composer-patches/discussions/478 for further info.

cweagans avatar Mar 03 '23 20:03 cweagans