dir-compare
Advanced tools
Comparing version 1.5.3 to 1.5.4
@@ -8,3 +8,3 @@ var fs = require('fs'); | ||
if(entry && entry.symlink){ | ||
var realPath = fs.realpathSync(entry.path); | ||
var realPath = fs.realpathSync(entry.absolutePath); | ||
if(symlinkCache[realPath]){ | ||
@@ -32,8 +32,9 @@ return true; | ||
buildEntry : function(path, name){ | ||
var statEntry = fs.statSync(path); | ||
var lstatEntry = fs.lstatSync(path); | ||
buildEntry : function(absolutePath, path, name){ | ||
var statEntry = fs.statSync(absolutePath); | ||
var lstatEntry = fs.lstatSync(absolutePath); | ||
var isSymlink = lstatEntry.isSymbolicLink(); | ||
return { | ||
name : name, | ||
absolutePath: absolutePath, | ||
path : path, | ||
@@ -40,0 +41,0 @@ stat : statEntry, |
@@ -12,18 +12,19 @@ var fs = require('fs'); | ||
*/ | ||
var getEntries = function (path, options, loopDetected) { | ||
if (!path || loopDetected) { | ||
var getEntries = function (absolutePath, path, options, loopDetected) { | ||
if (!absolutePath || loopDetected) { | ||
return Promise.resolve([]); | ||
} else{ | ||
return fsPromise.stat(path).then( | ||
return fsPromise.stat(absolutePath).then( | ||
function(statPath){ | ||
if(statPath.isDirectory()){ | ||
return fsPromise.readdir(path).then( | ||
return fsPromise.readdir(absolutePath).then( | ||
function(rawEntries){ | ||
return buildEntries(path, rawEntries, options); | ||
return buildEntries(absolutePath, path, rawEntries, options); | ||
}); | ||
} else{ | ||
var name = pathUtils.basename(path); | ||
var name = pathUtils.basename(absolutePath); | ||
return [ | ||
{ | ||
name : name, | ||
absolutePath: absolutePath, | ||
path : path, | ||
@@ -41,6 +42,6 @@ stat : statPath, | ||
var buildEntries = function(path, rawEntries, options){ | ||
var buildEntries = function(absolutePath, path, rawEntries, options){ | ||
var promisedEntries = []; | ||
rawEntries.forEach(function (entryName) { | ||
promisedEntries.push(buildEntry(path, entryName, options)); | ||
promisedEntries.push(buildEntry(absolutePath, path, entryName, options)); | ||
}); | ||
@@ -60,5 +61,6 @@ return Promise.all(promisedEntries).then( | ||
var buildEntry = function(path, entryName, options){ | ||
var buildEntry = function(absolutePath, path, entryName, options){ | ||
var entryAbsolutePath = absolutePath + PATH_SEP + entryName; | ||
var entryPath = path + PATH_SEP + entryName; | ||
return Promise.resolve(fsPromise.lstat(entryPath)).then(function(lstatEntry){ | ||
return Promise.resolve(fsPromise.lstat(entryAbsolutePath)).then(function(lstatEntry){ | ||
var isSymlink = lstatEntry.isSymbolicLink(); | ||
@@ -69,3 +71,3 @@ var statPromise; | ||
} else{ | ||
statPromise = fsPromise.stat(entryPath); | ||
statPromise = fsPromise.stat(entryAbsolutePath); | ||
} | ||
@@ -75,2 +77,3 @@ return statPromise.then(function(statEntry){ | ||
name : entryName, | ||
absolutePath : entryAbsolutePath, | ||
path : entryPath, | ||
@@ -101,13 +104,15 @@ stat : statEntry, | ||
if(rootEntry1 && !loopDetected1){ | ||
symlinkCachePath1 = rootEntry1.symlink?fs.realpathSync(rootEntry1.path):rootEntry1.path; | ||
symlinkCachePath1 = rootEntry1.symlink?fs.realpathSync(rootEntry1.absolutePath):rootEntry1.absolutePath; | ||
symlinkCache.dir1[symlinkCachePath1] = true; | ||
} | ||
if(rootEntry2 && !loopDetected2){ | ||
symlinkCachePath2 = rootEntry2.symlink?fs.realpathSync(rootEntry2.path):rootEntry2.path; | ||
symlinkCachePath2 = rootEntry2.symlink?fs.realpathSync(rootEntry2.absolutePath):rootEntry2.absolutePath; | ||
symlinkCache.dir2[symlinkCachePath2] = true; | ||
} | ||
var absolutePath1 = rootEntry1?rootEntry1.absolutePath:undefined; | ||
var absolutePath2 = rootEntry2?rootEntry2.absolutePath:undefined; | ||
var path1 = rootEntry1?rootEntry1.path:undefined; | ||
var path2 = rootEntry2?rootEntry2.path:undefined; | ||
return Promise.all([getEntries(path1, options, loopDetected1), getEntries(path2, options, loopDetected2)]).then( | ||
return Promise.all([getEntries(absolutePath1, path1, options, loopDetected1), getEntries(absolutePath2, path2, options, loopDetected2)]).then( | ||
function(entriesResult){ | ||
@@ -125,4 +130,4 @@ var entries1 = entriesResult[0]; | ||
var n2 = entry2 ? entry2.name : undefined; | ||
var p1 = entry1 ? entry1.path : undefined; | ||
var p2 = entry2 ? entry2.path : undefined; | ||
var p1 = entry1 ? entry1.absolutePath : undefined; | ||
var p2 = entry2 ? entry2.absolutePath : undefined; | ||
var fileStat1 = entry1 ? entry1.stat : undefined; | ||
@@ -129,0 +134,0 @@ var fileStat2 = entry2 ? entry2.stat : undefined; |
@@ -10,14 +10,15 @@ var fs = require('fs'); | ||
*/ | ||
var getEntries = function (path, options) { | ||
if (!path) { | ||
var getEntries = function (absolutePath, path, options) { | ||
if (!absolutePath) { | ||
return []; | ||
} else { | ||
var statPath = fs.statSync(path); | ||
var statPath = fs.statSync(absolutePath); | ||
if (statPath.isDirectory()) { | ||
var entries = fs.readdirSync(path); | ||
var entries = fs.readdirSync(absolutePath); | ||
var res = []; | ||
entries.forEach(function (entryName) { | ||
var entryAbsolutePath = absolutePath + PATH_SEP + entryName; | ||
var entryPath = path + PATH_SEP + entryName; | ||
var lstatEntry = fs.lstatSync(entryPath); | ||
var lstatEntry = fs.lstatSync(entryAbsolutePath); | ||
var isSymlink = lstatEntry.isSymbolicLink(); | ||
@@ -28,6 +29,7 @@ var statEntry; | ||
} else{ | ||
statEntry = fs.statSync(entryPath); | ||
statEntry = fs.statSync(entryAbsolutePath); | ||
} | ||
var entry = { | ||
name : entryName, | ||
absolutePath : entryAbsolutePath, | ||
path : entryPath, | ||
@@ -47,6 +49,7 @@ stat : statEntry, | ||
} else { | ||
var name = pathUtils.basename(path); | ||
var name = pathUtils.basename(absolutePath); | ||
return [ | ||
{ | ||
name : name, | ||
absolutePath: absolutePath, | ||
path : path, | ||
@@ -77,13 +80,15 @@ stat : statPath, | ||
if(rootEntry1 && !loopDetected1){ | ||
symlinkCachePath1 = rootEntry1.symlink?fs.realpathSync(rootEntry1.path):rootEntry1.path; | ||
symlinkCachePath1 = rootEntry1.symlink?fs.realpathSync(rootEntry1.absolutePath):rootEntry1.absolutePath; | ||
symlinkCache.dir1[symlinkCachePath1] = true; | ||
} | ||
if(rootEntry2 && !loopDetected2){ | ||
symlinkCachePath2 = rootEntry2.symlink?fs.realpathSync(rootEntry2.path):rootEntry2.path; | ||
symlinkCachePath2 = rootEntry2.symlink?fs.realpathSync(rootEntry2.absolutePath):rootEntry2.absolutePath; | ||
symlinkCache.dir2[symlinkCachePath2] = true; | ||
} | ||
var absolutePath1 = rootEntry1?rootEntry1.absolutePath:undefined; | ||
var absolutePath2 = rootEntry2?rootEntry2.absolutePath:undefined; | ||
var path1 = rootEntry1?rootEntry1.path:undefined; | ||
var path2 = rootEntry2?rootEntry2.path:undefined; | ||
var entries1 = loopDetected1?[]:getEntries(path1, options); | ||
var entries2 = loopDetected2?[]:getEntries(path2, options); | ||
var entries1 = loopDetected1?[]:getEntries(absolutePath1, path1, options); | ||
var entries2 = loopDetected2?[]:getEntries(absolutePath2, path2, options); | ||
var i1 = 0, i2 = 0; | ||
@@ -95,4 +100,4 @@ while (i1 < entries1.length || i2 < entries2.length) { | ||
var n2 = entry2 ? entry2.name : undefined; | ||
var p1 = entry1 ? entry1.path : undefined; | ||
var p2 = entry2 ? entry2.path : undefined; | ||
var p1 = entry1 ? entry1.absolutePath : undefined; | ||
var p2 = entry2 ? entry2.absolutePath : undefined; | ||
var fileStat1 = entry1 ? entry1.stat : undefined; | ||
@@ -99,0 +104,0 @@ var fileStat2 = entry2 ? entry2.stat : undefined; |
'use strict' | ||
var pathUtils = require('path'); | ||
var common = require('./common'); | ||
var common = require('./common'); | ||
@@ -22,2 +22,2 @@ module.exports = function (entry1, entry2, state, level, relativePath, options, statistics, diffSet) { | ||
}); | ||
}; | ||
}; |
17
index.js
@@ -14,4 +14,4 @@ var util = require('util'); | ||
// realpathSync() is necessary for loop detection to work properly | ||
path1 = pathUtils.normalize(pathUtils.resolve(fs.realpathSync(path1))) | ||
path2 = pathUtils.normalize(pathUtils.resolve(fs.realpathSync(path2))) | ||
var absolutePath1 = pathUtils.normalize(pathUtils.resolve(fs.realpathSync(path1))) | ||
var absolutePath2 = pathUtils.normalize(pathUtils.resolve(fs.realpathSync(path2))) | ||
var statistics = { | ||
@@ -38,4 +38,4 @@ distinct : 0, | ||
compareSyncInternal( | ||
common.buildEntry(path1, pathUtils.basename(path1)), | ||
common.buildEntry(path2, pathUtils.basename(path2)), | ||
common.buildEntry(absolutePath1, path1, pathUtils.basename(absolutePath1)), | ||
common.buildEntry(absolutePath2, path2, pathUtils.basename(absolutePath2)), | ||
0, '', options, statistics, diffSet); | ||
@@ -54,2 +54,3 @@ completeStatistics(statistics); | ||
'use strict'; | ||
var absolutePath1, absolutePath2 | ||
return Promise.resolve() | ||
@@ -63,4 +64,4 @@ .then(function(){ | ||
// realpath() is necessary for loop detection to work properly | ||
path1 = pathUtils.normalize(pathUtils.resolve(realPath1)) | ||
path2 = pathUtils.normalize(pathUtils.resolve(realPath2)) | ||
absolutePath1 = pathUtils.normalize(pathUtils.resolve(realPath1)) | ||
absolutePath2 = pathUtils.normalize(pathUtils.resolve(realPath2)) | ||
}) | ||
@@ -89,4 +90,4 @@ .then(function(){ | ||
return compareAsyncInternal( | ||
common.buildEntry(path1, pathUtils.basename(path1)), | ||
common.buildEntry(path2, pathUtils.basename(path2)), | ||
common.buildEntry(absolutePath1, path1, pathUtils.basename(path1)), | ||
common.buildEntry(absolutePath2, path2, pathUtils.basename(path2)), | ||
0, '', options, statistics, asyncDiffSet).then( | ||
@@ -93,0 +94,0 @@ function(){ |
{ | ||
"name": "dir-compare", | ||
"version": "1.5.3", | ||
"version": "1.5.4", | ||
"description": "Node JS directory compare", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -113,5 +113,5 @@ dir-compare | ||
* diffSet - List of changes (present if Options.noDiffSet is false) | ||
* path1: absolute path not including file/directory name, | ||
* path2: absolute path not including file/directory name, | ||
* relativePath: common path relative to root, | ||
* path1: path not including file/directory name; can be relative or absolute depending on call to compare(), | ||
* path2: path not including file/directory name; can be relative or absolute depending on call to compare(), | ||
* relativePath: path relative to root, | ||
* name1: file/directory name | ||
@@ -118,0 +118,0 @@ * name2: file/directory name |
@@ -88,3 +88,4 @@ // Usage: node runTests [unpacked] [test000_0] [show-result] | ||
*/ | ||
var tests = [ | ||
var getTests = function(testDirPath){ | ||
var res = [ | ||
{ | ||
@@ -672,4 +673,43 @@ name: 'test001_1', path1: 'd1', path2: 'd2', | ||
}, | ||
//////////////////////////////////////////////////// | ||
// Relative paths // | ||
//////////////////////////////////////////////////// | ||
{ | ||
name: 'test012_0', path1: 'd1', path2: 'd2', | ||
description: 'should report relative paths', | ||
options: {}, | ||
onlyLibrary: true, | ||
withRelativePath: true, | ||
print: function(res, writer, program){printRelativePathResult(res, testDirPath, writer)} | ||
}, | ||
{ | ||
name: 'test012_1', path1: 'd1/A6/../../d1', path2: 'd2', | ||
description: 'should report absolute paths', | ||
options: {}, | ||
onlyLibrary: true, | ||
withRelativePath: false, | ||
print: function(res, writer, program){printRelativePathResult(res, testDirPath, writer)} | ||
}, | ||
{ | ||
name: 'test012_2', path1: testDirPath+'/d1', path2: 'd2', | ||
description: 'should report absolute and relative paths', | ||
options: {}, | ||
onlyLibrary: true, | ||
withRelativePath: true, | ||
print: function(res, writer, program){printRelativePathResult(res, testDirPath, writer)} | ||
}, | ||
]; | ||
return res; | ||
} | ||
var printRelativePathResult = function(res, testDirPath, writer) { | ||
var result = res.diffSet.map(function(diff){ | ||
return util.format('path1: %s, path2: %s', | ||
diff.path1, diff.path2)}); | ||
result = JSON.stringify(result) | ||
result = result.replace(/\\\\/g, "/") | ||
result = result.replace(new RegExp(testDirPath.replace(/\\/g, "/"), 'g'), 'absolute_path') | ||
writer.write(result); | ||
} | ||
//Matches date (ie 2014-11-18T21:32:39.000Z) | ||
@@ -893,3 +933,3 @@ var normalizeDateRegexp = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/gm; | ||
initReport(saveReport); | ||
Promise.resolve(tests).then(function(tests){ | ||
Promise.resolve(getTests(testDirPath)).then(function(tests){ | ||
// Run sync tests | ||
@@ -911,3 +951,3 @@ var syncTestsPromises = []; | ||
var asyncTestsPromises = []; | ||
tests.filter(function(test){return !test.onlyCommandLine;}) | ||
getTests(testDirPath).filter(function(test){return !test.onlyCommandLine;}) | ||
.filter(function(test){return !test.onlySync;}) | ||
@@ -927,3 +967,3 @@ .filter(function(test){return test.nodeVersionSupport===undefined || semver.satisfies(process.version, test.nodeVersionSupport) }) | ||
var commandLinePromises = []; | ||
tests.filter(function(test){return !test.onlyLibrary;}) | ||
getTests(testDirPath).filter(function(test){return !test.onlyLibrary;}) | ||
.filter(function(test){return test.nodeVersionSupport===undefined || semver.satisfies(process.version, test.nodeVersionSupport) }) | ||
@@ -930,0 +970,0 @@ .filter(function(test){return singleTestName?test.name===singleTestName:true;}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
323883
85
2448