Skip to content

Commit

Permalink
Separate tables for changes in direct and indirect dependencies
Browse files Browse the repository at this point in the history
Builds upon davidrjonas#41

Example:

$ composer-lock-diff --no-links
+------------------------------------+-------------+-----------------------+
| Production Changes                 | From        | To                    |
+------------------------------------+-------------+-----------------------+
| andersundsehr/aus-driver-amazon-s3 | 1.12.1      | 1.13.1                |
| felixnagel/generic-gallery         | 4.3.0       | 5.2.0                 |
| fluidtypo3/flux                    | 9.7.2       | 9.7.4                 |
+------------------------------------+-------------+-----------------------+

+-------------------+---------+---------+
| Dev Changes       | From    | To      |
+-------------------+---------+---------+
| mogic/mogic-phpcs | d81fefd | 0eb8337 |
+-------------------+---------+---------+

+------------------------------------+---------+---------+
| Indirect Production Changes        | From    | To      |
+------------------------------------+---------+---------+
| aws/aws-crt-php                    | v1.0.2  | v1.2.7  |
| aws/aws-sdk-php                    | 3.255.7 | 3.331.0 |
| beberlei/assert                    | v3.3.2  | v3.3.3  |
| clue/stream-filter                 | v1.6.0  | v1.7.0  |
+------------------------------------+---------+---------+

+----------------------+---------+---------+
| Indirect Dev Changes | From    | To      |
+----------------------+---------+---------+
| phpstan/phpstan      | 1.12.10 | 1.12.11 |
+----------------------+---------+---------+
  • Loading branch information
cweiske committed Nov 28, 2024
1 parent 17406f2 commit ac363d4
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions composer-lock-diff
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ if ($opts['md']) {
}

$table_titles = array(
'changes' => 'Production Changes',
'changes-dev' => 'Dev Changes',
true => array(
'changes' => 'Production Changes',
'changes-dev' => 'Dev Changes',
),
false => array(
'changes' => 'Indirect Production Changes',
'changes-dev' => 'Indirect Dev Changes',
)
);

foreach($changes as $k => $diff) {
print tableize($table_titles[$k], $diff, $table_opts);
foreach(array(true, false) as $direct) {
foreach($changes as $k => $diff) {
$diff = filterDirect($diff, $direct);
print tableize($table_titles[$direct][$k], $diff, $table_opts);
}
}

function diff($key, $data_from, $data_to) {
Expand Down Expand Up @@ -70,6 +79,18 @@ function diff($key, $data_from, $data_to) {
return $pkgs;
}

function filterDirect($diff, $direct)
{
if (empty($diff)) return $diff;

$filtered = array();
foreach($diff as $key => $v) {
if ($v[3]['direct'] != $direct) continue;
$filtered[$key] = $v;
}
return $filtered;
}

function version($pkg)
{
if((substr($pkg->version,0,4) == 'dev-' || '-dev' === substr($pkg->version, -4)) && isset($pkg->source) && isset($pkg->source->reference)) {
Expand Down Expand Up @@ -104,7 +125,7 @@ function tableize($header, $data, $opts = array()) {

$widths = array(maxLength(array_merge(array($header), array_keys($data))));

$count = 3; // it will always be 3. The fourth item is a properties array
$count = count(reset($data)) - 1;
for($i = 0; $i < $count; $i++) {
$widths[] = max(strlen($titles[$i + 1]), maxLength(array_map(function($k) use ($data, $i) { return $data[$k][$i]; }, array_keys($data))));
}
Expand All @@ -116,17 +137,7 @@ function tableize($header, $data, $opts = array()) {
$lines[] = tabelizeLine($titles, $widths);
$lines[] = separatorLine($widths, $opts['joint']);

$lines[] = fillLine(array("Direct"), '~', $widths);

foreach($data as $key => $v) {
if (! $v[3]['direct']) continue;
$lines[] = tabelizeLine(array_merge(array($key), array_slice($v, 0, $count)), $widths);
}

$lines[] = fillLine(array("Indirect"), '~', $widths);

foreach($data as $key => $v) {
if ($v[3]['direct']) continue;
$lines[] = tabelizeLine(array_merge(array($key), array_slice($v, 0, $count)), $widths);
}

Expand Down Expand Up @@ -542,4 +553,3 @@ EOF;
exit(0);
}
# vim: ff=unix ts=4 ss=4 sr et

0 comments on commit ac363d4

Please sign in to comment.