Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dir-compare

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dir-compare - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

src/cli/dircompare.js

15

package.json
{
"name": "dir-compare",
"version": "2.0.0",
"version": "2.0.1",
"description": "Node JS directory compare",

@@ -20,3 +20,2 @@ "main": "src/index.js",

"dependencies": {
"bluebird": "3.4.1",
"buffer-equal": "1.0.0",

@@ -41,13 +40,13 @@ "colors": "1.0.3",

"bin": {
"dircompare": "src/dircompare.js"
"dircompare": "src/cli/dircompare.js"
},
"scripts": {
"clean": "rm -rf build && rm -rf .nyc_output && rm -rf coverage && rm -rf docs",
"copydeps": "copyfiles \"tests/expected/**\" tests/testdir.tar package.json build",
"clean": "rm -rf build && rm -rf .nyc_output && rm -rf coverage",
"copydeps": "copyfiles \"test/expected/**\" test/testdir.tar package.json build",
"build": "tsc && npm run copydeps",
"lint": "tslint -p tsconfig.json",
"pretest": "npm install && npm run build",
"test": "node build/tests/runTests.js",
"extest": "npm run pretest && ./tests/extended/init.sh && tests/extended/runall.sh",
"coverage": "npx nyc --exclude \"build/tests/**\" --reporter=lcov npm test && npx nyc report",
"test": "node build/test/runTests.js",
"extest": "npm run pretest && ./test/extended/init.sh && test/extended/runall.sh",
"coverage": "npx nyc --exclude \"build/test/**\" --reporter=lcov npm test && npx nyc report",
"toc": "npx markdown-toc README.md; echo \n",

@@ -54,0 +53,0 @@ "docs": "npx typedoc --includeDeclarations --excludeExternals --theme minimal --mode file --readme none --gitRevision master --toc compare,compareSync,fileCompareHandlers,Options,Result --out docs ./src/index.d.ts"

@@ -152,3 +152,3 @@ dir-compare

## Api
<a href="https://htmlpreview.github.io/?https://raw.githubusercontent.com/gliviu/dir-compare/master/docs/index.html" target="_blank">Api Docs</a>
<a href="https://gliviu.github.io/dc-api/" target="_blank">Api Docs</a>

@@ -300,2 +300,3 @@ ## Glob patterns

# Changelog
* v2.1.0 remove [bluebird](https://github.com/petkaantonov/bluebird/#note) dependency
* v2.0.0

@@ -302,0 +303,0 @@ * New option to compare symlinks.

var fs = require('fs')
var common = require('./common')
var compareRules = require('./compareEntry')
var stats = require('./stats')
var entryBuilder = require('./entry/entryBuilder')
var entryEquality = require('./entry/entryEquality')
var stats = require('./statistics/statisticsUpdate')
var pathUtils = require('path')
var Promise = require('bluebird')
var fsPromise = require('./fsPromise')
var fsPromise = require('./fs/fsPromise')
var loopDetector = require('./symlink/loopDetector')
var entryComparator = require('./entry/entryComparator')
var entryType = require('./entry/entryType')

@@ -19,3 +21,3 @@ /**

.then(function (entries) {
return common.buildDirEntries(rootEntry, entries, relativePath, options)
return entryBuilder.buildDirEntries(rootEntry, entries, relativePath, options)
})

@@ -30,19 +32,6 @@ }

var compare = function (rootEntry1, rootEntry2, level, relativePath, options, statistics, diffSet, symlinkCache) {
symlinkCache = symlinkCache || {
dir1: {},
dir2: {}
}
var loopDetected1 = common.detectLoop(rootEntry1, symlinkCache.dir1)
var loopDetected2 = common.detectLoop(rootEntry2, symlinkCache.dir2)
var loopDetected1 = loopDetector.detectLoop(rootEntry1, symlinkCache.dir1)
var loopDetected2 = loopDetector.detectLoop(rootEntry2, symlinkCache.dir2)
loopDetector.updateSymlinkCache(symlinkCache, rootEntry1, rootEntry2, loopDetected1, loopDetected2)
var symlinkCachePath1, symlinkCachePath2
if (rootEntry1 && !loopDetected1) {
symlinkCachePath1 = rootEntry1.isSymlink ? fs.realpathSync(rootEntry1.absolutePath) : rootEntry1.absolutePath
symlinkCache.dir1[symlinkCachePath1] = true
}
if (rootEntry2 && !loopDetected2) {
symlinkCachePath2 = rootEntry2.isSymlink ? fs.realpathSync(rootEntry2.absolutePath) : rootEntry2.absolutePath
symlinkCache.dir2[symlinkCachePath2] = true
}
return Promise.all([getEntries(rootEntry1, relativePath, loopDetected1, options), getEntries(rootEntry2, relativePath, loopDetected2, options)]).then(

@@ -65,12 +54,12 @@ function (entriesResult) {

if (i1 < entries1.length && i2 < entries2.length) {
cmp = options.ignoreCase ? common.compareEntryIgnoreCase(entry1, entry2) : common.compareEntryCaseSensitive(entry1, entry2)
type1 = common.getType(entry1)
type2 = common.getType(entry2)
cmp = options.ignoreCase ? entryComparator.compareEntryIgnoreCase(entry1, entry2) : entryComparator.compareEntryCaseSensitive(entry1, entry2)
type1 = entryType.getType(entry1)
type2 = entryType.getType(entry2)
} else if (i1 < entries1.length) {
type1 = common.getType(entry1)
type2 = common.getType(undefined)
type1 = entryType.getType(entry1)
type2 = entryType.getType(undefined)
cmp = -1
} else {
type1 = common.getType(undefined)
type2 = common.getType(entry2)
type1 = entryType.getType(undefined)
type2 = entryType.getType(entry2)
cmp = 1

@@ -82,3 +71,3 @@ }

// Both left/right exist and have the same name and type
var compareAsyncRes = compareRules.compareEntryAsync(entry1, entry2, type1, diffSet, options)
var compareAsyncRes = entryEquality.isEntryEqualAsync(entry1, entry2, type1, diffSet, options)
var samePromise = compareAsyncRes.samePromise

@@ -105,3 +94,3 @@ var same = compareAsyncRes.same

pathUtils.join(relativePath, entry1.name),
options, statistics, subDiffSet, common.cloneSymlinkCache(symlinkCache)))
options, statistics, subDiffSet, loopDetector.cloneSymlinkCache(symlinkCache)))
}

@@ -120,3 +109,3 @@ } else if (cmp < 0) {

level + 1,
pathUtils.join(relativePath, entry1.name), options, statistics, subDiffSet, common.cloneSymlinkCache(symlinkCache)))
pathUtils.join(relativePath, entry1.name), options, statistics, subDiffSet, loopDetector.cloneSymlinkCache(symlinkCache)))
}

@@ -135,3 +124,3 @@ } else {

level + 1,
pathUtils.join(relativePath, entry2.name), options, statistics, subDiffSet, common.cloneSymlinkCache(symlinkCache)))
pathUtils.join(relativePath, entry2.name), options, statistics, subDiffSet, loopDetector.cloneSymlinkCache(symlinkCache)))
}

@@ -138,0 +127,0 @@ }

var fs = require('fs')
var pathUtils = require('path')
var common = require('./common')
var compareRules = require('./compareEntry')
var stats = require('./stats')
var entryBuilder = require('./entry/entryBuilder')
var entryEquality = require('./entry/entryEquality')
var stats = require('./statistics/statisticsUpdate')
var loopDetector = require('./symlink/loopDetector')
var entryComparator = require('./entry/entryComparator')
var entryType = require('./entry/entryType')

@@ -16,3 +19,3 @@ /**

var entries = fs.readdirSync(rootEntry.absolutePath)
return common.buildDirEntries(rootEntry, entries, relativePath, options)
return entryBuilder.buildDirEntries(rootEntry, entries, relativePath, options)
}

@@ -26,18 +29,6 @@ return [rootEntry]

var compare = function (rootEntry1, rootEntry2, level, relativePath, options, statistics, diffSet, symlinkCache) {
symlinkCache = symlinkCache || {
dir1: {},
dir2: {}
}
var loopDetected1 = common.detectLoop(rootEntry1, symlinkCache.dir1)
var loopDetected2 = common.detectLoop(rootEntry2, symlinkCache.dir2)
var loopDetected1 = loopDetector.detectLoop(rootEntry1, symlinkCache.dir1)
var loopDetected2 = loopDetector.detectLoop(rootEntry2, symlinkCache.dir2)
loopDetector.updateSymlinkCache(symlinkCache, rootEntry1, rootEntry2, loopDetected1, loopDetected2)
var symlinkCachePath1, symlinkCachePath2
if (rootEntry1 && !loopDetected1) {
symlinkCachePath1 = rootEntry1.isSymlink ? fs.realpathSync(rootEntry1.absolutePath) : rootEntry1.absolutePath
symlinkCache.dir1[symlinkCachePath1] = true
}
if (rootEntry2 && !loopDetected2) {
symlinkCachePath2 = rootEntry2.isSymlink ? fs.realpathSync(rootEntry2.absolutePath) : rootEntry2.absolutePath
symlinkCache.dir2[symlinkCachePath2] = true
}
var entries1 = getEntries(rootEntry1, relativePath, loopDetected1, options)

@@ -54,12 +45,12 @@ var entries2 = getEntries(rootEntry2, relativePath, loopDetected2, options)

if (i1 < entries1.length && i2 < entries2.length) {
cmp = options.ignoreCase ? common.compareEntryIgnoreCase(entry1, entry2) : common.compareEntryCaseSensitive(entry1, entry2)
type1 = common.getType(entry1)
type2 = common.getType(entry2)
cmp = options.ignoreCase ? entryComparator.compareEntryIgnoreCase(entry1, entry2) : entryComparator.compareEntryCaseSensitive(entry1, entry2)
type1 = entryType.getType(entry1)
type2 = entryType.getType(entry2)
} else if (i1 < entries1.length) {
type1 = common.getType(entry1)
type2 = common.getType(undefined)
type1 = entryType.getType(entry1)
type2 = entryType.getType(undefined)
cmp = -1
} else {
type1 = common.getType(undefined)
type2 = common.getType(entry2)
type1 = entryType.getType(undefined)
type2 = entryType.getType(entry2)
cmp = 1

@@ -71,3 +62,3 @@ }

// Both left/right exist and have the same name and type
var compareEntryRes = compareRules.compareEntrySync(entry1, entry2, type1, options)
var compareEntryRes = entryEquality.isEntryEqualSync(entry1, entry2, type1, options)
options.resultBuilder(entry1, entry2,

@@ -81,3 +72,3 @@ compareEntryRes.same ? 'equal' : 'distinct',

if (!options.skipSubdirs && type1 === 'directory') {
compare(entry1, entry2, level + 1, pathUtils.join(relativePath, entry1.name), options, statistics, diffSet, common.cloneSymlinkCache(symlinkCache))
compare(entry1, entry2, level + 1, pathUtils.join(relativePath, entry1.name), options, statistics, diffSet, loopDetector.cloneSymlinkCache(symlinkCache))
}

@@ -90,3 +81,3 @@ } else if (cmp < 0) {

if (type1 === 'directory' && !options.skipSubdirs) {
compare(entry1, undefined, level + 1, pathUtils.join(relativePath, entry1.name), options, statistics, diffSet, common.cloneSymlinkCache(symlinkCache))
compare(entry1, undefined, level + 1, pathUtils.join(relativePath, entry1.name), options, statistics, diffSet, loopDetector.cloneSymlinkCache(symlinkCache))
}

@@ -99,3 +90,3 @@ } else {

if (type2 === 'directory' && !options.skipSubdirs) {
compare(undefined, entry2, level + 1, pathUtils.join(relativePath, entry2.name), options, statistics, diffSet, common.cloneSymlinkCache(symlinkCache))
compare(undefined, entry2, level + 1, pathUtils.join(relativePath, entry2.name), options, statistics, diffSet, loopDetector.cloneSymlinkCache(symlinkCache))
}

@@ -102,0 +93,0 @@ }

@@ -398,3 +398,3 @@ /// <reference types="node" />

/**
* Reft entry modification date (stat.mtime).
* Right entry modification date (stat.mtime).
*/

@@ -401,0 +401,0 @@ date2?: number

var util = require('util')
var pathUtils = require('path')
var fs = require('fs')
var Promise = require('bluebird')
var compareSyncInternal = require('./compareSync')
var compareAsyncInternal = require('./compareAsync')
var defaultResultBuilderCallback = require('./defaultResultBuilderCallback')
var defaultFileCompare = require('./file_compare_handlers/defaultFileCompare')
var lineBasedFileCompare = require('./file_compare_handlers/lineBasedFileCompare')
var common = require('./common')
var stats = require('./stats')
var defaultResultBuilderCallback = require('./resultBuilder/defaultResultBuilderCallback')
var defaultFileCompare = require('./fileCompareHandler/defaultFileCompare')
var lineBasedFileCompare = require('./fileCompareHandler/lineBasedFileCompare')
var entryBuilder = require('./entry/entryBuilder')
var statsLifecycle = require('./statistics/statisticsLifecycle')
var loopDetector = require('./symlink/loopDetector')

@@ -25,8 +25,8 @@ var ROOT_PATH = pathUtils.sep

}
var statistics = stats.initStats(options)
var statistics = statsLifecycle.initStats(options)
compareSyncInternal(
common.buildEntry(absolutePath1, path1, pathUtils.basename(absolutePath1)),
common.buildEntry(absolutePath2, path2, pathUtils.basename(absolutePath2)),
0, ROOT_PATH, options, statistics, diffSet)
stats.completeStatistics(statistics, options)
entryBuilder.buildEntry(absolutePath1, path1, pathUtils.basename(absolutePath1)),
entryBuilder.buildEntry(absolutePath2, path2, pathUtils.basename(absolutePath2)),
0, ROOT_PATH, options, statistics, diffSet, loopDetector.initSymlinkCache())
statsLifecycle.completeStatistics(statistics, options)
statistics.diffSet = diffSet

@@ -38,3 +38,13 @@

var wrapper = {
realPath: Promise.promisify(fs.realpath),
realPath: function(path, options) {
return new Promise(function (resolve, reject) {
fs.realpath(path, options, function(err, resolvedPath) {
if(err){
reject(err)
} else {
resolve(resolvedPath)
}
})
})
}
}

@@ -62,9 +72,9 @@

}
var statistics = stats.initStats(options)
var statistics = statsLifecycle.initStats(options)
return compareAsyncInternal(
common.buildEntry(absolutePath1, path1, pathUtils.basename(path1)),
common.buildEntry(absolutePath2, path2, pathUtils.basename(path2)),
0, ROOT_PATH, options, statistics, asyncDiffSet).then(
entryBuilder.buildEntry(absolutePath1, path1, pathUtils.basename(path1)),
entryBuilder.buildEntry(absolutePath2, path2, pathUtils.basename(path2)),
0, ROOT_PATH, options, statistics, asyncDiffSet, loopDetector.initSymlinkCache()).then(
function () {
stats.completeStatistics(statistics, options)
statsLifecycle.completeStatistics(statistics, options)
if (!options.noDiffSet) {

@@ -71,0 +81,0 @@ var diffSet = []

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc