Skip to content

Instantly share code, notes, and snippets.

@mvorisek
Last active September 6, 2022 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvorisek/91ffee6254aed784daff3f1a0994d11a to your computer and use it in GitHub Desktop.
Save mvorisek/91ffee6254aed784daff3f1a0994d11a to your computer and use it in GitHub Desktop.
Analyse non-latest PrestaShop dependencies
<?php
$pkgs = [
// packages required by PrestaShop, retrived from PrestaShop composer.lock, then rerun and retrived from all composer.lock files
'beberlei/doctrineextensions', 'behat/behat', 'behat/gherkin', 'behat/transliterator', 'composer/ca-bundle', 'composer/installers', 'composer/semver', 'composer/xdebug-handler', 'container-interop/container-interop', 'csa/guzzle-bundle', 'csa/guzzle-cache-middleware', 'csa/guzzle-history-middleware', 'csa/guzzle-stopwatch-middleware', 'cssjanus/cssjanus', 'curl/curl', 'defuse/php-encryption', 'doctrine/annotations', 'doctrine/cache', 'doctrine/collections', 'doctrine/common', 'doctrine/dbal', 'doctrine/doctrine-bundle', 'doctrine/doctrine-cache-bundle', 'doctrine/event-manager', 'doctrine/inflector', 'doctrine/instantiator', 'doctrine/lexer', 'doctrine/orm', 'doctrine/persistence', 'doctrine/reflection', 'egulias/email-validator', 'ezyang/htmlpurifier', 'fig/link-util', 'friendsofphp/php-cs-fixer', 'friendsofsymfony/jsrouting-bundle', 'geoip2/geoip2', 'greenlion/php-sql-parser', 'guzzlehttp/cache-subscriber', 'guzzlehttp/guzzle', 'guzzlehttp/log-subscriber', 'guzzlehttp/promises', 'guzzlehttp/psr7', 'guzzlehttp/ringphp', 'guzzlehttp/streams', 'incenteev/composer-parameter-handler', 'intervention/httpauth', 'ircmaxell/password-compat', 'ircmaxell/random-lib', 'ircmaxell/security-lib', 'jakeasmith/http_build_url', 'jdorn/sql-formatter', 'johnkary/phpunit-speedtrap', 'league/tactician', 'league/tactician-bundle', 'league/tactician-container', 'league/tactician-logger', 'marcusschwarz/lesserphp', 'markbaker/complex', 'markbaker/matrix', 'martinlindhe/php-mb-helpers', 'matthiasmullie/minify', 'matthiasmullie/path-converter', 'maxmind/web-service-common', 'maxmind-db/reader', 'mikey179/vfsstream', 'mobiledetect/mobiledetectlib', 'monolog/monolog', 'mrclay/jsmin-php', 'mrclay/minify', 'mrclay/props-dic', 'myclabs/deep-copy', 'nikic/php-parser', 'paragonie/random_compat', 'pear/archive_tar', 'pear/console_getopt', 'pear/pear_exception', 'pear/pear-core-minimal', 'pelago/emogrifier', 'phake/phake', 'phar-io/manifest', 'phar-io/version', 'php-cs-fixer/diff', 'phpdocumentor/reflection-common', 'phpdocumentor/reflection-docblock', 'phpdocumentor/type-resolver', 'phpoffice/phpspreadsheet', 'phpspec/prophecy', 'phpunit/php-code-coverage', 'phpunit/php-file-iterator', 'phpunit/php-text-template', 'phpunit/php-timer', 'phpunit/php-token-stream', 'phpunit/phpunit', 'pimple/pimple', 'prestashop/blockreassurance', 'prestashop/circuit-breaker', 'prestashop/contactform', 'prestashop/dashactivity', 'prestashop/dashgoals', 'prestashop/dashproducts', 'prestashop/dashtrends', 'prestashop/decimal', 'prestashop/graphnvd3', 'prestashop/gridhtml', 'prestashop/gsitemap', 'prestashop/pagesnotfound', 'prestashop/productcomments', 'prestashop/ps_banner', 'prestashop/ps_categorytree', 'prestashop/ps_checkpayment', 'prestashop/ps_contactinfo', 'prestashop/ps_crossselling', 'prestashop/ps_currencyselector', 'prestashop/ps_customeraccountlinks', 'prestashop/ps_customersignin', 'prestashop/ps_customtext', 'prestashop/ps_dataprivacy', 'prestashop/ps_emailsubscription', 'prestashop/ps_facetedsearch', 'prestashop/ps_faviconnotificationbo', 'prestashop/ps_featuredproducts', 'prestashop/ps_imageslider', 'prestashop/ps_languageselector', 'prestashop/ps_linklist', 'prestashop/ps_mainmenu', 'prestashop/ps_searchbar', 'prestashop/ps_sharebuttons', 'prestashop/ps_shoppingcart', 'prestashop/ps_socialfollow', 'prestashop/ps_themecusto', 'prestashop/ps_wirepayment', 'prestashop/sekeywords', 'prestashop/statsbestcategories', 'prestashop/statsbestcustomers', 'prestashop/statsbestmanufacturers', 'prestashop/statsbestproducts', 'prestashop/statsbestsuppliers', 'prestashop/statsbestvouchers', 'prestashop/statscarrier', 'prestashop/statscatalog', 'prestashop/statscheckup', 'prestashop/statsdata', 'prestashop/statsequipment', 'prestashop/statsforecast', 'prestashop/statslive', 'prestashop/statsnewsletter', 'prestashop/statsorigin', 'prestashop/statspersonalinfos', 'prestashop/statsproduct', 'prestashop/statsregistrations', 'prestashop/statssales', 'prestashop/statssearch', 'prestashop/statsstock', 'prestashop/statsvisits', 'prestashop/translationtools-bundle', 'prestashop/welcome', 'psr/cache', 'psr/container', 'psr/event-dispatcher', 'psr/http-message', 'psr/link', 'psr/log', 'psr/simple-cache', 'ralouphie/getallheaders', 'react/promise', 'sebastian/code-unit-reverse-lookup', 'sebastian/comparator', 'sebastian/diff', 'sebastian/environment', 'sebastian/exporter', 'sebastian/global-state', 'sebastian/object-enumerator', 'sebastian/object-reflector', 'sebastian/recursion-context', 'sebastian/resource-operations', 'sebastian/type', 'sebastian/version', 'sensio/distribution-bundle', 'sensio/framework-extra-bundle', 'sensiolabs/security-checker', 'shudrum/array-finder', 'smarty/smarty', 'soundasleep/html2text', 'swiftmailer/swiftmailer', 'symfony/cache', 'symfony/cache-contracts', 'symfony/class-loader', 'symfony/config', 'symfony/console', 'symfony/contracts', 'symfony/css-selector', 'symfony/debug', 'symfony/dependency-injection', 'symfony/doctrine-bridge', 'symfony/error-handler', 'symfony/event-dispatcher', 'symfony/event-dispatcher-contracts', 'symfony/filesystem', 'symfony/finder', 'symfony/framework-bundle', 'symfony/http-client', 'symfony/http-client-contracts', 'symfony/http-foundation', 'symfony/http-kernel', 'symfony/intl', 'symfony/mime', 'symfony/monolog-bridge', 'symfony/monolog-bundle', 'symfony/options-resolver', 'symfony/phpunit-bridge', 'symfony/polyfill-apcu', 'symfony/polyfill-ctype', 'symfony/polyfill-iconv', 'symfony/polyfill-intl-grapheme', 'symfony/polyfill-intl-icu', 'symfony/polyfill-intl-idn', 'symfony/polyfill-intl-normalizer', 'symfony/polyfill-mbstring', 'symfony/polyfill-php56', 'symfony/polyfill-php70', 'symfony/polyfill-php72', 'symfony/polyfill-php73', 'symfony/polyfill-util', 'symfony/process', 'symfony/routing', 'symfony/serializer', 'symfony/service-contracts', 'symfony/stopwatch', 'symfony/swiftmailer-bundle', 'symfony/symfony', 'symfony/translation', 'symfony/translation-contracts', 'symfony/twig-bridge', 'symfony/var-dumper', 'symfony/var-exporter', 'symfony/yaml', 'tecnickcom/tcpdf', 'theseer/tokenizer', 'tijsverkoyen/css-to-inline-styles', 'tubalmartin/cssmin', 'twig/twig', 'webmozart/assert', 'willdurand/jsonp-callback-validator',
// download manually - git clone https://github.com/PrestaShop/PrestaShop.git data/prestashop___prestashop
'prestashop/prestashop',
];
function getPkgPath($pkg) {
return __DIR__ . '/data/' . preg_replace('~/~', '___', $pkg);
}
// create composer.lock files
foreach ($pkgs as $pkg) {
if (!file_exists(getPkgPath($pkg))) { // delete "data" dir to refresh
mkdir(getPkgPath($pkg));
exec('cd "' . getPkgPath($pkg) . '" && composer require ' . $pkg, $out, $retVar);
if ($retVar !== 0) {
throw new \Exception(implode("\n", $out));
}
}
}
// read data
$dataByPkg = [];
foreach ($pkgs as $pkg) {
$d = json_decode(file_get_contents(getPkgPath($pkg) . '/composer.lock'), true);
if (empty($d)) {
throw new \Exception('Failed to load composer.lock for "' . $pkg . '".');
}
$res = [];
foreach ($d['packages'] as $p) {
$res[$p['name']] = preg_replace('~^v~', '', $p['version']);
}
$dataByPkg[$pkg] = $res;
}
$getLatestPackageVersion = function($pkg) use($dataByPkg) {
return $dataByPkg[$pkg][$pkg] ?? null;
};
// find packages that require packages of non-latest versions
$res = [];
foreach ($pkgs as $pkg) {
foreach ($dataByPkg[$pkg] as $p => $v) {
$lv = $getLatestPackageVersion($p);
if ($v !== $lv && $lv !== null) {
$res[$pkg][$p] = $v;
}
}
}
// print_r($dataByPkg);
print_r($res);
@mvorisek
Copy link
Author

