Last active
March 2, 2021 13:38
-
-
Save nrctkno/ecaa664305b3fd8b0c86128d99056255 to your computer and use it in GitHub Desktop.
List all non-repeated dependency versions in a composer.lock file by package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
usage: | |
$ php -f .\show_composer_lock_reqs.php | |
$ php -f .\show_composer_lock_reqs.php /my/base/dir/ (note the slash at the end) | |
*/ | |
array_walk( | |
array_reduce ( | |
json_decode( | |
file_get_contents( | |
(count($_SERVER['argv']) > 1 ? $_SERVER['argv'][1] : '') | |
. 'composer.lock' | |
), | |
true | |
)['packages'], | |
function($acc, $item) { | |
$acc = array_merge_recursive( | |
(is_null($acc) ? [] : $acc), | |
[$item['name'] => [ $item['version']. ' (project)'] ], | |
(isset($item['require']) ? $item['require']: []), | |
(isset($item['require-dev']) ? $item['require-dev']: []) | |
); | |
ksort($acc); | |
return $acc; | |
} | |
), | |
function($v, $k){ | |
if(is_array($v)){ | |
$v = array_unique($v); | |
asort($v); | |
$versions = implode('; ', $v); | |
} else { | |
$versions = $v; | |
} | |
echo $k, ': ', $versions, "\n"; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment