Skip to content

Commit 5fa7c7b

Browse files
committed
Separate tables for changes in direct and indirect dependencies
Builds upon davidrjonas#41 Resolves: davidrjonas#37 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 | +----------------------+---------+---------+
1 parent 17406f2 commit 5fa7c7b

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

composer-lock-diff

+26-16
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@ if ($opts['md']) {
3434
}
3535

3636
$table_titles = array(
37-
'changes' => 'Production Changes',
38-
'changes-dev' => 'Dev Changes',
37+
true => array(
38+
'changes' => 'Production Changes',
39+
'changes-dev' => 'Dev Changes',
40+
),
41+
false => array(
42+
'changes' => 'Indirect Production Changes',
43+
'changes-dev' => 'Indirect Dev Changes',
44+
)
3945
);
4046

41-
foreach($changes as $k => $diff) {
42-
print tableize($table_titles[$k], $diff, $table_opts);
47+
foreach(array(true, false) as $direct) {
48+
foreach($changes as $k => $diff) {
49+
$diff = filterDirect($diff, $direct);
50+
print tableize($table_titles[$direct][$k], $diff, $table_opts);
51+
}
4352
}
4453

4554
function diff($key, $data_from, $data_to) {
@@ -70,6 +79,18 @@ function diff($key, $data_from, $data_to) {
7079
return $pkgs;
7180
}
7281

82+
function filterDirect($diff, $direct)
83+
{
84+
if (empty($diff)) return $diff;
85+
86+
$filtered = array();
87+
foreach($diff as $key => $v) {
88+
if ($v[3]['direct'] != $direct) continue;
89+
$filtered[$key] = $v;
90+
}
91+
return $filtered;
92+
}
93+
7394
function version($pkg)
7495
{
7596
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()) {
104125

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

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

119-
$lines[] = fillLine(array("Direct"), '~', $widths);
120-
121140
foreach($data as $key => $v) {
122-
if (! $v[3]['direct']) continue;
123-
$lines[] = tabelizeLine(array_merge(array($key), array_slice($v, 0, $count)), $widths);
124-
}
125-
126-
$lines[] = fillLine(array("Indirect"), '~', $widths);
127-
128-
foreach($data as $key => $v) {
129-
if ($v[3]['direct']) continue;
130141
$lines[] = tabelizeLine(array_merge(array($key), array_slice($v, 0, $count)), $widths);
131142
}
132143

@@ -542,4 +553,3 @@ EOF;
542553
exit(0);
543554
}
544555
# vim: ff=unix ts=4 ss=4 sr et
545-

0 commit comments

Comments
 (0)