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-zip

v1.0.1

Published

This module creates and applies differences/patches between two folders.

Downloads

5

Readme

dif-zipp

This module creates and applies differences/patches between two folders.

Raison d'etre

Although the module can't create diffs cross-platform, yet (Windows support is missing, see below) it can apply them cross-platform.

This means that this is a useful tool when building update-patches for desktop applications (think Electron, NW) etc. Because:

  • The end user does not have to have git (or even an unzipper) installed.
  • Diffs/patches can be easily downloaded and applied in a "user data" - folder, omitting the need to rebuild a binary on updates.

Inner workings

The module works by

  • Creating diffs

    1. Identifying the differences using the Linux/Mac command "diff". (So it won't work on Windows. We might fix Windows-compatability in the future by using the FC command.)
    2. Analyzing the output of the diff, thus sorting files and folders into three categories (add, change and remove).
    3. Creating a manifest file with the differences.
    4. Zipping the manifest file together with the files/folders that are additions and changes.
  • Applying diffs

    1. Unzipping a "diff-zip".
    2. Reading the manifest file.
    3. Applying the changes to a folder.

Installation

npm install diff-zip

Then, in your program, require diff-zip:

const DiffZip = require('diff-zip')

Creating diffs

Choose any two folders or two different commits in a git repository.

If you choose a git repository you can run any commands (build scripts etc) on the folders before creating a diff.

Diffing between two folders

await DiffZip.create (
  'path to zip file to be created',
  
  'path to folder A (initial state)',
   // null: for empty initial state
  
  'path to folderB (final state)',
  
  // OPTIONAL
  
  true 
  // for verbose logging
  // default: false
)

Diffing between two commits in a git repository

await DiffZip.repoDiff (
  'path to temporary working dir',
  
  'path to git repo (ssh path)',

  'path to zip file to be created',
  
  'commitHash for initial state',
  
  // OPTIONAL
  
  'commitHash for final state',
  // default: head
  
  ['command1', 'command2' etc]
  // commands to apply on both folders
  // default: ['npm install --production']
  
  true,
  // remove temporary folder when done
  // default: true

  true 
  // for verbose logging
  // default: false
)

Applying diffs

Choose a folder to apply the diff to and decide if you want to apply it directly to the folder or to a copy of the folder.

await DiffZip.apply(
  'path to zip file to apply as diff',

  'path to folder to apply the diff to',

  // OPTIONAL

  'path to copy of folder to be created',
  // set this if you want the diff to be applied
  // to a copy of the folder instead of to the original folder

  true 
  // for verbose logging
  // default: false
)