composer-patches
composer-patches copied to clipboard
Local patch could not be downloaded for dependencies
Preconditions:
- Package with a local patch file, for example:
composer.json{ "name": "example/patched-library", "description": "Example patched library", "version": "1.0.0", "require": { "composer/composer": "^1.9||^2.0", "cweagans/composer-patches": "^1.5.0" }, "extra": { "patches": { "composer/composer": { "Patch Composer dependency manager": "patches/composer.txt" } } } }patches/composer.txtdiff --git a/src/Composer/Repository/RepositoryFactory.php b/src/Composer/Repository/RepositoryFactory.php index 97a8ee9576ed..3a6de6f5c49f 100644 --- a/src/Composer/Repository/RepositoryFactory.php +++ b/src/Composer/Repository/RepositoryFactory.php @@ -132,6 +132,7 @@ public static function manager(IOInterface $io, Config $config, HttpDownloader $ $rm->setRepositoryClass('hg-bitbucket', 'Composer\Repository\VcsRepository'); $rm->setRepositoryClass('artifact', 'Composer\Repository\ArtifactRepository'); $rm->setRepositoryClass('path', 'Composer\Repository\PathRepository'); + // Test return $rm; } - Another package dependent on the patched library:
composer.json{ "name": "example/dependent-library", "description": "Example dependent library", "require": { "example/patched-library": "^1.0", "cweagans/composer-patches": "^1.5.0" }, "extra": { "enable-patching": true } }
Steps to reproduce:
- Install the patched library as standalone
- Install the patched library as a dependency
Actual result:
- Local patches do work perfectly for the standalone package installation:
Loading composer repositories with package information Updating dependencies Package operations: 19 installs, 0 updates, 0 removals - Installing cweagans/composer-patches (1.6.7): Loading from cache Gathering patches for root package. Gathering patches for dependencies. This might take a minute. - Installing symfony/process (v4.4.8): Loading from cache - Installing symfony/finder (v4.4.8): Loading from cache - Installing symfony/polyfill-ctype (v1.15.0): Loading from cache - Installing symfony/filesystem (v4.4.8): Loading from cache - Installing psr/container (1.0.0): Loading from cache - Installing symfony/service-contracts (v1.1.8): Loading from cache - Installing symfony/polyfill-php73 (v1.15.0): Loading from cache - Installing symfony/polyfill-mbstring (v1.15.0): Loading from cache - Installing symfony/console (v4.4.8): Loading from cache - Installing psr/log (1.1.3): Loading from cache - Installing seld/phar-utils (1.1.0): Loading from cache - Installing seld/jsonlint (1.8.0): Loading from cache - Installing justinrainbow/json-schema (5.2.9): Loading from cache - Installing composer/xdebug-handler (1.4.1): Loading from cache - Installing composer/spdx-licenses (1.5.3): Loading from cache - Installing composer/semver (1.5.1): Loading from cache - Installing composer/ca-bundle (1.2.7): Loading from cache - Installing composer/composer (1.10.6): Loading from cache - Applying patches for composer/composer patches/composer.txt (Patch Composer dependency manager) - Local patches cannot be downloaded for dependencies:
Loading composer repositories with package information Updating dependencies Package operations: 21 installs, 0 updates, 0 removals - Installing cweagans/composer-patches (1.6.7): Downloading (100%) No patches supplied. Gathering patches for dependencies. This might take a minute. - Installing psr/container (1.0.0): Downloading (100%) - Installing symfony/service-contracts (v2.0.1): Downloading (100%) - Installing symfony/process (v4.4.4): Downloading (100%) - Installing symfony/finder (v4.4.4): Downloading (100%) - Installing symfony/polyfill-ctype (v1.14.0): Downloading (100%) - Installing symfony/filesystem (v4.4.4): Downloading (100%) - Installing symfony/polyfill-php73 (v1.14.0): Downloading (100%) - Installing symfony/polyfill-mbstring (v1.14.0): Downloading (100%) - Installing symfony/console (v4.4.4): Downloading (100%) - Installing psr/log (1.1.2): Downloading (100%) - Installing composer/xdebug-handler (1.4.0): Downloading (100%) - Installing composer/semver (1.5.1): Downloading (100%) - Installing twig/twig (v3.0.3): Downloading (100%) - Installing seld/phar-utils (1.1.0): Downloading (100%) - Installing seld/jsonlint (1.7.2): Downloading (100%) - Installing justinrainbow/json-schema (5.2.9): Downloading (100%) - Installing composer/spdx-licenses (1.5.3): Downloading (100%) - Installing composer/ca-bundle (1.2.6): Downloading (100%) - Installing composer/composer (1.9.3): Downloading (100%) - Applying patches for composer/composer patches/composer.txt (Patch Composer dependency manager) Could not apply patch! Skipping. The error was: The "patches/composer.txt" file could not be downloaded: failed to open stream: No such file or directory - Installing example/patched-library (1.0.0): Downloading (100%)
I'm also having issues with applying a local path on my end. I tried different solutions based on #146 such as:
- Changing my file extension to
.patch.txt - Creating the patch with
--no-prefixflag - Changing the relative path in the patch file
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!
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.
@successmarket External patch URLs work perfectly fine for me. Only the local patch files do not.
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:
@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.
I have tested with that path and it didn't end up working for me. @sshymko let me know that solution worked for you!
@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.
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.
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
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
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).
Not sure what was going on here. main is a lot different now though.