Remove the cweagans/composer-patches patch to prevent whole /web dir might get deleted
Currently there are two ways to lose /web directory completely:
Apply a patch to Drupal core
We have this code: https://github.com/drupal-composer/drupal-project/blob/339c81dcfd6881f3f3e1069b8ab3fe4149094e6b/composer.json#L76-L80 It tries to solve the issue described in https://github.com/drupal-composer/preserve-paths/issues/10
However, this does not work. Explained here: https://github.com/drupal-composer/preserve-paths/issues/10#issuecomment-468614704
Moreover, current setup is pretty confusing and it can lead to not nice situations. For example, this could happen:
- A D7 project was migrated to drupal-composer/drupal-project
- The patch was applied nicely to cweagans/composer-patches package
- During deployment, the patch was not applied to the production installation
- Later, a developer applied a patch to Drupal core locally (and this worked fine because the composer-patches patch was applied on the developer's installation)
- The /web directory was vanished on production during the deployment
Proposed solution:
- remove the current patch
- make a fork of cweagans/composer-patches with the patch applied
- use the fork in drupal-composer/drupal-project
~If composer-exit-on-patch-failure is true, and there is an issue with applying a Drupal core patch~
composer-exit-on-patch-failure is not part of the composer.json in the 7.x branch
I'm not sure if a fork of cweagans/composer-patches just to apply this patch is the best solution.
I think that forcing the patching of that package somehow in the post-create-project-cmd step or maybe also in the pre-install-cmd and pre-update-cmd steps, would be a way more maintainable solution.
Also note that composer-exit-on-patch-failure is not part of the composer.json in the 7.x branch.
forcing the patching of that package somehow in the post-create-project-cmd step or maybe also in the pre-install-cmd and pre-update-cmd steps
I know only these ways to patch a package:
- change "patches" section in composer.json
- remove and re-add the package
Both are not usable for composer pre/post commands.
Maybe @cweagans know other ways?
Yes, this would not be done the 'normal' way... It would be a direct call for composer-patches to patch itself. It would probably require some custom PHP code, but most likely it should not be too complicated.
The question is whether that code should be on this project or in composer-patches.. It is somewhat a bug in that package that it is unable to apply a patch to itself on the first install.
Just for reference the discussion on this is going on at https://github.com/cweagans/composer-patches/issues/42
We created this for D7 projects: https://github.com/druidfi/mona-plugin
See how it's used in: https://github.com/druidfi/mona/blob/master/composer.json
Existing D7 site that 6 months ago was converted to Composer. During composer install --no-dev we lost all files in web directory.
Not sure how we make sure this not happen again and I am not able to re-create this in dev.
- Composer version 2.2.13
- PHP 7.1.33
- Drupal 7.89 => 7.90 core upgrade
"patches": {
"cweagans/composer-patches": {
"Call the preserve paths hooks" : "https://github.com/jcnventura/composer-patches/compare/1.x...jcnventura:fix-preserve-paths.diff"
}
},
"preserve-paths": [
"web/sites"
]
I reported an issue with meta packages and overlapping preserve paths like this in https://github.com/drupal-composer/preserve-paths/issues/42 . If the composer patches patch didn’t fix the issue it’s likely this issue instead