npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

diff-file-tree

v2.5.1

Published

Compare two file-trees, get a list of changes, then apply left or right

Downloads

84

Readme

diff-file-tree

Compare two file-trees, get a list of changes, then apply left or right.

npm install diff-file-tree

Usage

var dft = require('diff-file-tree')

var changes = await dft.diff('/home/alice/stuff', '/home/alice/things')
console.log(changes) /* => [
  {change: 'mod', type: 'file', path: '/hello.txt'},
  {change: 'add', type: 'dir',  path: '/pics'},
  {change: 'add', type: 'file', path: '/pics/kitty.png'},
  {change: 'del', type: 'file', path: '/backup/hello.txt'},
  {change: 'del', type: 'dir',  path: '/backup'},
  {change: 'del', type: 'file', path: '/hello.txt'},
]*/

// make 'things' a copy of 'stuff' 
await dft.applyRight('/home/alice/stuff', '/home/alice/things', changes)
// -or-
// make 'stuff' a copy of 'things'
await dft.applyLeft('/home/alice/stuff', '/home/alice/things', changes)

Known issues

Files with equal size and mtimes will show as equal, even if their content is different. This is caused by an optimization which can sometimes give false positives.

API

var changes = await dft.diff(left, right[, opts])

Get the differences between left and right.

Options include:

{
  filter: null // optional function to ignore files (function (path) => bool)
  shallow: false // dont recurse into folders that need to be added or removed
  sizeLimit: {
    maxSize: undefined // max number of bytes before comparison aborts
    assumeEq: false // assume == (true) or assume != (false)
  }
  compareContent: false // set to true to compare by content instead of mtime & size
  compareContentCache: undefined // provide an object to cache file equality tests in memory
}

If you are using a custom fs module (like graceful-fs or hyperdrive) you can pass that in with the left or right like this:

dft.diff({path: '/Users/alice/stuff', fs: customFs}, {path: '/', fs: hyperdriveArchive})

await dft.applyRight(left, right, changes)

Make right equivalent to left using the given changes. Both left and right can be an object with custom {path:, fs:} as with diff().

await dft.applyLeft(left, right, changes)

Make left equivalent to right using the given changes. Both left and right can be an object with custom {path:, fs:} as with diff().

dft.applyRightStream(left, right, changes)

Make right equivalent to left using the given changes. Both left and right can be an object with custom {path:, fs:} as with diff().

Returns a stream which emits each operation as {op: String, path: String}. You can cancel the merge-operation by destroying the stream.