From e62f42f4be904d2b7b46e02be9631ecd57702ae3 Mon Sep 17 00:00:00 2001 From: Bart van den Broeck Date: Wed, 3 Dec 2025 15:58:48 +0100 Subject: [PATCH 1/3] alter version compare and change readme --- README.md | 35 ++++++++++++----------- src/Services/DependencyService.php | 9 +++++- src/Services/ProjectClassifierService.php | 13 +++++---- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index db1a962..52b9c6d 100644 --- a/README.md +++ b/README.md @@ -13,39 +13,40 @@ View the `LICENSE.md` file for licensing details. Installation of [`xpertselect/tools`](https://packagist.org/packages/xpertselect/tools) is done via [Composer](https://getcomposer.org). ```shell -composer require --dev composer-runtime-api ^2.2 xpertselect/tools +composer require --dev xpertselect/tools ``` > This is purely a development dependency, do not include this package as a runtime dependency! ## Usage -Append the below instructions to `composer.json` to automatically create the latest configuration files when running -`composer update`: +Before the plugin is allowed to add configuration and development dependencies, it must be explicitly allowed by Composer. +Add the following block to your composer.json: ```json { - "scripts": { - "post-update-cmd": [ - "vendor/bin/xs-config --type={project-type} --force=false", - "vendor/bin/xs-dependencies" - ] - } + "config": { + "allow-plugins": { + "xpertselect/tools": true + } + } } ``` +After this is in place, run: -The following `{project-type}`s are supported: +```shell +composer update +``` + +During the update process, the plugin will automatically: -- `standard` -- `laravel-project` -- `laravel-package` -- `drupal-project` -- `drupal-package` +- Inspect your existing composer requirements and add the necessary development dependencies. +- Apply the required configuration entries. -Set `--force=true` to always replace any existing configuration files. This will undo any local changes to these files! +No manual changes are needed; the plugin performs these updates based on your project’s current composer.json. ### Updating the package When updating tools, it’s crucial to allow the package to override any existing generated files. -This can be achieved either by removing the generated files or by using the force flag, as outlined above. +This can be achieved by removing the generated files. Afterward, you can apply any necessary local changes to the configuration. diff --git a/src/Services/DependencyService.php b/src/Services/DependencyService.php index 721e3a8..bcf5c80 100644 --- a/src/Services/DependencyService.php +++ b/src/Services/DependencyService.php @@ -129,7 +129,7 @@ final readonly class DependencyService private function isLaravel(array $currentData): bool { foreach (ProjectClassifierService::LARAVEL_DETECTION_DEPENDENCIES as $packageName) { - if (isset($currentData['require'][$packageName])) { + if (isset($currentData['require'][$packageName]) || isset($currentData['require-dev'][$packageName])) { return true; } } @@ -152,6 +152,11 @@ final readonly class DependencyService if (isset($currentData['require'][$packageName])) { $version = $currentData['require'][$packageName]; + break; + } + if (isset($currentData['require-dev'][$packageName])) { + $version = $currentData['require-dev'][$packageName]; + break; } } @@ -164,6 +169,8 @@ final readonly class DependencyService return false; } + $version = ltrim($version, '^~><=v '); + return str_starts_with($version, '10'); } } diff --git a/src/Services/ProjectClassifierService.php b/src/Services/ProjectClassifierService.php index 63cfaea..30c61dd 100644 --- a/src/Services/ProjectClassifierService.php +++ b/src/Services/ProjectClassifierService.php @@ -22,9 +22,11 @@ final readonly class ProjectClassifierService public const DRUPAL_DETECTION_DEPENDENCIES = [ 'drupal/core', 'drupal/core-dev', + 'drupal/core-recommended', ]; public const LARAVEL_DETECTION_DEPENDENCIES = [ + 'illuminate/support', 'laravel/framework', 'orchestra/testbench', ]; @@ -154,7 +156,7 @@ final readonly class ProjectClassifierService public function isDrupal10(): bool { foreach (self::DRUPAL_DETECTION_DEPENDENCIES as $packageName) { - if ($this->isVersionInstalled($packageName, '10')) { + if ($this->isVersionInstalled($packageName, 10)) { return true; } } @@ -170,7 +172,7 @@ final readonly class ProjectClassifierService public function isDrupal11(): bool { foreach (self::DRUPAL_DETECTION_DEPENDENCIES as $packageName) { - if ($this->isVersionInstalled($packageName, '11')) { + if ($this->isVersionInstalled($packageName, 11)) { return true; } } @@ -194,11 +196,11 @@ final readonly class ProjectClassifierService * Determines if the composer.json contains the given package with the specific version. * * @param string $package The package to check for - * @param string $requiredMajorVersion The exact major version to check for + * @param int $requiredMajorVersion The exact major version to check for * * @return bool If the composer.json contains the given package with the specific version */ - public function isVersionInstalled(string $package, string $requiredMajorVersion): bool + public function isVersionInstalled(string $package, int $requiredMajorVersion): bool { if (!$this->isInstalled($package)) { return false; @@ -206,7 +208,8 @@ final readonly class ProjectClassifierService $version = InstalledVersions::getPrettyVersion($package) ?? ''; - return boolval(preg_match(sprintf('/^%s(\.|-)/', $requiredMajorVersion), $version)); + return version_compare($version, $requiredMajorVersion . '.0.0', '>=') + && version_compare($version, $requiredMajorVersion + 1 . '.0.0', '<'); } /** -- GitLab From 7b75136afbfe36415f557543ed8256e14f200e35 Mon Sep 17 00:00:00 2001 From: Bart van den Broeck Date: Wed, 3 Dec 2025 16:27:49 +0100 Subject: [PATCH 2/3] feedback --- README.md | 22 +++++-------------- src/Services/DependencyService.php | 4 +--- .../Services/ProjectClassifierServiceTest.php | 2 +- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 52b9c6d..398e92a 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ View the `LICENSE.md` file for licensing details. Installation of [`xpertselect/tools`](https://packagist.org/packages/xpertselect/tools) is done via [Composer](https://getcomposer.org). ```shell +composer config allow-plugins.xpertselect/tools true composer require --dev xpertselect/tools ``` @@ -20,19 +21,7 @@ composer require --dev xpertselect/tools ## Usage -Before the plugin is allowed to add configuration and development dependencies, it must be explicitly allowed by Composer. -Add the following block to your composer.json: - -```json -{ - "config": { - "allow-plugins": { - "xpertselect/tools": true - } - } -} -``` -After this is in place, run: +Run: ```shell composer update @@ -40,13 +29,14 @@ composer update During the update process, the plugin will automatically: -- Inspect your existing composer requirements and add the necessary development dependencies. -- Apply the required configuration entries. +- Inspect your existing composer requirements. +- Add the necessary development dependencies. +- Applies the required configuration entries to the root of your project. No manual changes are needed; the plugin performs these updates based on your project’s current composer.json. ### Updating the package When updating tools, it’s crucial to allow the package to override any existing generated files. -This can be achieved by removing the generated files. +This can be achieved by removing the generated files, and running composer update. Afterward, you can apply any necessary local changes to the configuration. diff --git a/src/Services/DependencyService.php b/src/Services/DependencyService.php index bcf5c80..e1cd398 100644 --- a/src/Services/DependencyService.php +++ b/src/Services/DependencyService.php @@ -169,8 +169,6 @@ final readonly class DependencyService return false; } - $version = ltrim($version, '^~><=v '); - - return str_starts_with($version, '10'); + return str_starts_with(ltrim($version, '^~><=v '), '10'); } } diff --git a/tests/Functional/Services/ProjectClassifierServiceTest.php b/tests/Functional/Services/ProjectClassifierServiceTest.php index e6b315c..3208e43 100644 --- a/tests/Functional/Services/ProjectClassifierServiceTest.php +++ b/tests/Functional/Services/ProjectClassifierServiceTest.php @@ -144,7 +144,7 @@ final class ProjectClassifierServiceTest extends TestCase self::assertTrue($classifierService->isDrupal10()); self::assertFalse($classifierService->isDrupal11()); - $this->withInstalled(['drupal/core' => '11.0.0-alpha1']); + $this->withInstalled(['drupal/core' => '11.0.0']); self::assertTrue($classifierService->isDrupal11()); self::assertFalse($classifierService->isDrupal10()); } -- GitLab From 9aac539583abdf53a0c5120ba869fb3bd47e9627 Mon Sep 17 00:00:00 2001 From: Bart van den Broeck Date: Wed, 3 Dec 2025 16:30:05 +0100 Subject: [PATCH 3/3] update pipeline --- .gitlab/ci/{analysis => test}/php-cs-fixer.yml | 2 +- .gitlab/ci/{analysis => test}/phpstan.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .gitlab/ci/{analysis => test}/php-cs-fixer.yml (97%) rename .gitlab/ci/{analysis => test}/phpstan.yml (97%) diff --git a/.gitlab/ci/analysis/php-cs-fixer.yml b/.gitlab/ci/test/php-cs-fixer.yml similarity index 97% rename from .gitlab/ci/analysis/php-cs-fixer.yml rename to .gitlab/ci/test/php-cs-fixer.yml index 9abff90..0875ce5 100644 --- a/.gitlab/ci/analysis/php-cs-fixer.yml +++ b/.gitlab/ci/test/php-cs-fixer.yml @@ -1,7 +1,7 @@ --- php-cs-fixer: - stage: analysis + stage: test image: php:8.2-cli-alpine rules: - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' diff --git a/.gitlab/ci/analysis/phpstan.yml b/.gitlab/ci/test/phpstan.yml similarity index 97% rename from .gitlab/ci/analysis/phpstan.yml rename to .gitlab/ci/test/phpstan.yml index 3d95a6e..4634b0f 100644 --- a/.gitlab/ci/analysis/phpstan.yml +++ b/.gitlab/ci/test/phpstan.yml @@ -1,7 +1,7 @@ --- phpstan: - stage: analysis + stage: test image: php:8.3-cli-alpine rules: - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' -- GitLab