Advertisements

Archive

Archive for February, 2016

Diff compressed Javascript files

February 9, 2016 Leave a comment

I periodically need to find the differences between two javascript files that have been run through something like uglifyjs.  There are a variety of ways to do this, but I haven’t found a solution that really gets me what I am looking for succinctly.

For a while I used git’s diff, but I found this to be cumbersome and not always available.

Then for a while I used wdiff with colordiff.  That would look like this:

wdiff /path/file1.js /path/file2.js | colordiff

The problem with that is that the output is often really long because compressed js doesn’t have many line feeds, and wdiff doesn’t recognize non-word characters as word boundaries, and compressed js often doesn’t have whitespace to deliniate word boundaries, so the strength of wdiff is somewhat thwarted.

What I really wanted was to split the files into their smaller pieces for diffing.  My latest solution is a bash alias, which looks like this in my .bash_alias file:

alias diffjs='function _diffjs(){ diff -w <(uglifyjs "$1" -b) <(uglifyjs "$2" -b); };_diffjs'

Its not perfect, but in many situations it gets me what I want, assuming of course that uglifyjs is available.

Advertisements
Categories: Uncategorized