hgraca / composer-system-requirements-plugin
A composer plugin to manage system dependencies.
Installs: 21
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
Type:composer-plugin
pkg:composer/hgraca/composer-system-requirements-plugin
Requires
- php: ^8.2
- composer-plugin-api: ^2.0
Requires (Dev)
- composer/composer: ^2.5.5
- ergebnis/composer-normalize: ^2.30.2
- friendsofphp/php-cs-fixer: ^v3.16.0
- malukenho/mcbumpface: ^1.2.0
- overtrue/phplint: ^9.0.4
- phpstan/phpstan: ^1.10.11
- phpunit/phpunit: ^10.0.19
- psalm/plugin-phpunit: ^0.18.4
- rector/rector: ^0.15.24
- roave/security-advisories: dev-master
- vimeo/psalm: ^5.9.0
README
This is a composer plugin that will check for requirements at the OS level itself, for example checking if Bash is installed and at a version above 5.0.
How to use
Install and allow the plugin
composer require "hgraca/composer-system-requirements-plugin"
{
  "name": "hgraca/some-project",
  "type": "project",
  "require": {
    "hgraca/composer-system-requirements-plugin": "^1.0"
  },
  "config": {
    "allow-plugins": {
      "hgraca/composer-system-requirements-plugin": true
    }
  }
}
Configure the requirements
At the moment of this writing, there is only one built in requirement, bash, which is validated by the class in
src/Package/RequirementValidator/BashRequirementValidator.php.
If/when more requirements validators are added, you can find them in the same location.
The system requirements can be configured as:
{
  "name": "hgraca/dummy-shell-project-1",
  "type": "project",
  "extra": {
    "hgraca/composer-system-requirements-plugin": {
      "require": {
        "bash": "^5.1"
      }
    }
  }
}
Create your own validators
Your validators need to implement the interface \Hgraca\ComposerSystemRequirementsPlugin\Package\RequirementValidator\RequirementValidatorInterface.
For an example, see src/Package/RequirementValidator/BashRequirementValidator.php.
Add your custom requirements validators
{
  "name": "hgraca/dummy-shell-project-1",
  "type": "project",
  "extra": {
    "hgraca/composer-system-requirements-plugin": {
      "require": {
        "bash": "^5.1"
      },
      "validators": [
        "MyVendor\\MyProject\\MyValidatorClass"
      ]
    }
  }
}
A working example
For a working example, please check tests/PluginTestPlayground.
Feel free to run any of the following:
export COMPOSER="composer_with_successful_root_requirement-run_on_shell.json" && composer -d tests/PluginTestPlayground/TestProject install
export COMPOSER="composer_with_failed_root_requirement-run_on_shell.json" && composer -d tests/PluginTestPlayground/TestProject install
How to run
Using local PHP (8.2):
- Install the dependencies with composer install;
- The tests can be run with composer test;
- To list all custom scripts run composer run-script --list.
Using Docker:
- Change PHP and xdebug configs in ./build;
- Install the dependencies with docker compose -f ./build/docker-compose.yaml run app composer install;
- The tests can be run with composer docker-test;
- To list all custom scripts run docker compose -f ./build/docker-compose.yaml run app composer run-script --list.
Other commands
- composer git-bundle: create a git bundle
- git clone -b main composer-system-requirements-plugin.gitbundle composer-system-requirements-plugin: recreate the repository from the git bundle