Problem/Motivation
Disclaimer: Not sure that is the right project to post this.
- Add a module as dist (using a stable, beta, alpha version) in your composer.json.
- Create a patch that fixes the .info.yml file.
- Add the patch in composer.json and update.
In most of the cases the paching will fail because the content of the dist .info.yml contains also the packager script lines. The patch is build every time using the source, where those lines doesn't exist.
Proposed resolution
The .info.yml file is part of the codebase, it should not be altered by any script.
Long term solution
Move these package info in their own file that should be added by the the packager script, as LICENSE.txt is added.
Quick fix
Before the line # Information added by Drupal.org packaging script on ... add enough empty lines, so that the changed hunk doesn't interfere. Will still be a problem with the .info.yml files of sub-modules being deleted.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Comments
Comment #2
dwwGood issue, hard to classify. There's been talk of this before, but I don't remember exactly where.
The quick fix would be a feature request for https://www.drupal.org/project/issues/drupalorg
The long term fix would need changes both on the d.o side and in core itself (since core would have to know to look in *.version.yml (or whatever) for the version info, instead of looking in *.info.yml).
Adding a bunch of related issues that are high priority for D9 that would be touching very similar code.
How exactly you wish to navigate all this complexity with this particular issue is up to you. Maybe make it a META plan and open sub issues in the various places for the various short vs. long term aspects?
Good luck!
-Derek
Comment #4
claudiu.cristea@dww, thank you. I've opened #3066468: Packaging info from .info.yml often creates conflicts when patching (ddo).
Comment #5
drummDoes composer patches have a way to specify
-C<n>to reduce or remove the required context match?As dww said:
We can’t just remove the data and break update module.
Comment #7
adamzimmermann commentedI ran into this issue recently. Was great to see this issue and that others are aware of this and thinking about it.
https://www.drupal.org/project/publication_date/issues/2983348#comment-1...
Comment #9
andrewmacpherson commentedRe. #5:
No, it doesn't.
It tries two different methods of patching. For projects which have a
.gitdirectory (because of--prefer-source, or whatever) it attempts to apply the patch using git. The relevant line is in\cweagans\Composer\Patches::applyPatchWithGit():$patched = $this->executeCommand('git -C %s apply %s %s', $install_path, $patch_level, $filename);For projects which don't have a
.gitdirectory, it falls back to apatchcommand:These are from the 1.6.7 release of cweagans/composer-patches.
Comment #10
damienmckennaAt a certain point it might be worth switching to https://github.com/vaimo/composer-patches instead of cweagans/composer-patches as vaimo's version has more options available.
Disclaimer: I haven't tested vaimo/composer-patches yet, but the docs suggest it might help.
Comment #11
adamzimmermann commentedI documented the solution that I used as a short term work-around. Hopefully this helps others while we decide on a long-term solution.
https://chromatichq.com/blog/patching-info-files-composer
Comment #13
gaëlg@adamzimmermann, great tip, thanks!
Comment #14
pieterdt commentedindeed, great tip in #11! much appreciated you took the time to document a workaround!
Comment #15
roy84 commentedHad a hard time patching a module.info file...
#11 worked! Thanks for that!
Is there any option to work with a version.info file, to keep clean module.info files?
Comment #20
orakili commentedI encountered this issue when trying to add modules that are not yet compatible with Drupal 10 but have a compatibility patch.
I created this tiny composer plugin https://packagist.org/packages/orakili/composer-drupal-info-file-patch-h... as a companion of https://packagist.org/packages/cweagans/composer-patches that registers to the patch events provided by this plugin and removes the data added to the `info.yml` by the Drupal packaging script before patching and add it back after the patch.
I'm using that together with https://packagist.org/packages/mglaman/composer-drupal-lenient to install D9 modules and apply their D10 compatibility patch, on D10 sites.
Comment #21
matsbla commentedI also have problems to update my sites to D10, there are patches ready to be applied, but am unable to patch my modules using composer. I think this issue should be escalated to major, as it makes it difficult to update sites to next drupal version.
Comment #22
edmund.dunn commented@orakili package in #22 works well. I tried the patcher from vaimo, but it wasn't applying all of the patches cleanly.
Comment #24
rasikap commented@orakili, the package does work but not for all modules. I tried patching sfweb2lead_webform but it fails.
Comment #25
watergate commented@orakili, thanks for the Composer plugin. It helped me/us a lot!