Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allow-all for leniency to all packages #40

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ Alternatively, manually add the latest version in the module `*.info.yml` file:
core_version_requirement: ^9.3 || ^10 || ^11
```

## Allowing all packages

If you want to allow all packages to have a lenient Drupal core version constraint, you can set `extra.drupal-lenient.allow-all` to `true`.

```shell
composer config --json extra.drupal-lenient.allow-all true
```

Using `allow-all` allows you to install any package without needing to add it to the `allowed-list`.

## Support when `composer.lock` removed

This plugin must be installed globally if your project's `composer.lock` file is removed.
Expand Down
8 changes: 7 additions & 1 deletion src/PackageRequiresAdjuster.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ public function applies(PackageInterface $package): bool
) {
return false;
}
/**
* @var array{drupal-lenient?: array{allow-all?: bool, allowed-list?: list<string>|mixed}} $extra
*/
$extra = $this->composer->getPackage()->getExtra();
// @phpstan-ignore-next-line
$allowAll = $extra['drupal-lenient']['allow-all'] ?? false;
if ($allowAll) {
return true;
}
$allowedList = $extra['drupal-lenient']['allowed-list'] ?? [];
if (!is_array($allowedList) || count($allowedList) === 0) {
return false;
Expand Down
28 changes: 28 additions & 0 deletions tests/PackageRequiresAdjusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ public function testApplies(string $name, string $type, bool $expected): void
self::assertEquals($expected, $adjuster->applies($package));
}

/**
* @covers ::__construct
* @covers ::applies
* @dataProvider provideTypes
*/
public function testAppliesWithAllowsAll(string $name, string $type): void
{
$root = new RootPackage('foo', '1.0', '1.0');
$root->setExtra([
'drupal-lenient' => [
'allow-all' => true,
]
]);
$composer = new Composer();
$composer->setPackage($root);

$adjuster = new PackageRequiresAdjuster($composer);
$package = new Package($name, '1.0', '1.0');
$package->setType($type);

$expected = !(($type === 'library' || $type === 'drupal-core'));
self::assertEquals(
$expected,
$adjuster->applies($package),
"Package $name of type $type should be allowed."
);
}

/**
* @return array<int, array<int, string|bool>>
*/
Expand Down
Loading