-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comparing files gives confusing result #48
Comments
The current behavior is exactly as you specified. Initially dir-compare was intended to work with directories. Later I added for convenience the ability to specify files as arguments but failed to make it right as you suggested. I will think about it. It will definitely need to bump a major version as it breaks compatibility. Meanwhile you can use custom-name-comparators to overcome this inconvenience. var dircompare = require('./build/src/index.js');
var options = {
compareSize: true,
compareContent: false,
compareNameHandler: customNameCompare,
compareFiles: true // Change this to 'false' to go back to old behavior
};
var path1 = '/.../test.js';
var path2 = '/.../test2.js';
function customNameCompare(name1, name2, options) {
if(options.compareFiles){
return 0 // ignore differences in file names
}
return ((name1 === name2) ? 0 : ((name1 > name2) ? 1 : -1)) // default name comparator
}
var res = dircompare.compareSync(path1, path2, options); |
Thanks very much for the quick response and workaround! I look forward to an eventual new release. |
Issue fixed in v4.0.0. Lets consider these directories as example.
Following table shows the difference from v3.x to v4.0.0 when calling
|
Thanks very much for this; I was able to simplify my code exactly as I hoped. |
If the arguments to
compareSync
are two files, then the result of comparison is a little odd: it seems they are treated as if they were each contained in a directory, so the files are only considered the same if their names are the same.But
compareSync
applied to two directories compares their contents; it should do the same for files.I came across this issue because I have some code that normally compares directories, but in some cases it may only compare single files, and I had to special case this and not use
dir-compare
for the single files.Thanks for
dir-compare
! A very handy piece of code.The text was updated successfully, but these errors were encountered: