Ocramius / PackageVersions

:package: Composer addon to efficiently get installed packages' version numbers
MIT License
3.22k stars 67 forks source link

Support for Versions::ROOT_PACKAGE_NAME is broken #148

Closed stof closed 4 years ago

stof commented 4 years ago

Versions::getVersion(Versions::ROOT_PACKAGE_NAME) is expected to return the version of the root package. But currently, the implementation forwards such call to Composer\InstalledVersions::getVersion() directly, which does not support the root package as package name. Info about the root package is exposed through Composer\InstalledVersions::getRootPackage()

Ocramius commented 4 years ago

I think Versions::ROOT_PACKAGE_NAME should be overall deprecated (https://github.com/Ocramius/PackageVersions/issues/142, https://github.com/Ocramius/PackageVersions/issues/139)

stof commented 4 years ago

sure. But in the meantime, it should still work. for now, there is no way to get the info about the root package anymore in this library.

Ocramius commented 4 years ago

Hmm, wait, so Composer\InstalledVersions::getVersion() has no root package info at all?

stof commented 4 years ago

Composer\InstalledVersions::getVersion() is only about packages installed in vendors (same than Composer\InstalledVersions::isInstalled(). The info about the root package are available through a separate Composer\InstalledVersions::getRootPackage() method.

Ocramius commented 4 years ago

I see, makes sense. Will indeed need some trickery to work :-\

stof commented 4 years ago

Well, I think this could look like this:

function getVersion(string $packageName)
{
    if ($packageName === self::ROOT_PACKAGE_NAME) {
        return \Composer\InstalledVersions::getRootPackage()['version']; // Or whatever is needed to output the right info
    }

    // existing code stays here
}
Ocramius commented 4 years ago

This seems to be only affecting the "fallback" version, when 'unknown/root-package@UNKNOWN' is used for a lookup. Not a massive fix though :-)