{"name":"dir-compare","version":"1.4.0","description":"Node JS directory compare","main":"index.js","repository":{"type":"git","url":"https://github.com/gliviu/dir-compare"},"keywords":["compare","directory","folder"],"dependencies":{"buffer-equal":"1.0.0","colors":"1.0.3","commander":"2.9.0","minimatch":"3.0.2","bluebird":"3.4.1"},"devDependencies":{"shelljs":"0.3.0","tar-fs":"1.13.0","temp":"0.8.1","istanbul":"0.4.4","memory-streams":"0.1.0"},"bin":{"dircompare":"dircompare.js"},"scripts":{"test":"istanbul cover tests/runTests.js"},"author":{"name":"Liviu Grigorescu"},"license":"MIT","bugs":{"url":"https://github.com/gliviu/dir-compare/issues"},"gitHead":"83a37aeddbb1e0c209d897fa4b28eff1bdd26aec","homepage":"https://github.com/gliviu/dir-compare","_id":"dir-compare@1.4.0","_shasum":"afa00ab99c0fb1c412b48dc65e8f4378d257f006","_from":".","_npmVersion":"1.4.14","_npmUser":{"name":"gliviu","email":"grigoresculiviu@gmail.com"},"maintainers":[{"name":"gliviu","email":"grigoresculiviu@gmail.com"}],"dist":{"shasum":"afa00ab99c0fb1c412b48dc65e8f4378d257f006","tarball":"http://registry-npm.ywwl.com/dir-compare/download/dir-compare-1.4.0.tgz","integrity":"sha512-GAdfFi3/YYjZ2swW98D9AR39s4AQAIFgKeaCMwZAqNmjvbCiaGsd5JpbI+OgUmYdcwcgK3mCRzZohGIaX0pVvA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD56jugE/kk1H8wsTqQ6bQZWMwRJvfg3bGYUIh63px4EwIgK95odUI1072gPZ569NYrgMZNfBxLFyTm68kV5omWAbw="}],"size":26787,"noattachment":false,"key":"/dir-compare/-/dir-compare-1.4.0.tgz"},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/dir-compare-1.4.0.tgz_1491364974770_0.09905866510234773"},"directories":{},"readme":"dir-compare\n==========\nNode JS directory compare\n\n**Starting with v3.0.0 the CLI utility moved to [dir-compare-cli](https://www.npmjs.com/package/dir-compare-cli).**\n\n[![Build status](https://ci.appveyor.com/api/projects/status/fpnqkr2gfg7pwkxk/branch/master?svg=true)](https://ci.appveyor.com/project/gliviu/dir-compare)\n[![codecov.io](http://codecov.io/github/gliviu/dir-compare/coverage.svg?branch=master)](http://codecov.io/github/gliviu/dir-compare?branch=master)\n\n- [Installation](#installation)\n- [Library](#library)\n  * [Use](#use)\n  * [Api](#api)\n  * [Glob patterns](#glob-patterns)\n  * [Symbolic links](#symbolic-links)\n  * [Handling permission denied errors](#handling-permission-denied-errors)\n- [Extension points](#extension-points)\n  * [File content comparators](#file-content-comparators)\n    + [Ignore line endings and white spaces](#ignore-line-endings-and-white-spaces)\n  * [Glob filter](#glob-filter)\n    + [Implement .gitignore filter](#implement-gitignore-filter)\n  * [Name comparators](#name-comparators)\n  * [Result builder](#result-builder)\n- [UI tools](#ui-tools)\n- [Changelog](#changelog)\n\n# Installation\n```bash\nnpm install dir-compare\n```\n\n# Library\n\n## Use\n```javascript\nconst dircompare = require('dir-compare');\n\nconst options = { compareSize: true };\n// Multiple compare strategy can be used simultaneously - compareSize, compareContent, compareDate, compareSymlink.\n// If one comparison fails for a pair of files, they are considered distinct.\nconst path1 = '...';\nconst path2 = '...';\n\n// Synchronous\nconst res = dircompare.compareSync(path1, path2, options)\nprint(res)\n\n// Asynchronous\ndircompare.compare(path1, path2, options)\n  .then(res => print(res))\n  .catch(error => console.error(error));\n\nfunction print(result) {\n  console.log('Directories are %s', result.same ? 'identical' : 'different')\n\n  console.log('Statistics - equal entries: %s, distinct entries: %s, left only entries: %s, right only entries: %s, differences: %s',\n    result.equal, result.distinct, result.left, result.right, result.differences)\n\n  result.diffSet.forEach(dif => console.log('Difference - path: %s, name1: %s, type1: %s, name2: %s, type2: %s, state: %s',\n    dif.relativePath, dif.name1, dif.type1, dif.name2, dif.type2, dif.state))\n}\n```\n\nTypescript\n```typescript\nimport { compare, compareSync, Options, Result } from \"dir-compare\";\nconst path1 = '...';\nconst path2 = '...';\nconst options: Options = { compareSize: true };\n\nconst res: Result = compareSync(path1, path2, options);\nconsole.log(res)\n\ncompare(path1, path2, options)\n  .then(res => console.log(res))\n  .catch(error => console.error(error));\n```\n\n## Api\n\n```typescript\ncompare(path1: string, path2: string, options?: Options): Promise<Result>\ncompareSync(path1: string, path2: string, options?: Options): Result\n```\nMore details can be found in the reference documentation:\n* [compare](https://gliviu.github.io/dc-api/functions/compare.html)\n* [compareSync](https://gliviu.github.io/dc-api/functions/compareSync.html)\n* [Options](https://gliviu.github.io/dc-api/interfaces/Options.html) \n* [Result](https://gliviu.github.io/dc-api/interfaces/Result.html)\n\nCommon options:\n* [compareSize](https://gliviu.github.io/dc-api/interfaces/Options.html#compareSize)\n* [compareContent](https://gliviu.github.io/dc-api/interfaces/Options.html#compareContent)\n* [compareDate](https://gliviu.github.io/dc-api/interfaces/Options.html#compareDate) \n* [excludeFilter](https://gliviu.github.io/dc-api/interfaces/Options.html#excludeFilter)\n* [includeFilter](https://gliviu.github.io/dc-api/interfaces/Options.html#includeFilter) \n* [ignoreCase](https://gliviu.github.io/dc-api/interfaces/Options.html#ignoreCase) \n* [skipSubdirs](https://gliviu.github.io/dc-api/interfaces/Options.html#skipSubdirs)\n* [skipEmptyDirs](https://gliviu.github.io/dc-api/interfaces/Options.html#skipEmptyDirs)\n\n##  Glob patterns\n[Minimatch](https://www.npmjs.com/package/minimatch) patterns are used to include/exclude files to be compared.\n\nThe pattern is matched against the relative path of the entry being compared.\n\nFollowing examples assume we are comparing two [dir-compare](https://github.com/gliviu/dir-compare) code bases.\n\n```javascript\nconst options = { \n  excludeFilter: \".git,node_modules\",   //  exclude git and node modules directories  \n  excludeFilter: \"expected\"         ,   //  exclude '/tests/expected' directory  \n  excludeFilter: \"/tests/expected\"  ,   //  exclude '/tests/expected' directory  \n  excludeFilter: \"**/expected\"      ,   //  exclude '/tests/expected' directory  \n  excludeFilter: \"**/tests/**/*.js\" ,   //  exclude all js files in '/tests' directory and subdirectories  \n\n  includeFilter: \"*.js,*.yml\"       ,   //  include js and yaml files  \n  includeFilter: \"/tests/**/*.js\"   ,   //  include all js files in '/tests' directory and subdirectories  \n  includeFilter: \"**/tests/**/*.ts\"     //  include all js files in '/tests' directory and subdirectories  \n}\n```\nThis behavior can be changed with [Glob filter extensions](#glob-filter).\n\n\n## Symbolic links\nUnless `compareSymlink` option is used, symbolic links are resolved and any comparison is applied to the file/directory they point to.\n\nCircular loops are handled by breaking the loop as soon as it is detected.\n\nVersion `1.x` treats broken links as `ENOENT: no such file or directory`.  \nSince `2.0` they are treated as a special type of entry - `broken-link` - and are available as stats (`totalBrokenLinks`, `distinctBrokenLinks`, ...).\n\nUsing `compareSymlink` option causes `dircompare` to check symlink values for equality.\nIn this mode two entries with identical names are considered different if\n* one is symlink, the other is not\n* both are symlinks but point to different locations\n\nThese rules are applied in addition to the other comparison modes; ie. by content, by size...\n\nIf entries are different because of symlinks, `reason` will be `different-symlink`. Also statistics summarize differences caused by symbolic links.\n\n## Handling permission denied errors\nUnreadable files or directories are normally reported as errors. The comparison will be interrupted with an `EACCES` exception.\nThis behavior can be altered with [Options.handlePermissionDenied](https://gliviu.github.io/dc-api/interfaces/Options.html#handlePermissionDenied).\n\n# Extension points\n\n## File content comparators\nBy default file content is binary compared. As of version 1.5.0 custom file comparison handlers may be specified.\n\nCustom handlers are specified by `compareFileSync` and `compareFileAsync` options which correspond to `dircompare.compareSync()` or `dircompare.compare()` methods.\n\nA couple of handlers are included in the library:\n* binary sync compare - `dircompare.fileCompareHandlers.defaultFileCompare.compareSync`\n* binary async compare - `dircompare.fileCompareHandlers.defaultFileCompare.compareAsync`\n* text sync compare - `dircompare.fileCompareHandlers.lineBasedFileCompare.compareSync`\n* text async compare - `dircompare.fileCompareHandlers.lineBasedFileCompare.compareAsync`\n\nUse [defaultFileCompare](https://github.com/gliviu/dir-compare/blob/master/src/FileCompareHandler/default/defaultFileCompare.ts) as an example to create your own.\n\n### Ignore line endings and white spaces\nLine based comparator can be used to ignore line ending and white space differences.\n```javascript\nconst dircompare = require('dir-compare');\n\nconst options = {\n  compareContent: true,\n  compareFileSync: dircompare.fileCompareHandlers.lineBasedFileCompare.compareSync,\n  compareFileAsync: dircompare.fileCompareHandlers.lineBasedFileCompare.compareAsync,\n  ignoreLineEnding: true,      // Ignore crlf/lf line ending differences\n  ignoreWhiteSpaces: true,     // Ignore white spaces at the beginning and end of a line (similar to 'diff -b')\n  ignoreAllWhiteSpaces: true,  // Ignore all white space differences (similar to 'diff -w')\n  ignoreEmptyLines: true       // Ignores differences caused by empty lines (similar to 'diff -B')\n};\n\nconst path1 = '...';\nconst path2 = '...';\nconst res = dircompare.compareSync(path1, path2, options);\nconsole.log(res)\n\ndircompare.compare(path1, path2, options)\n.then(res => console.log(res))\n```\n\n## Glob filter\nThe current implementation of the glob filter uses minimatch and is based on [includeFilter and excludeFilter options](#glob-patterns). While it is meant to fit most use cases, [some scenarios](https://github.com/gliviu/dir-compare/issues/67) are not addressed.\n\nUse [filterHandler option](https://gliviu.github.io/dc-api/interfaces/Options.html#filterHandler) to alter this behavior.\n\nThe following example demonstrates how to include only files with a specific extension in our comparison.\n```typescript\nimport { Options, compareSync, Result, FilterHandler, Entry, filterHandlers } from 'dir-compare'\nimport { extname } from 'path'\n\nvar d1 = '...';\nvar d2 = '...';\n\nconst filterByfileExtension: FilterHandler = (entry: Entry, relativePath: string, options: Options): boolean => {\n  if (!options.fileExtension) {\n    // Fallback on the default 'minimatch' implementation\n    return filterHandlers.defaultFilterHandler(entry, relativePath, options)\n  }\n\n  return options.fileExtension === extname(entry.name)\n}\n\nconst options: Options = {\n  compareSize: true,\n  fileExtension: '.txt',\n  filterHandler: filterByfileExtension\n}\n\nconst res: Result = compareSync(d1, d2, options)\n```\n\nFor reference, the default minimatch filter can be found in [defaultFilterHandler](https://github.com/gliviu/dir-compare/blob/master/src/FilterHandler/defaultFilterHandler.ts) which is exposed by [filterHandlers property](https://gliviu.github.io/dc-api/variables/filterHandlers.html).\n\n### Implement .gitignore filter\n[Globby](https://www.npmjs.com/package/globby) library provides the functionality to parse and apply `.gitignore` rules.\nThis is a [sample implementation](https://github.com/gliviu/dir-compare/blob/master/test/extended/gitignoreSupport/gitignoreFilter.ts) that uses globby and dir-compare filter extension.\n\nUsage:\n```typescript\nimport { Options, compareSync, Result} from 'dir-compare'\nimport { getGitignoreFilter } from './gitignoreFilter.js'\n\nvar d1 = '...';\nvar d2 = '...';\n\nconst options: Options = {\n  compareSize: true,\n  filterHandler: getGitignoreFilter(d1, d2),\n  includeFilter: '*.js'  // if present, regular filters are applied after .gitignore rules.\n}\n\nconst res: Result = compareSync(d1, d2, options)\n\n```\n\n## Name comparators\nIf [default](https://github.com/gliviu/dir-compare/blob/master/src/NameCompare/defaultNameCompare.ts) name comparison is not enough, custom behavior can be specified with [compareNameHandler](https://gliviu.github.io/dc-api/interfaces/Options.html#compareNameHandler) option.\nFollowing example adds the possibility to ignore file extensions.\n```typescript\nimport { Options, compare } from 'dir-compare'\nimport path from 'path'\n\nconst options: Options = {\n    compareSize: false,                    // compare only name by disabling size and content criteria\n    compareContent: false,\n    compareNameHandler: customNameCompare, // new name comparator used to ignore extensions\n    ignoreExtension: true,                 // supported by the custom name compare below\n};\n\nfunction customNameCompare(name1: string, name2: string, options: Options) {\n    if (options.ignoreCase) {\n        name1 = name1.toLowerCase()\n        name2 = name2.toLowerCase()\n    }\n    if (options.ignoreExtension) {\n        name1 = path.basename(name1, path.extname(name1))\n        name2 = path.basename(name2, path.extname(name2))\n    }\n    return ((name1 === name2) ? 0 : ((name1 > name2) ? 1 : -1))\n}\n\nconst path1 = '/tmp/a';\nconst path2 = '/tmp/b';\n\nconst res = compare(path1, path2, options).then(res => {\n    console.log(`Same: ${res.same}`)\n    if (!res.diffSet) {\n        return\n    }\n    res.diffSet.forEach(dif => console.log(`${dif.name1} ${dif.name2} ${dif.state}`))\n})\n\n// Outputs\n// icon.svg icon.png equal\n// logo.svg logo.jpg equal\n```\nFor reference, the default name comparator can be found in [defaultNameCompare](https://github.com/gliviu/dir-compare/blob/master/src/NameCompare/defaultNameCompare.ts) which is exposed by [compareNameHandlers property](https://gliviu.github.io/dc-api/variables/compareNameHandlers.html).\n\n\n## Result builder\n[Result builder](https://gliviu.github.io/dc-api/interfaces/Options.html#resultBuilder) is called for each pair of entries encountered during comparison. Its purpose is to append entries in `diffSet` and eventually update `statistics` object with new stats.\n\nIf needed it can be replaced with custom implementation.\n\n```javascript\nconst dircompare = require(\"dircompare\")\n\nconst customResultBuilder = function (entry1, entry2, state, level, relativePath, options, statistics, diffSet, reason) {\n    ...\n}\n\nconst options = {\n    compareSize: true,\n    resultBuilder: customResultBuilder\n}\nconst res = dircompare.compareSync('...', '...', options)\n\n```\n\nThe [default](https://github.com/gliviu/dir-compare/blob/master/src/ResultBuilder/defaultResultBuilderCallback.ts) builder can be used as an example.\n\n# UI tools\n* [dir-compare-cli](https://github.com/gliviu/dir-compare-cli)\n* [Visual Studio Code - Compare Folders](https://marketplace.visualstudio.com/items?itemName=moshfeu.compare-folders)\n\n# Changelog\n* v5.0.0\n  Breaking changes:\n    * `skipSubdirs` option has slightly different behavior. More details in [#77](https://github.com/gliviu/dir-compare/issues/77#issuecomment-2094375352)\n* v4.2.0\n  * Updated dependencies\n  * Increased test coverage\n* v4.1.0\n  * Possibility to alter the default [Glob filter](#glob-filter) behavior\n  * [Ignore files and directories according to .gitignore rules](#implement-gitignore-filter).\n  * New [origin](https://gliviu.github.io/dc-api/interfaces/Entry.html#origin) field in Entry to distinguish between the left or right directory\n  * Improved api documentation\n* v4.0.0\n    * Switched project to typescript\n    * [Async comparator](https://gliviu.github.io/dc-api/functions/compare.html) improvements when comparing large directory structures\n      * Heap usage has decreased 3x compared to previous version\n      * Works 2x faster when comparing by content\n      * Better concurrency. UI apps will be more responsive while comparison is ongoing\n\n  Breaking changes:\n    * Using this library to compare two files will ignore the name of the files. More details in [#48](https://github.com/gliviu/dir-compare/issues/48)\n    * Removed support for node 8, 9\n* v3.3.0 Added `skipEmptyDirs` option\n* v3.2.0 [Handle permission denied errors](#handling-permission-denied-errors)\n* v3.1.0 Added `ignoreAllWhiteSpaces` and `ignoreEmptyLines` options\n* v3.0.0 Moved CLI component into separate project [dir-compare-cli](https://github.com/gliviu/dir-compare-cli)\n* v2.4.0 [New option](https://gliviu.github.io/dc-api/interfaces/Options.html#compareNameHandler) to customize file/folder name comparison\n* v2.3.0 Fixes\n* v2.1.0 Removed [bluebird](https://github.com/petkaantonov/bluebird/#%EF%B8%8Fnote%EF%B8%8F) dependency\n* v2.0.0\n  * New option to compare symlinks.\n  * New field indicating reason for two entries being distinct.\n  * Improved command line output format.\n  * Tests are no longer part of published package.\n  * Generated [Api](https://gliviu.github.io/dc-api) documentation.\n  \n  Breaking changes:\n  * Broken links are no longer treated as errors. As a result there are new statistics (leftBrokenLinks, rightBrokenLinks, distinctBrokenLinks, totalBrokenLinks) and new entry type - broken-link.\n    Details in [Symbolic links](#symbolic-links).\n  * Typescript correction: new interface `Result` replaced `Statistics`.\n* v1.8.0 \n    * globstar patterns\n    * typescript corrections\n    * removed support for node 0.11, 0.12, iojs\n* v1.7.0 performance improvements\n* v1.6.0 typescript support\n* v1.5.0 added option to ignore line endings and white space differences\n* v1.3.0 added date tolerance option\n* v1.2.0 added compare by date option\n* v1.1.0\n    * detect symlink loops\n    * improved color scheme for command line utility\n* v1.0.0\n    * asynchronous comparison\n    * new library options: noDiffSet, resultBuilder\n    * new statistics: distinctFiles, equalFiles, leftFiles, rightFiles, distinctDirs, equalDirs, leftDirs, rightDirs\n    * new --async command line option\n    * Fix for https://github.com/tj/commander.js/issues/125\n* v0.0.3 Fix file ordering issue for newer node versions\n\n","publish_time":1491364975686,"_cnpm_publish_time":1491364975686,"dist-tags":{"latest":"5.0.0"}}