Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false-positive when determining if patcher (current package) is going to be uninstalled #101

Open
wants to merge 1 commit into
base: release/3
Choose a base branch
from

Conversation

enl
Copy link

@enl enl commented Aug 23, 2022

When a package that is really going to be deleted defines a "Vaimo" namespace in its PSR-4 autoload,
then vaimo/composer patches decides that it is going to be deleted and wipes out patches.

It happens because strpos("Vaimo\ComposerPatches", "Vaimo") indeed returns 0.

Steps to Reproduce

  1. Have a package that defines "Vaimo" as it's root namespace (I've encountered this issue having vaimo/phpcs-rulesets installed as a --dev dependency).
  2. Require it as a --dev dependency in a project that has vaimo/composer-patches installed as production dependency
  3. Run composer install --no-dev
  4. Observe your patches being wiped out.

…oing to be uninstalled

When a package that is really going to be deleted defines a "Vaimo" namespace in its PSR-4 autoload,
then vaimo/composer patches decides that it is going to be deleted and wipes out patches.

It happens because strpos("Vaimo\ComposerPatches", "Vaimo") indeed returns 0.
@enl enl force-pushed the fix/false-positive-is-patcher-uninstall branch from 9ef04b2 to e1afb03 Compare August 23, 2022 11:22
public function isPatcherUninstallOperation(OperationInterface $operation)
{
if (!$operation instanceof \Composer\DependencyResolver\Operation\UninstallOperation) {
return false;
}

return $this->configAnalyser->ownsNamespace($operation->getPackage(), __NAMESPACE__);
return \in_array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you looked at adding a test for this change?

Perhaps there is some existing test, which exercises this code, that could be the basis for an additional test to show that the "Vaimo namespace case" works as expected?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave up on figuring out how it is tested. It has too smart testing framework and close to no documentation on how to actually use it :(

@@ -15,6 +15,8 @@ class Plugin implements
\Composer\EventDispatcher\EventSubscriberInterface,
\Composer\Plugin\Capable
{
const COMPOSER_PACKAGE = 'vaimo/composer-patches';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of introducing random constants like that, is it possible to get this information out of composer API in a backward compatible way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not seem possible, because the addPlugin method does not pass anything about the $sourcePackage to the plugin's activate method.

I suggest just leaving this as is.

@vaimo-wilko
Copy link
Member

PR looks good to me. Continue with merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants