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

Support for Versions::ROOT_PACKAGE_NAME is broken #148

Closed
stof opened this issue Aug 17, 2020 · 7 comments · Fixed by #150
Closed

Support for Versions::ROOT_PACKAGE_NAME is broken #148

stof opened this issue Aug 17, 2020 · 7 comments · Fixed by #150
Assignees
Labels
Milestone

Comments

@stof
Copy link
Contributor

stof commented Aug 17, 2020

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
Copy link
Owner

I think Versions::ROOT_PACKAGE_NAME should be overall deprecated (#142, #139)

@Ocramius Ocramius self-assigned this Aug 17, 2020
@Ocramius Ocramius added this to the 2.0.0 milestone Aug 17, 2020
@stof
Copy link
Contributor Author

stof commented Aug 17, 2020

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
Copy link
Owner

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

@stof
Copy link
Contributor Author

stof commented Aug 17, 2020

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
Copy link
Owner

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

@Ocramius Ocramius added bug and removed enhancement labels Aug 17, 2020
@Ocramius Ocramius modified the milestones: 2.0.0, 1.10.1 Aug 17, 2020
@stof
Copy link
Contributor Author

stof commented Aug 17, 2020

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 Ocramius modified the milestones: 1.10.1, 1.10.2 Aug 18, 2020
@Ocramius
Copy link
Owner

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

Ocramius added a commit that referenced this issue Aug 18, 2020
…h `--no-scripts`

The root package version, when running with a stub version of `PackageVersions\Versions`
(which happens when installation was run with `--no-scripts` or equivalent), uses a string
that is not recognized by Composer's `composer-runtime-api` tooling: for that special
case, we compare it to the default version that is stored in the constant, and use
composer's tooling to figure out the actual root package version
Ocramius added a commit that referenced this issue Aug 18, 2020
…name-version

#148 retrieve root package version also when package is installed with `--no-scripts`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants