Problem/Motivation

The recipe unpacker is, in effect, a version lock. When you unpack a recipe and remove it from Composer's awareness, you are pinning it to that specific version.

That's all well and good, but it means we have no way to interrogate Composer to ask which version of the recipe was installed -- which is very much necessary for, say, downloading the correct translation of the recipe.

Normally you'd use the version field in composer.json for that, but there is no guarantee that will be set, because Composer can and does infer versions from things like Git tags and such.

Proposed resolution

The recipe unpacker should alter the unpacked recipe's composer.json file and write the version field explicitly. It has access to the version because it has access to the PackageInterface object and its getPrettyVersion() method.

Issue fork drupal-3607162

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Status: Active » Needs review
smustgrave’s picture

Should I see a version key added to the recipe?

phenaproxima’s picture

To the recipe's composer.json, yeah.

smustgrave’s picture

Sorry trying to help test this one.

I applied the MR, downloaded a recipe via composer, but not seeing VERSION key.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Going to do a lot of leaning on other sources here.

1. I trust what @phenaproxima is suggesting around recipes.
2. MR is green, I did rebase as it was 500+ commits behind.
3. I had to run the test-only locally

Failed asserting that a NULL is not empty.
/var/www/html/core/tests/Drupal/BuildTests/Composer/Plugin/Unpack/Functional/UnpackRecipeTest.php:691
/var/www/html/core/tests/Drupal/BuildTests/Composer/Plugin/Unpack/Functional/UnpackRecipeTest.php:94

Failed asserting that a NULL is not empty.
/var/www/html/core/tests/Drupal/BuildTests/Composer/Plugin/Unpack/Functional/UnpackRecipeTest.php:691
/var/www/html/core/tests/Drupal/BuildTests/Composer/Plugin/Unpack/Functional/UnpackRecipeTest.php:226

Going to go on a limb

catch’s picture

Status: Reviewed & tested by the community » Needs review

Changing the recipe's composer.json seems a bit unexpected, I wouldn't expect the local site to change that.

Could we put this information into vendor/composer - like vendor/composer/unpacked-recipes.json or similar? (note this is a proper question not a concrete suggestion because I don't know how hard that would be).

phenaproxima’s picture

Not hard at all, actually. I've implemented this and updated the tests.

phenaproxima’s picture

Title: The recipe unpacker should explicitly write the unpacked version of the recipe into its composer.json » The recipe unpacker should store the unpacked version of the recipe
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.04 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

phenaproxima’s picture

Status: Needs work » Needs review