ddev / ddev-drupal-contrib

DDEV integration for developing Drupal contrib projects
Apache License 2.0
61 stars 8 forks source link

Module installation with Drupal 11 #38

Open mscieszka opened 1 month ago

mscieszka commented 1 month ago

Currently, the Drupal version to install is determined in expand-composer-json based on $DDEV_PROJECT_TYPE.

It looks like the current approach won't work for Drupal 11 when DDEV introduces D11 support, as $DDEV_PROJECT_TYPE won't have a drupal11 value, but will simply be drupal.

rfay commented 1 month ago

DDEV does detect and use the Drupal version though. Should it be introduced as a new variable or something?

mscieszka commented 1 month ago

To install 11.x-dev now, before running ddev poser, I can add[[ $DDEV_PROJECT_TYPE == "drupal" ]]] && export _TARGET_CORE=11.x-dev to the expand-composer-json file or add the following lines to the composer.json:

"require-dev": {
  "drupal/core-composer-scaffold": "11.x-dev",
  "drupal/core-recommended": "11.x-dev",
  "drupal/core-dev": "11.x-dev"
}

From the README:

This project reads your project_type from DDEV and fetches adds the corresponding version of drupal/core-recommended to composer.json

Until there was an explicit drupalX project type, it was clear which version would be installed - now DDEV's autodetection will not help if this project needs to read the project type from DDEV.

If in the future (D12, etc.) there will only be one `drupal' project type, and if a contrib module supports (or aims to support) more than one Drupal version (like both D10 and D11), what would be the correct installation flow to explicitly install Drupal 11 instead of a Drupal 10 (or to be able to switch between D10 and D11)?

If there is a clear way, perhaps this can be added to the README?

mscieszka commented 1 month ago

There is another approach that does not involve modifying composer.json.

For example, in .ddev/commands/web/poser, just before composer install, we can add composer require drupal/core-recommended:11.x-dev@dev drupal/core-composer-scaffold:11.x-dev@dev drupal/core-project-message:11.x-dev@dev --update-with-all-dependencies to install Drupal 11.x-dev.

As a side note, I was getting an error:

error This project's package.json defines "packageManager": "yarn@4.1.1". However, the current global version of Yarn is 1.22.22

As a quick fix, I have added yarn policies set-version stable to the poser file.

Wylbur commented 3 weeks ago

@mscieszka Thanks for you quick work! I applied your fix to .ddev/commands/web/poser, but I had to add the latest version of drush to the composer require line.

Here's the edited poser file.

export COMPOSER=composer.contrib.json
.ddev/commands/web/expand-composer-json "$DDEV_PROJECT_NAME"
composer require drupal/core-recommended:11.x-dev@dev drupal/core-composer-scaffold:11.x-dev@dev drupal/core-project-message:11.x-dev@dev drush/drush:13.x-dev --update-with-all-dependencies
composer install
rm composer.contrib.json composer.contrib.lock
yarn policies set-version stable
yarn --cwd $DDEV_DOCROOT/core install
touch $DDEV_DOCROOT/core/.env