cweagans / composer-patches

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

Local patch could not be downloaded for dependencies #315

Closed sshymko closed 1 year ago

sshymko commented 4 years ago

Preconditions:

Steps to reproduce:

  1. Install the patched library as standalone
  2. Install the patched library as a dependency

Actual result:

jennyychaa commented 4 years ago

I'm also having issues with applying a local path on my end. I tried different solutions based on #146 such as:

I am able to apply the patch successfully using git but unsuccessfully with composer. Here are my files as well: photoswipe-200527.patch

diff --git ./webroot/modules/contrib/photoswipe/js/photoswipe.jquery.js ./webroot/modules/contrib/photoswipe/js/photoswipe.jquery.js
index cdb4dff..167728f 100644
--- ./webroot/modules/contrib/photoswipe/js/photoswipe.jquery.js
+++ ./webroot/modules/contrib/photoswipe/js/photoswipe.jquery.js
@@ -14,17 +14,11 @@
     attach: function (context, settings) {
       this.photoSwipeOptions = settings.photoswipe ? settings.photoswipe.options : {};

-      // First ensure all photoswipe photos are in a photoswipe-gallery wrapper:
-      var $imagesWithoutGalleries = $('a.photoswipe', context).filter(function (elem) {
-        return !$(this).parents('.photoswipe-gallery').length;
-      });
-      if ($imagesWithoutGalleries.length) {
-        // We have no galleries just individual images.
-        $imagesWithoutGalleries.each(function (index) {
-          $imageLink = $(this);
-          // Add the wrapper and indicate that it's an automatic fallback:
-          $imageLink.wrap('<span class="photoswipe-gallery photoswipe-gallery--fallback-wrapper"></span>');
-        });
+      // Wrap all photo gallery photos with a photoswipe-gallery wrapper
+      var $photoGallery = $('.photo-gallery__images', context);
+
+      if($photoGallery.parents('.photoswipe-gallery').length < 1) {
+        $photoGallery.wrap('<span class="photoswipe-gallery photoswipe-gallery--fallback-wrapper"></span>');
       }

       var $galleries = $('.photoswipe-gallery', context);
@@ -96,7 +90,7 @@
             src: $image.attr('href'),
             w: size[0],
             h: size[1],
-            title: $image.data('overlay-title'),
+            title: $image.data('overlay-title').replace('Caption', ''),
             msrc: $image.find('img').attr('src')
           }
         );
@@ -122,7 +116,7 @@
         return { x: tpos.left, y: tpos.top, w: tw };
       }

-      // Ensures we have items (.photoswipe element) before initializing 
+      // Ensures we have items (.photoswipe element) before initializing
       // PhotoSwipe so to make PhotoSwipe get along with Blazy, Slick, etc.
       if (items.length > 0) {
         // Pass data to PhotoSwipe and initialize it
@@ -169,4 +163,4 @@
       return params;
     }
   };
-})(jQuery, Drupal, PhotoSwipe, PhotoSwipeUI_Default);
+})(jQuery, Drupal, PhotoSwipe, PhotoSwipeUI_Default);

composer.json

"patches": {
            "drupal/paragraphs": {
                "Integrity constraint violation: 1048 Column 'langcode' cannot be null": "https://www.drupal.org/files/issues/2019-08-10/paragraphs-set_langcode_widgets-290139_updated.patch"
            },
            "drupal/photoswipe": {
                "Wrapping photoswipe-gallery div around entire collection of images and removing caption label in the text": "patches/photoswipe-200527.patch"
            }
        }

I could use all the help I can get. Please and thank you!

successmarket commented 4 years ago

I'm having the same issue too. Tried all the same fixes, also including putting the file on the web and providing a full url to it.

sshymko commented 4 years ago

@successmarket External patch URLs work perfectly fine for me. Only the local patch files do not.

cweagans commented 4 years ago

What if you prefix the patch path like so: ./patches/composer.txt ? It's entirely possible that this is broken -- we rely on the Composer RemoteFilesystem class to download the patches. Maybe they changed RemoteFilesystem so that it only works on remote filesystems :-1:

sshymko commented 4 years ago

@cweagans (Haven't tested ./patches path yet; will try to find time to test this shortly and report back). Looks like the issue is with the directory relative to which the file path is being resolved. The patch file is found no problem for standalone package install, but not when it's a dependency.

jennyychaa commented 4 years ago

I have tested with that path and it didn't end up working for me. @sshymko let me know that solution worked for you!

successmarket commented 4 years ago

@cweagans I have tested with ./ in the composer patches extra, I have played around with a/ b/ ./ ./ or nothing at the beginning of my diff paths... nothing is working, local or web.

I will keep trying today and try to find a solution, or at least, pinpoint where it fails.

successmarket commented 4 years ago

For people following, make sure that you have the "patch" cli command installed properly on the system you are running your composer command. Also, add --verbose to have proper error messages after that. Hope this helps.

emudojo commented 4 years ago

was getting an error before, realized patch was not installed, using the -vv flag helps a lot, so yeah for me local patching works using ./path/file.patch

danlobo02 commented 4 years ago

I had a similar issue rolling a local composer patch.

Eventually I figured out that the preferred-install needs to be set to source.for the patched e.g.

"config": { "preferred-install": { "{org][package]": "source" } }

Not sure if this is documented anywhwre

maxstarkenburg commented 3 years ago

I've also run into this when trying to add a patch file to a dependency package, in my case the dependency package being a custom Drupal profile (let's call it my_account/my_profile). When I set its composer.json with the following:

        "patches": {
            "some_vendor/some_package": {
              "My patch description": "patches/my-change.patch"
            }
        }

I get that The "patches/my-change.patch" file could not be downloaded: failed to open stream: No such file or directory message when trying run composer update my_account/my_profile from the site root package that's requiring it. Same with using "./patches/my-change.patch". However, if I change the above with the following:

-              "My patch description": "patches/my-change.patch"
+              "My patch description": "web/profiles/my_profile/patches/my-change.patch"

(based on where I know the site root is installing my_profile), then the patch file in the dependency gets successfully applied. So it doesn't necessarily have to be external/remote.

But this workaround only works as long as I never update "web/profiles/{$name}" in my site root's installer-paths (or remember to update my_account/my_profile and all the sites that require it).

cweagans commented 1 year ago

Not sure what was going on here. main is a lot different now though.