Problem/Motivation

This is spun off from #3635625: Remove parts of Package Manager which tend to thwart site owners. In that issue, I railed against \Drupal\package_manager\Validator\ComposerPatchesValidator:

[It] does a lot of work because we don't trust that site owners know what they're doing. Developers are the only people who can apply patches. They can be trusted to configure the patcher plugin. If they have configured it, we can trust them to manage it. Package Manager's validation adds nothing but red tape.

I still think we should remove it, but in Slack, @catch asked for this piece to be made into its own issue so we can discuss and consider the removal more carefully.

Proposed resolution

Either remove ComposerPatchesValidator, or make it a simple StatusCheckEvent subscriber that warns if you have the patcher enabled.

Remaining tasks

TBD

User interface changes

TBD

Introduced terminology

None.

API changes

None anticipated. The validator is explicitly marked as internal.

Data model changes

None.

Release notes snippet

TBD

Comments

phenaproxima created an issue.

phenaproxima’s picture

As far as I know, the main argument in favor of keeping this validator is the fact that patches can break updates.

And that's absolutely true, but let's consider:

  • No matter how many patches you or your dependencies define, none of them mean anything unless cweagans/composer-patches is enabled at the root of the project. And that is true for Drupal CMS 2.3.0 and up, but not the core project template. We have since reverted that, so: neither core nor Drupal CMS trust the patches plugin by default.
  • Module and distribution maintainers should not be shipping patches under any circumstances (internal development is a different story), precisely because there's no way to guarantee how they will interact with the rest of the code that makes up a Drupal site. This should be documented as a bad practice. The only people who should be patching anything is site owners/developers -- the people who control the fully assembled code base.

In Slack, @bbrala did a quick search, ecosystem-wide, for "patches", and it's a lot:

184 composer.json files contain a "patches": { block, spread over well over 100 projects. A looser search for the word "patches" in composer.json matched 419 files, but that includes descriptions and other mentions, so I'm not using that number.
Who has them. The files with the most hits are distributions and project templates. Examples are rocketship_core, dropsolid_rocketship_profile, varbase_project, lightning_core, localgov_*, acquia_cms_* and sector. Single modules show up too, for example eca, views_field_formatter, media_library_media_modify, payment, bakery and babel.

To me, that makes the documentation problem urgent. People do this, and they shouldn't! Without guidance, people do the thing that gets them out of their current pickle, even if it's a bad idea long-term.

Granted, ComposerPatchesValidator isn't too problematic in and of itself; it doesn't validate the patches themselves, it just validates that the patches plugin is configured in a specific way. I could live with keeping it. But it's not Package Manager's job to be this prescriptive. Package Manager actually has no opinion on this beyond "a patch that doesn't apply, should cause a failed Composer operation". Which is already the case; the current, supported version of the patches plugin (2.x) will always crap out with an error if it encounters a patch it can't apply. Indeed, one of the settings the validator checks for (composer-exit-on-patch-failure) no longer even exists.

So that leaves us with a validator that is mostly useless, relying on a configuration option that doesn't exist, and neither helping or harming the ecosystem-wide problem of people shipping patches when they shouldn't.

It's cruft. Let's throw it out.