Skip to content

Commit

Permalink
Update to working example with Simplenews, prepare for Drupal 12 (#34)
Browse files Browse the repository at this point in the history
* Update README.md to Drupal 11

Also, switch from Token to Simplenews, which is not Drupal 11 ready.

* Update PackageRequiresAdjusterTest.php

* Update PackageRequiresAdjuster.php
  • Loading branch information
gitressa authored Oct 18, 2024
1 parent 6f9e03f commit 37ee92d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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?

Expand All @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/PackageRequiresAdjuster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions tests/PackageRequiresAdjusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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'],
];
}
}

0 comments on commit 37ee92d

Please sign in to comment.