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 🙏

© 2025 – Pkg Stats / Ryan Hefner

gatsby-source-gitdiff

v1.0.0

Published

A source plugin for Gatsby that creates Diff nodes from a local git repo.

Downloads

4

Readme

gatsby-source-gitdiff

A source plugin that creates Diff nodes from a local git repo. Each Diff is generated by diffing two adjacent commits using git-diff. A key use case would be to create a change-log section showing the history of changes to your site.

Important: Your git repo must be at the root of your Gatsby project.

Also Important: No Diff nodes will be produced if you only have one commit in your history (and this will probably produce a "no nodes found" error in graphql queries).

Install

npm install --save gatsby-source-gitdiff

How to use

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-gitdiff`,
      options: {
        ...
      },
    },
  ],
}

Options

See defaultOptions.js for defaults to each option.

options: {
  "diffFilter" : "ADM",                     // (string) A = Added, D = Deleted, M = Modified (fed into --diff-filter option of git-diff command)
  "dateFormat" :  "MMM DD, YYYY - h:mm a",  // (string) momentjs formatting string, would produce "Oct 08, 2018 - 12:34 am"
  "targetDirectory"  : "src/pages",         // (string) only include diff'ed files in this directory
  "afterCommit" : "017180a",                // (string) start comparing after this commit
  "ignore" : 
  {
    "firstCommit" : false,                  // (bool) ignore the first commit
    "files" : ["package.json"],             // (string[]) file names to exclude
    "exts" : ["png"],                       // (string[]) file extensions to exclude
    "commits" : ["017180a"],                // (string[]) hashes of commits to exclude
  }
}

Diff Node

The format of a Diff node is as follows:

{
  "node": {
    "date": "Nov 12, 2018 - 12:31 pm",  // The date of the commit
    "message": "Updated home page",     // The commit message (i.e. git commit -m"Updated home page")
    "files": [                          // An array of files that have changed
      {
        "name": "src/pages/index.js",   // Filepath of file
        "binary": false,                // Whether the file is a binary
        "type": "modified",             // What type of change occured (e.g. added, modified, deleted)
        "changes": [                    // An array of diff-formatted strings
          "-  this\n+ that"
        ]
      }
    ]
  }
}

How to query

A query for Diff nodes would look like:

{
  allGitDiffCommit {
    edges {
      node {
        date
        message
        files {
          name
          binary
          type
          changes
        }
      }
    }
  }
}

and this would produce a result like:

{
  "data": {
    "allGitDiffCommit": {
      "edges": [
        {
          "node": {
            "date": "Nov 12, 2018 - 12:31 pm",
            "message": "Updated home page",
            "files": [
              {
                "name": "src/pages/index.js",
                "binary": false,
                "type": "modified",
                "changes": [
                  " import Image from '../components/image'\n \n const IndexPage = () => (\n   <Layout>\n-    <h1>Hi people</h1>\n+    <h1>Hello everyone!</h1>\n     <p>Welcome to your new Gatsby site.</p>\n     <p>Now go build something great.</p>\n     <div style={{ maxWidth: '300px', marginBottom: '1.45rem' }}>\n"
                ]
              }
            ]
          }
        }
      ]
    }
  }
}