composer-bin-plugin icon indicating copy to clipboard operation
composer-bin-plugin copied to clipboard

Detect installation via this plugin

Open ondrejmirtes opened this issue 4 years ago • 8 comments

Hello, is it possible to reliably detect from inside a library that it was installed in a special way through this plugin and not as a normal require-dev dependency? Thank you.

ondrejmirtes avatar Oct 23 '21 10:10 ondrejmirtes

Hi, at the moment I don't think so. Maybe it would be possible by adding an environment variable before executing the installation?

theofidry avatar Nov 02 '21 09:11 theofidry

Coming back to this: is there any reason for this? Because such a library would not be any different from another. It just comes from a different directory but it's not installed in a special way

theofidry avatar Jan 13 '22 09:01 theofidry

What I need to detect is this situation:

vendor/
    // Symfony 6 instaled here
vendor-bin/
   // PHPStan installed here
   // Symfony 4 installed here because of another dependency

Because people sometimes install PHPStan like this even if there's no othe reason, and because PHPStan looks around its vendor directory to see the dependencies used in the analysed project, with this structure it will think the project uses Symfony 4 and not Symfony 6.

Do you have any tips for me? :)

ondrejmirtes avatar Jan 13 '22 09:01 ondrejmirtes

PHPStan looks around its vendor directory to see the dependencies used in the analysed project

Is it a behaviour specific to when PHPStan is installed as a package instead of being used as a PHAR?

theofidry avatar Jan 13 '22 10:01 theofidry

PHPStan is installed as a package in vendor-bin. PHPStan is always distributed as PHAR, even in the phpstan/phpstan package.

ondrejmirtes avatar Jan 13 '22 10:01 ondrejmirtes

would providing an environment variable be enough here?

theofidry avatar Jul 08 '22 07:07 theofidry

Erratum actually that would not work since what you want is to check afterwards.

I think in 99.99% of the cases, you can check for the path (root/vendor-bin/namespaceName/{vendor, composer.json, composer.lock}).

There is a chance someones changes the path via https://github.com/bamarni/composer-bin-plugin#change-directory, but honestly not sure what you can do here...

If you have any idea I'm open to it though.

theofidry avatar Jul 10 '22 17:07 theofidry

When "bin-installed" by bamarni/composer-bin-plugin the parent directory of the current bin/ (thus the "non-bin" vendor directory) has no phpstan/phpstan subdirectory.

szepeviktor avatar Jul 10 '22 22:07 szepeviktor

@ondrejmirtes is working out via the file directories good enough or you think something else should be done there?

theofidry avatar Sep 26 '22 22:09 theofidry

Yes, it's sufficient, thank you :)

ondrejmirtes avatar Sep 27 '22 07:09 ondrejmirtes