From ac363d40390f84d3695a2e6394a60163917a27e6 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 28 Nov 2024 12:27:44 +0100 Subject: [PATCH] Separate tables for changes in direct and indirect dependencies Builds upon https://github.com/davidrjonas/composer-lock-diff/pull/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 | +----------------------+---------+---------+ --- composer-lock-diff | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/composer-lock-diff b/composer-lock-diff index 2818ee6..1332cb6 100755 --- a/composer-lock-diff +++ b/composer-lock-diff @@ -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) { @@ -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)) { @@ -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)))); } @@ -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); } @@ -542,4 +553,3 @@ EOF; exit(0); } # vim: ff=unix ts=4 ss=4 sr et -