Skip to content

Commit 430edb2

Browse files
committed
Initial commit
0 parents  commit 430edb2

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
composer-lock-diff
2+
==================
3+
4+
See what packages have changed after you run `composer update` by comparing composer.lock to the the git HEAD.
5+
6+
Usage
7+
=====
8+
9+
```bash
10+
composer update
11+
# don't commit yet!
12+
composer-lock-diff
13+
```

composer-lock-diff

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/perl -w
2+
3+
use strict;
4+
use List::Util qw(max);
5+
6+
my $JQ_FILTER = "jq -r '.packages[] | \"\\(.name) \\(.version)\"'";
7+
my $JQ_FILTER_DEV = "sed 's/packages-dev/packages_dev/g' | jq -r '.packages_dev[] | \"\\(.name) \\(.version)\"'";
8+
9+
print "production packages\n===================\n";
10+
print_pkgs(diff($JQ_FILTER));
11+
12+
print "\ndev packages\n============\n";
13+
print_pkgs(diff($JQ_FILTER_DEV));
14+
15+
sub diff {
16+
my $jq_filter = shift;
17+
my %pkgs;
18+
my $fh;
19+
20+
open($fh, "-|", "git show HEAD:composer.lock | $jq_filter | sort") or die "Failed to open before command for reading; $!";
21+
while(<$fh>) {
22+
next unless /^(\S+) (\S+)$/;
23+
$pkgs{$1} = [$2, "REMOVED"];
24+
}
25+
close $fh;
26+
27+
open($fh, "-|", "cat composer.lock | $jq_filter | sort") or die "Failed to open before command for reading; $!";
28+
while(<$fh>) {
29+
next unless /^(\S+) (\S+)$/;
30+
$pkgs{$1} = ["NEW", 0] unless defined $pkgs{$1};
31+
if ($pkgs{$1}[0] eq $2) {
32+
delete $pkgs{$1};
33+
} else {
34+
$pkgs{$1}[1] = $2;
35+
}
36+
}
37+
close $fh;
38+
39+
return \%pkgs;
40+
}
41+
42+
sub print_pkgs {
43+
my $pkgs = shift;
44+
my $pkg_width = max_len(keys %$pkgs) + 1;
45+
my $before_width = max_len(map { $pkgs->{$_}[0] } keys %$pkgs);
46+
for my $k (keys %$pkgs) {
47+
printf "%-${pkg_width}s %-${before_width}s => %s\n", $k, $pkgs->{$k}[0], $pkgs->{$k}[1];
48+
}
49+
}
50+
51+
sub max_len {
52+
return max map { length } @_;
53+
}
54+

0 commit comments

Comments
 (0)