shipmonk-rnd / composer-dependency-analyser

🚀 Fast detection of composer dependency issues (unused dependencies, shadow dependencies, misplaced dependencies)
MIT License
399 stars 10 forks source link

Ability to show what application version we are running #168

Closed llaville closed 1 month ago

llaville commented 2 months ago

Hello,

All CLI applications have an option like this

-V, --version                      Display this application version

to be able to know what version we are running. Even PHP CLI runner got it !

It will be very helpfull to add such option.

llaville commented 1 month ago

The Composer Runtime API Composer\InstalledVersions::getPrettyVersion suffer of local git clone (forks) usage, because it check only on versions list, excluding the root entry.

While my fork of your project is installed (via git clone), I've following vendor/composer/installed.php file contents :

file contents ```php array( 'name' => 'shipmonk/composer-dependency-analyser', 'pretty_version' => 'dev-master', 'version' => 'dev-master', 'reference' => '9252ee58b802328237ebbd4e1decb002823afbb2', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev' => true, ), 'versions' => array( 'dealerdirect/phpcodesniffer-composer-installer' => array( 'pretty_version' => 'v1.0.0', 'version' => '1.0.0.0', 'reference' => '4be43904336affa5c2f70744a348312336afd0da', 'type' => 'composer-plugin', 'install_path' => __DIR__ . '/../dealerdirect/phpcodesniffer-composer-installer', 'aliases' => array(), 'dev_requirement' => true, ), 'doctrine/instantiator' => array( 'pretty_version' => '2.0.0', 'version' => '2.0.0.0', 'reference' => 'c6222283fa3f4ac679f8b9ced9a4e23f163e80d0', 'type' => 'library', 'install_path' => __DIR__ . '/../doctrine/instantiator', 'aliases' => array(), 'dev_requirement' => true, ), 'editorconfig-checker/editorconfig-checker' => array( 'pretty_version' => '10.6.0', 'version' => '10.6.0.0', 'reference' => 'c51272f825bf0aa02421d47825a8d5f1f2c15049', 'type' => 'library', 'install_path' => __DIR__ . '/../editorconfig-checker/editorconfig-checker', 'aliases' => array(), 'dev_requirement' => true, ), 'ergebnis/composer-normalize' => array( 'pretty_version' => '2.42.0', 'version' => '2.42.0.0', 'reference' => '02cf2b69ad2a74c6f11a8c3f5f054b8f949df910', 'type' => 'composer-plugin', 'install_path' => __DIR__ . '/../ergebnis/composer-normalize', 'aliases' => array(), 'dev_requirement' => true, ), 'ergebnis/json' => array( 'pretty_version' => '1.2.0', 'version' => '1.2.0.0', 'reference' => 'a457f25a5ba7ea11fc94f84d53678c5211abfce0', 'type' => 'library', 'install_path' => __DIR__ . '/../ergebnis/json', 'aliases' => array(), 'dev_requirement' => true, ), 'ergebnis/json-normalizer' => array( 'pretty_version' => '4.5.0', 'version' => '4.5.0.0', 'reference' => 'f0ee9e70739f121b27fac8b743e4a52b23de2152', 'type' => 'library', 'install_path' => __DIR__ . '/../ergebnis/json-normalizer', 'aliases' => array(), 'dev_requirement' => true, ), 'ergebnis/json-pointer' => array( 'pretty_version' => '3.4.0', 'version' => '3.4.0.0', 'reference' => 'b654757d873050622c2166f55ab25d04685261c5', 'type' => 'library', 'install_path' => __DIR__ . '/../ergebnis/json-pointer', 'aliases' => array(), 'dev_requirement' => true, ), 'ergebnis/json-printer' => array( 'pretty_version' => '3.5.0', 'version' => '3.5.0.0', 'reference' => '549e16fe6de34b8c3aee7b421be12caa552f3ced', 'type' => 'library', 'install_path' => __DIR__ . '/../ergebnis/json-printer', 'aliases' => array(), 'dev_requirement' => true, ), 'ergebnis/json-schema-validator' => array( 'pretty_version' => '4.2.0', 'version' => '4.2.0.0', 'reference' => '10ed514fdc3f9b71f8a92c567afea21a2f6fa1ef', 'type' => 'library', 'install_path' => __DIR__ . '/../ergebnis/json-schema-validator', 'aliases' => array(), 'dev_requirement' => true, ), 'justinrainbow/json-schema' => array( 'pretty_version' => 'v5.2.13', 'version' => '5.2.13.0', 'reference' => 'fbbe7e5d79f618997bc3332a6f49246036c45793', 'type' => 'library', 'install_path' => __DIR__ . '/../justinrainbow/json-schema', 'aliases' => array(), 'dev_requirement' => true, ), 'localheinz/diff' => array( 'pretty_version' => '1.1.1', 'version' => '1.1.1.0', 'reference' => '851bb20ea8358c86f677f5f111c4ab031b1c764c', 'type' => 'library', 'install_path' => __DIR__ . '/../localheinz/diff', 'aliases' => array(), 'dev_requirement' => true, ), 'myclabs/deep-copy' => array( 'pretty_version' => '1.11.1', 'version' => '1.11.1.0', 'reference' => '7284c22080590fb39f2ffa3e9057f10a4ddd0e0c', 'type' => 'library', 'install_path' => __DIR__ . '/../myclabs/deep-copy', 'aliases' => array(), 'dev_requirement' => true, ), 'nette/schema' => array( 'pretty_version' => 'v1.3.0', 'version' => '1.3.0.0', 'reference' => 'a6d3a6d1f545f01ef38e60f375d1cf1f4de98188', 'type' => 'library', 'install_path' => __DIR__ . '/../nette/schema', 'aliases' => array(), 'dev_requirement' => true, ), 'nette/utils' => array( 'pretty_version' => 'v4.0.4', 'version' => '4.0.4.0', 'reference' => 'd3ad0aa3b9f934602cb3e3902ebccf10be34d218', 'type' => 'library', 'install_path' => __DIR__ . '/../nette/utils', 'aliases' => array(), 'dev_requirement' => true, ), 'nikic/php-parser' => array( 'pretty_version' => 'v5.0.2', 'version' => '5.0.2.0', 'reference' => '139676794dc1e9231bf7bcd123cfc0c99182cb13', 'type' => 'library', 'install_path' => __DIR__ . '/../nikic/php-parser', 'aliases' => array(), 'dev_requirement' => true, ), 'phar-io/manifest' => array( 'pretty_version' => '2.0.4', 'version' => '2.0.4.0', 'reference' => '54750ef60c58e43759730615a392c31c80e23176', 'type' => 'library', 'install_path' => __DIR__ . '/../phar-io/manifest', 'aliases' => array(), 'dev_requirement' => true, ), 'phar-io/version' => array( 'pretty_version' => '3.2.1', 'version' => '3.2.1.0', 'reference' => '4f7fd7836c6f332bb2933569e566a0d6c4cbed74', 'type' => 'library', 'install_path' => __DIR__ . '/../phar-io/version', 'aliases' => array(), 'dev_requirement' => true, ), 'phpcompatibility/php-compatibility' => array( 'pretty_version' => '9.3.5', 'version' => '9.3.5.0', 'reference' => '9fb324479acf6f39452e0655d2429cc0d3914243', 'type' => 'phpcodesniffer-standard', 'install_path' => __DIR__ . '/../phpcompatibility/php-compatibility', 'aliases' => array(), 'dev_requirement' => true, ), 'phpstan/phpdoc-parser' => array( 'pretty_version' => '1.27.0', 'version' => '1.27.0.0', 'reference' => '86e4d5a4b036f8f0be1464522f4c6b584c452757', 'type' => 'library', 'install_path' => __DIR__ . '/../phpstan/phpdoc-parser', 'aliases' => array(), 'dev_requirement' => true, ), 'phpstan/phpstan' => array( 'pretty_version' => '1.11.3', 'version' => '1.11.3.0', 'reference' => 'e64220a05c1209fc856d58e789c3b7a32c0bb9a5', 'type' => 'library', 'install_path' => __DIR__ . '/../phpstan/phpstan', 'aliases' => array(), 'dev_requirement' => true, ), 'phpstan/phpstan-phpunit' => array( 'pretty_version' => '1.4.0', 'version' => '1.4.0.0', 'reference' => 'f3ea021866f4263f07ca3636bf22c64be9610c11', 'type' => 'phpstan-extension', 'install_path' => __DIR__ . '/../phpstan/phpstan-phpunit', 'aliases' => array(), 'dev_requirement' => true, ), 'phpstan/phpstan-strict-rules' => array( 'pretty_version' => '1.6.0', 'version' => '1.6.0.0', 'reference' => '363f921dd8441777d4fc137deb99beb486c77df1', 'type' => 'phpstan-extension', 'install_path' => __DIR__ . '/../phpstan/phpstan-strict-rules', 'aliases' => array(), 'dev_requirement' => true, ), 'phpunit/php-code-coverage' => array( 'pretty_version' => '9.2.31', 'version' => '9.2.31.0', 'reference' => '48c34b5d8d983006bd2adc2d0de92963b9155965', 'type' => 'library', 'install_path' => __DIR__ . '/../phpunit/php-code-coverage', 'aliases' => array(), 'dev_requirement' => true, ), 'phpunit/php-file-iterator' => array( 'pretty_version' => '3.0.6', 'version' => '3.0.6.0', 'reference' => 'cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf', 'type' => 'library', 'install_path' => __DIR__ . '/../phpunit/php-file-iterator', 'aliases' => array(), 'dev_requirement' => true, ), 'phpunit/php-invoker' => array( 'pretty_version' => '3.1.1', 'version' => '3.1.1.0', 'reference' => '5a10147d0aaf65b58940a0b72f71c9ac0423cc67', 'type' => 'library', 'install_path' => __DIR__ . '/../phpunit/php-invoker', 'aliases' => array(), 'dev_requirement' => true, ), 'phpunit/php-text-template' => array( 'pretty_version' => '2.0.4', 'version' => '2.0.4.0', 'reference' => '5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28', 'type' => 'library', 'install_path' => __DIR__ . '/../phpunit/php-text-template', 'aliases' => array(), 'dev_requirement' => true, ), 'phpunit/php-timer' => array( 'pretty_version' => '5.0.3', 'version' => '5.0.3.0', 'reference' => '5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2', 'type' => 'library', 'install_path' => __DIR__ . '/../phpunit/php-timer', 'aliases' => array(), 'dev_requirement' => true, ), 'phpunit/phpunit' => array( 'pretty_version' => '9.6.19', 'version' => '9.6.19.0', 'reference' => 'a1a54a473501ef4cdeaae4e06891674114d79db8', 'type' => 'library', 'install_path' => __DIR__ . '/../phpunit/phpunit', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/cli-parser' => array( 'pretty_version' => '1.0.2', 'version' => '1.0.2.0', 'reference' => '2b56bea83a09de3ac06bb18b92f068e60cc6f50b', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/cli-parser', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/code-unit' => array( 'pretty_version' => '1.0.8', 'version' => '1.0.8.0', 'reference' => '1fc9f64c0927627ef78ba436c9b17d967e68e120', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/code-unit', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/code-unit-reverse-lookup' => array( 'pretty_version' => '2.0.3', 'version' => '2.0.3.0', 'reference' => 'ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/code-unit-reverse-lookup', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/comparator' => array( 'pretty_version' => '4.0.8', 'version' => '4.0.8.0', 'reference' => 'fa0f136dd2334583309d32b62544682ee972b51a', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/comparator', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/complexity' => array( 'pretty_version' => '2.0.3', 'version' => '2.0.3.0', 'reference' => '25f207c40d62b8b7aa32f5ab026c53561964053a', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/complexity', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/diff' => array( 'pretty_version' => '4.0.6', 'version' => '4.0.6.0', 'reference' => 'ba01945089c3a293b01ba9badc29ad55b106b0bc', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/diff', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/environment' => array( 'pretty_version' => '5.1.5', 'version' => '5.1.5.0', 'reference' => '830c43a844f1f8d5b7a1f6d6076b784454d8b7ed', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/environment', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/exporter' => array( 'pretty_version' => '4.0.6', 'version' => '4.0.6.0', 'reference' => '78c00df8f170e02473b682df15bfcdacc3d32d72', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/exporter', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/global-state' => array( 'pretty_version' => '5.0.7', 'version' => '5.0.7.0', 'reference' => 'bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/global-state', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/lines-of-code' => array( 'pretty_version' => '1.0.4', 'version' => '1.0.4.0', 'reference' => 'e1e4a170560925c26d424b6a03aed157e7dcc5c5', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/lines-of-code', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/object-enumerator' => array( 'pretty_version' => '4.0.4', 'version' => '4.0.4.0', 'reference' => '5c9eeac41b290a3712d88851518825ad78f45c71', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/object-enumerator', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/object-reflector' => array( 'pretty_version' => '2.0.4', 'version' => '2.0.4.0', 'reference' => 'b4f479ebdbf63ac605d183ece17d8d7fe49c15c7', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/object-reflector', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/recursion-context' => array( 'pretty_version' => '4.0.5', 'version' => '4.0.5.0', 'reference' => 'e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/recursion-context', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/resource-operations' => array( 'pretty_version' => '3.0.4', 'version' => '3.0.4.0', 'reference' => '05d5692a7993ecccd56a03e40cd7e5b09b1d404e', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/resource-operations', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/type' => array( 'pretty_version' => '3.2.1', 'version' => '3.2.1.0', 'reference' => '75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/type', 'aliases' => array(), 'dev_requirement' => true, ), 'sebastian/version' => array( 'pretty_version' => '3.0.2', 'version' => '3.0.2.0', 'reference' => 'c6c1022351a901512170118436c764e473f6de8c', 'type' => 'library', 'install_path' => __DIR__ . '/../sebastian/version', 'aliases' => array(), 'dev_requirement' => true, ), 'shipmonk/composer-dependency-analyser' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', 'reference' => '9252ee58b802328237ebbd4e1decb002823afbb2', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev_requirement' => false, ), 'shipmonk/name-collision-detector' => array( 'pretty_version' => '2.1.1', 'version' => '2.1.1.0', 'reference' => 'e8c8267a9a3774450b64f4cbf0bb035108e78f07', 'type' => 'library', 'install_path' => __DIR__ . '/../shipmonk/name-collision-detector', 'aliases' => array(), 'dev_requirement' => true, ), 'slevomat/coding-standard' => array( 'pretty_version' => '8.15.0', 'version' => '8.15.0.0', 'reference' => '7d1d957421618a3803b593ec31ace470177d7817', 'type' => 'phpcodesniffer-standard', 'install_path' => __DIR__ . '/../slevomat/coding-standard', 'aliases' => array(), 'dev_requirement' => true, ), 'squizlabs/php_codesniffer' => array( 'pretty_version' => '3.9.1', 'version' => '3.9.1.0', 'reference' => '267a4405fff1d9c847134db3a3c92f1ab7f77909', 'type' => 'library', 'install_path' => __DIR__ . '/../squizlabs/php_codesniffer', 'aliases' => array(), 'dev_requirement' => true, ), 'theseer/tokenizer' => array( 'pretty_version' => '1.2.3', 'version' => '1.2.3.0', 'reference' => '737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2', 'type' => 'library', 'install_path' => __DIR__ . '/../theseer/tokenizer', 'aliases' => array(), 'dev_requirement' => true, ), ), ); ```

In such context, we will always have Version: unknown while an expected good value could be either :

And, last but not least, if we want to use your package as a PHAR distribution, we will never know what version is included !

This is the reason why I've adopted myself another approach of Composer Runtime API. For example, on my repo https://github.com/llaville/sarif-php-converters/blob/master/src/Console/Application.php#L40-L62

And at runtime, I got

devilbox@php-8.2.21 in /shared/backups/bartlett/sarif-php-converters $ php report-converter --version
SARIF PHP Converters 1.0.x-dev@cbc5f68

devilbox@php-8.2.21 in /shared/backups/bartlett/sarif-php-converters $ head -12 vendor/composer/installed.php
<?php return array(
    'root' => array(
        'name' => 'bartlett/sarif-php-converters',
        'pretty_version' => '1.0.x-dev',
        'version' => '1.0.9999999.9999999-dev',
        'reference' => 'cbc5f683983111c335e8c76af87d347a7858e966',
        'type' => 'library',
        'install_path' => __DIR__ . '/../../',
        'aliases' => array(),
        'dev' => true,
    ),
    'versions' => array(