@mvorisek
Copy link
Author

mvorisek commented Jan 24, 2020

Result:

Array
(
    [behat/behat] => Array // has merged PR https://github.com/Behat/Behat/pull/1256 , SOLVED - TAGGED/RELEASED
        (
            [symfony/config] => 4.4.3
            [symfony/console] => 4.4.3
            [symfony/dependency-injection] => 4.4.3
            [symfony/event-dispatcher] => 4.4.3
            [symfony/event-dispatcher-contracts] => 1.1.7
            [symfony/translation] => 4.4.3
            [symfony/yaml] => 4.4.3
        )

    [csa/guzzle-bundle] => Array // required directly and only by PrestaShop, has merged PR https://github.com/csarrazi/CsaGuzzleBundle/pull/255 , SOLVED - TAGGED/RELEASED
        (
            [symfony/config] => 4.4.3
            [symfony/dependency-injection] => 4.4.3
            [symfony/error-handler] => 4.4.3
            [symfony/event-dispatcher] => 4.4.3
            [symfony/event-dispatcher-contracts] => 1.1.7
            [symfony/filesystem] => 4.4.3
            [symfony/framework-bundle] => 4.4.3
            [symfony/http-kernel] => 4.4.3
            [symfony/routing] => 4.4.3
            [symfony/stopwatch] => 4.4.3
            [twig/twig] => 2.12.3
        )

    [csa/guzzle-cache-middleware] => Array // required by "csa/guzzle-bundle" only, has merged PR https://github.com/csarrazi/guzzle-cache-middleware/pull/8 , SOLVED - TAGGED/RELEASED
        (
            [symfony/filesystem] => 4.4.3
        )

    [csa/guzzle-stopwatch-middleware] => Array // required by "csa/guzzle-bundle" only, has merged PR https://github.com/csarrazi/guzzle-stopwatch-middleware/pull/1 , SOLVED - TAGGED/RELEASED
        (
            [symfony/stopwatch] => 4.4.3
        )

    [doctrine/doctrine-cache-bundle] => Array // required by "doctrine/doctrine-bundle", package no longer needed if "doctrine-bundle" is migrated to version >= 2.0 ~~has merged PR https://github.com/doctrine/DoctrineCacheBundle/pull/158 , waiting for tagged release~~
        (
            [symfony/doctrine-bridge] => 4.4.3
        )

    [friendsofphp/php-cs-fixer] => Array // 1.3.x version is fine, only internal and intended dependency of CS fixer (consulted in https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4754 )
        (
            [php-cs-fixer/diff] => 1.3.0
        )

    [guzzlehttp/cache-subscriber] => Array // archived/deprecated package, required by: "prestashop/blockreassurance", "prestashop/productcomments", suggested by: "prestashop/circuit-breaker"
        (
            [guzzlehttp/guzzle] => 5.3.4
        )

    [guzzlehttp/log-subscriber] => Array // archived/deprecated package, required by: old "csa/guzzle-bundle"
        (
            [guzzlehttp/guzzle] => 5.3.4
        )

    [incenteev/composer-parameter-handler] => Array // has merged PR https://github.com/Incenteev/ParameterHandler/pull/132 , waiting for tagged release (but last release in 2018!)
        (
            [symfony/yaml] => 4.4.3
        )

    [prestashop/blockreassurance] => Array
        (
            [guzzlehttp/guzzle] => 5.3.4 // required by requiring archived/deprecated "guzzlehttp/cache-subscriber" package
            [symfony/css-selector] => 3.4.37 // PR merged https://github.com/PrestaShop/blockreassurance/pull/38
        )

    [prestashop/circuit-breaker] => Array
        (
            [guzzlehttp/guzzle] => 5.3.4 // required by requiring "guzzlehttp/guzzle: ^5" package
        )

    [prestashop/productcomments] => Array
        (
            [guzzlehttp/guzzle] => 5.3.4 // required by requiring archived/deprecated "guzzlehttp/cache-subscriber" package
            [symfony/css-selector] => 3.4.37 // PR merged https://github.com/PrestaShop/productcomments/pull/49
        )

    [prestashop/translationtools-bundle] => Array // PR submitted https://github.com/PrestaShop/TranslationToolsBundle/pull/71 , waiting for merge and tagged release
        (
            [symfony/twig-bridge] => 3.4.37
            [twig/twig] => 2.12.3
        )

    [sensio/distribution-bundle] => Array // archived/deprecated package, required directly and only by PrestaShop
        (
            [symfony/config] => 3.4.37
            [symfony/console] => 4.4.3
            [symfony/dependency-injection] => 3.4.37
            [symfony/event-dispatcher] => 4.4.3
            [symfony/event-dispatcher-contracts] => 1.1.7
            [symfony/filesystem] => 3.4.37
            [symfony/http-foundation] => 4.4.3
            [symfony/http-kernel] => 3.4.37
            [symfony/process] => 3.4.37
        )

    [prestashop/prestashop] => Array // TODO once all deps are compatible with the latest Guzzle, Symfony and Twig packages
        (
            [csa/guzzle-bundle] => 1.3.0
            [cssjanus/cssjanus] => dev-patch-1
            [curl/curl] => 1.9.3
            [defuse/php-encryption] => 2.0.3
            [doctrine/dbal] => 2.9.3
            [doctrine/doctrine-bundle] => 1.12.6
            [doctrine/lexer] => 1.0.2
            [doctrine/persistence] => 1.3.5
            [egulias/email-validator] => 2.1.14
            [geoip2/geoip2] => 2.4.5
            [guzzlehttp/guzzle] => 5.3.4
            [matthiasmullie/minify] => 1.3.62
            [matthiasmullie/path-converter] => 1.1.2
            [monolog/monolog] => 1.25.3
            [mrclay/minify] => 2.3.3
            [paragonie/random_compat] => 2.0.18
            [pelago/emogrifier] => 2.2.0
            [sensio/framework-extra-bundle] => 5.4.1
            [soundasleep/html2text] => 0.5.0
            [symfony/http-client] => 4.4.2
            [symfony/http-client-contracts] => 1.1.8
            [symfony/mime] => 4.4.2
            [symfony/service-contracts] => 1.1.8
            [symfony/swiftmailer-bundle] => 3.2.6
            [symfony/symfony] => 3.4.36
            [twig/twig] => 1.42.4
        )

)

@mvorisek
Copy link
Author

mvorisek commented Jan 25, 2020

To check devs packages of each dependency run the script above, rename data directory to datad and replace the first foreach with:

// create composer.lock files
foreach ($pkgs as $pkg) {
    if (!file_exists(getPkgPath($pkg))) { // delete "data" dir to refresh
        var_dump($pkg);
        $srcComposerFile = preg_replace('~(?<=[/\\\\])data(?=[/\\\\]|$)~', 'datad', getPkgPath($pkg), 1) . '/vendor/' . $pkg . '/composer.json';
        if (!file_exists($srcComposerFile)) {
            echo '-> ' . $srcComposerFile . ' does not exists!' . "\n";
            continue;
        }
        mkdir(getPkgPath($pkg));

        copy($srcComposerFile, getPkgPath($pkg) . '/composer.json');
        exec('cd "' . getPkgPath($pkg) . '" && composer install', $out, $retVar);
        if ($retVar !== 0) {
            throw new \Exception(implode("\n", $out));
        }
    }
}

@mvorisek
Copy link
Author

Thanks to composer/composer@3a7ea25 no longer needed for composer 2.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment