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 9abff904d115160af501ebfb0146af06778f0755..0875ce556353353d44fed174abc462231e5291d3 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 3d95a6e334ab3127061302d23cef756677690744..4634b0f9c5d5eda586c026edc1bf2bae5fdc480b 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' diff --git a/README.md b/README.md index db1a96288edd41508e3ee2935a7e16a600358269..398e92a036f680ea4a3d708ba21a480472ba2eb1 100644 --- a/README.md +++ b/README.md @@ -13,39 +13,30 @@ 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 config allow-plugins.xpertselect/tools true +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`: - -```json -{ - "scripts": { - "post-update-cmd": [ - "vendor/bin/xs-config --type={project-type} --force=false", - "vendor/bin/xs-dependencies" - ] - } -} +Run: + +```shell +composer update ``` -The following `{project-type}`s are supported: +During the update process, the plugin will automatically: -- `standard` -- `laravel-project` -- `laravel-package` -- `drupal-project` -- `drupal-package` +- Inspect your existing composer requirements. +- Add the necessary development dependencies. +- Applies the required configuration entries to the root of your project. -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, 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 721e3a881828a3f81b15857db3203e20de459a4a..e1cd398651313fb7605c641fab913a45b90451aa 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,6 @@ final readonly class DependencyService return false; } - return str_starts_with($version, '10'); + return str_starts_with(ltrim($version, '^~><=v '), '10'); } } diff --git a/src/Services/ProjectClassifierService.php b/src/Services/ProjectClassifierService.php index 63cfaea2d98bcc88e8b15b8b9f428854403f7b69..30c61dd26af34170d7b973d7e307554982b38942 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', '<'); } /** diff --git a/tests/Functional/Services/ProjectClassifierServiceTest.php b/tests/Functional/Services/ProjectClassifierServiceTest.php index e6b315ce7da0eb67294be2c9c1df4f652ba031d5..3208e4327632cb06e724d2529ca84d6bd1a64dd1 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()); }