[PP-1] Look for recipes in common locations where site builders might keep them

Created on 16 February 2024, 10 months ago

Problem/Motivation

This is postponed on #3421197: It is impossible for recipes to depend on recipes outside of their own directory β†’ .

In that issue, we're making the RecipeDiscovery better by ensuring it always searches core's recipes, rather than just the directory that contains the recipe currently being applied.

Right now, we're hard-coding core/recipes as RecipeDiscovery's sole search path. But this isn't suitable for the real world; site builders will install recipes via Composer, and we need to also search for recipes that they might have made available.

Proposed resolution

Figure out how to determine where to search for recipes, then add that to RecipeDiscovery, with test coverage.

There are a few ways we could determine where recipes are installed, but I think one attractive option is to use Composer's InstalledVersions class. We could simply look for recipes, wherever recipes are already installed. For example:

$installed_recipes = InstalledVersions::getInstalledPackagesByType('drupal-recipe');
$installed_recipe_paths = array_map(InstalledVersions::getInstallPath(...), $installed_recipes);
$installed_recipe_paths = array_map('dirname', $installed_recipe_paths);
$paths_to_search = array_map('realpath', array_unique($installed_recipe_paths));

API changes

Shouldn't be any. This would be an internal change to the RecipeDiscovery class to make it more useful.

✨ Feature request
Status

Postponed

Version

11.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @phenaproxima
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    Does Drupal look for modules in more than just core/modules and /modules/*?

    I think it would be a safe expectation to say that recipes would only be located at core/recipes and /recipes/*.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    #3: Drupal looks for modules in those places, yes, but also in sites/*/modules and within the current installation profile. That said, we don't need to search for recipes in those places, necessarily. I'm on board with keeping it simple and doing what you propose, but IMHO it costs us very little to take advantage of Composer here, and it will allow us greater flexibility if some sites need to put recipes in different places for whatever reason. (I can totally imagine a case where site builders want certain recipes to be in sites/examples.com/recipes, rather than webroot/recipes.)

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    it costs us very little to take advantage of Composer here,

    … this got me thinking … could we do something similar to the way that Drupal core has some "virtual packages" (IDK the correct terminology) to put everything in core/lib/Drupal/Component in its own Composer package?

    i.e. if we could put every core/recipes/* in its own composer package, then suddenly everything is perfectly consistent, because then it'd be just like recipes/*: they all are Composer packages for Drupal recipes.

    I have no idea how feasible this is though πŸ˜…

  • Status changed to Active 10 months ago
  • Merge request !81Use Composer to find recipe paths β†’ (Open) created by phenaproxima
  • Pipeline finished with Failed
    10 months ago
    Total: 153s
    #105286
  • Pipeline finished with Failed
    10 months ago
    Total: 182s
    #105292
  • πŸ‡³πŸ‡ΏNew Zealand xurizaemon Ōtepoti, Aotearoa 🏝

    Removing postpone from ID coz ^^

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    This has turned out to be critical. See this Slack comment:

    I install recipes in /recipes/contrib. If I apply a recipe that calls other recipes in the same folder, they are no longer found.

    So the lack of this is breaking sites that are already using recipes. Big problem.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I thought we had preserved the same folder as the original recipe functionality... we should not have removed that.

  • Pipeline finished with Success
    10 months ago
    Total: 301s
    #109018
  • Pipeline finished with Failed
    10 months ago
    Total: 162s
    #110759
  • Pipeline finished with Failed
    10 months ago
    Total: 191s
    #110764
  • Pipeline finished with Failed
    10 months ago
    Total: 163s
    #110772
  • Pipeline finished with Success
    10 months ago
    Total: 182s
    #110784
  • Status changed to Needs review 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Okay, well, I think I found a way to test this without having to write a build test, which would be very complicated to do. I'm directly manipulating the InstalledVersions class, yes, but it is a documented part of Composer's runtime API which is available for use by non-Composer code, and I'm not calling any internal or deprecated methods of it.

    I think this is probably ready for review.

  • First commit to issue fork.
  • Pipeline finished with Success
    9 months ago
    Total: 309s
    #117005
  • Status changed to Needs work about 1 month ago
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    There are merge conflicts. Moving back to Needs Work.

Production build 0.71.5 2024