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

pkdiff

v2.0.1

Published

Diff npm packages across versions, ex. `pkdiff react 16.11.0`

Downloads

83

Readme

NPM package diff (pkdiff)

Compare npm package releases and tarball. Show diff between package versions in browser or as unix diff output.

Requirements:

  • node > 8.6.0
  • GNU diffutils (diff)
  • xargs

Usage:

npm install -g pkdiff

pkdiff <new-version> <old-version>

Basic examples:

show diff in browser:

npx pkdiff react 16.11.0

npx pkdiff react@next 16.11.0

diff as JSON:

npx pkdiff [email protected] 16.11.0 --quite --format=json > diff.json

diff as unix Diff:

npx pkdiff [email protected] 16.11.0 -f diff

exclude files from diff:

npx pkdiff react@latest 16.11.0 --exclude='\.json$'

Compare local packed packages:

  • npx pkdiff your-package@latest ./your-packed-package.tgz
  • npx pkdiff ./your-packed-package1.tgz ./your-packed-package2.tgz

Output formats:

Options

  • -x, --exclude [string] - exclude files (JS RegExp)
  • -f, --format [diff|json|html] - output format (default: "html")
  • -o, --output [path] - output destination (default: false)
  • -c, --no-exit-code - returns code 0 if found differences
  • -q, --quite - turn off actions log (default: false)
  • --fast-check - will try to find diff in any file and return result (default: false)
  • --registry [string] - npm registry url
  • --prefer-offline - npm cli preffer-offline
  • -h, --help - output usage information

JS API

const {
    hasDiff,
    // result as "unix diff" string
    // if you don't logs set it to false
    compare,
    // diff as json
    compareJSON,
    setLogQuite
} = require('pkdiff');

/**
 * @param {string} package1 - new package
 * @param {string} package2 - old package (can be as version or tag)
 * @param {Object} options - comparison options
 * @param {boolean} options.full=true - flag for full check,
   if "false" compare function will stop on first diff and returns boolean (package equals: true or has diff: false)
 * @param {function} options.validate - call validate diff function if found diff
 * @param {string|RegExp} options.exclude - JS RegExp
 * @param {boolean} options.toStdOut - all diff output to stdOut
 *
 * @returns {Promise<boolean|string|undefined>}
*/


// check diff between package versions
const result = hasDiff('react', '16.8.0', { exclude: 'package\\.json$' });
const result = hasDiff('react', '16.8.0', { exclude: '\\.(md|json)$' });

// with validate function
const result = hasDiff('[email protected]', '0.9.0', {
  // will call validate function after found diff in this file
  validate: (newVersionFilePath, oldVersionFilePath) => {
    if (newVersionFilePath.include('/package.json')) {
      const newPkgJSON = require(newVersionFilePath);
      const oldPkgJSON = require(oldVersionFilepath);

      return assert.deepEqual(newPkgJSON.dependecies, oldPkgJSON.dependecies);
    }

    // if isn't package.json
    return false;
  }
});

// get diff as JSON
const diffJSON = compareJSON('[email protected]', '0.9.0');

const changedFiles = diffJSON.map(fileDiff => {
  return {
    newVersion: fileDiff.newName,
    oldVersion: fileDiff.oldName
  }
})