From 37ee92d480eb3bb870a4c7003854978f184e5aa9 Mon Sep 17 00:00:00 2001 From: gitressa <3491208+gitressa@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:36:34 +0200 Subject: [PATCH] Update to working example with Simplenews, prepare for Drupal 12 (#34) * Update README.md to Drupal 11 Also, switch from Token to Simplenews, which is not Drupal 11 ready. * Update PackageRequiresAdjusterTest.php * Update PackageRequiresAdjuster.php --- README.md | 31 ++++++++++++++++----------- src/PackageRequiresAdjuster.php | 2 +- tests/PackageRequiresAdjusterTest.php | 19 ++++++++-------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 22ce383..5325fde 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# mglaman/composer-drupal-lenient +# Drupal Lenient Composer Plugin -Lenient with it, Drupal 10 with it. +Lenient with it, Drupal 11 with it. ## Why? @@ -9,7 +9,9 @@ was done to remove a barrier with getting extensions installed via Composer to w We hit the same problem, again. At DrupalCon Portland we sat down and decided a Composer plugin is the best approach. -See [Add a composer plugin that supports 'composer require-lenient' to support major version transitions](https://www.drupal.org/project/drupal/issues/3267143) +See [Add a composer plugin that supports 'composer require-lenient' to support major version transitions](https://www.drupal.org/project/drupal/issues/3267143). + +Drupal documentation page: [Using Drupal's Lenient Composer Endpoint](https://www.drupal.org/docs/develop/using-composer/using-drupals-lenient-composer-endpoint). ## How @@ -19,30 +21,35 @@ excluding `drupal-core`. The constraint is set to `'^8 || ^9 || ^10 || ^11'` for ## Try it -Setup a fresh Drupal 10 site with this plugin (remember to press `y` for the new `allow-plugins` prompt.) +Set up a fresh Drupal 11 site with this plugin (remember to press `y` for the new `allow-plugins` prompt.) ```shell -composer create-project drupal/recommended-project:^10@alpha d10 -cd d10 -composer config minimum-stability dev +composer create-project drupal/recommended-project d11 +cd d11 composer require mglaman/composer-drupal-lenient ``` The plugin only works against specified packages. To allow a package to have a lenient Drupal core version constraint, -you must add it to `extra.drupal-lenient.allowed-list`. The following is an example to add Token via the command line +you must add it to `extra.drupal-lenient.allowed-list`. The following is an example to add Simplenews via the command line with `composer config` ```shell -composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/token"]' +composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/simplenews"]' ``` -Now, add a module that does not have a D10 compatible release! +Now, add a module that does not have a Drupal 11 compatible release! ```shell -composer require drupal/token:1.10.0 +composer require drupal/simplenews ``` -🥳 Now you can use [cweagans/composer-patches](https://github.com/cweagans/composer-patches) to patch the module for Drupal 10 compatibility! +🥳 Now you can use [cweagans/composer-patches](https://github.com/cweagans/composer-patches) to patch the module for Drupal 11 compatibility! + +For a quick start, allow installation by adding the latest version in the module `*.info.yml` file: + +```shell +core_version_requirement: ^9.3 || ^10 || ^11 +``` ## Support when `composer.lock` removed diff --git a/src/PackageRequiresAdjuster.php b/src/PackageRequiresAdjuster.php index 602fc4f..c424296 100644 --- a/src/PackageRequiresAdjuster.php +++ b/src/PackageRequiresAdjuster.php @@ -22,7 +22,7 @@ public function __construct( private readonly Composer $composer ) { $this->drupalCoreConstraint = (new VersionParser()) - ->parseConstraints('^8 || ^9 || ^10 || ^11'); + ->parseConstraints('^8 || ^9 || ^10 || ^11 || ^12'); } public function applies(PackageInterface $package): bool diff --git a/tests/PackageRequiresAdjusterTest.php b/tests/PackageRequiresAdjusterTest.php index e33faf2..db3cb70 100644 --- a/tests/PackageRequiresAdjusterTest.php +++ b/tests/PackageRequiresAdjusterTest.php @@ -87,8 +87,9 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS new Constraint('>=', '8.0'), new Constraint('>=', '9.0'), new Constraint('>=', '10.0'), + new Constraint('>=', '11.0'), ]); - $originalTokenConstraint = new Constraint('>=', '1.10.0'); + $originalSimplenewsConstraint = new Constraint('>=', '4.0.0'); $package = new CompletePackage('foo', '1.0', '1.0'); $package->setType('drupal-module'); $package->setRequires([ @@ -99,12 +100,12 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS Link::TYPE_REQUIRE, $originalDrupalCoreConstraint->getPrettyString() ), - 'drupal/token' => new Link( + 'drupal/simplenews' => new Link( 'bar', - 'drupal/token', - $originalTokenConstraint, + 'drupal/simplenews', + $originalSimplenewsConstraint, Link::TYPE_REQUIRE, - $originalTokenConstraint->getPrettyString() + $originalSimplenewsConstraint->getPrettyString() ) ]); $adjuster->adjust($package); @@ -113,8 +114,8 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS $package->getRequires()['drupal/core']->getConstraint()->getPrettyString() ); self::assertSame( - $originalTokenConstraint, - $package->getRequires()['drupal/token']->getConstraint() + $originalSimplenewsConstraint, + $package->getRequires()['drupal/simplenews']->getConstraint() ); if ($coreVersion !== null) { self::assertTrue( @@ -129,8 +130,8 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS public function provideAdjustData(): array { return [ - [null, '^8 || ^9 || ^10 || ^11'], - ['10.0.0-alpha5', '^8 || ^9 || ^10 || ^11'], + [null, '^8 || ^9 || ^10 || ^11 || ^12'], + ['10.0.0-alpha5', '^8 || ^9 || ^10 || ^11 || ^12'], ]; } }