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 🙏

© 2026 – Pkg Stats / Ryan Hefner

git-patch-native

v0.2.0

Published

Generate git-style unified patch strings from in-memory source changes, powered by Rust.

Readme

git-patch-native

Rust-backed Node/Bun-oriented package for generating git-style unified patch strings from in-memory file changes.

import { generatePatch } from "git-patch-native";

const patch = generatePatch({
  "src/main.ts": {
    before: "const value = 1;\n",
    after: "const value = 2;\n",
  },
  "src/added.ts": {
    after: "export const added = true;\n",
  },
  "src/new-name.ts": {
    moved: "src/old-name.ts",
    before: "same\n",
    after: "same\n",
  },
});

API shape

generatePatch(changes, options?) accepts a record whose key is the new path, except deletions where the key is the deleted path.

type GitFileMode = "100644" | "100755";

type Changes = Record<string, {
  before?: string | null; // omitted for additions
  after?: string | null;  // omitted for deletions
  moved?: string | { from: string; similarity?: number };
  mode?: GitFileMode | { before?: GitFileMode | null; after?: GitFileMode | null };
}>;

Guarantees for the initial contract:

  • deterministic path ordering
  • git-style diff --git, ---, +++, hunk, add/delete, and rename headers
  • path separator normalization to /
  • Git-compatible C-style quoting for paths containing quotes or control characters
  • new file mode, deleted file mode, old mode, and new mode headers for 100644/100755 mode metadata
  • NUL paths and NUL content are rejected
  • final-newline markers when needed
  • contextLines >= 1 so output applies with default git apply
  • text-only input: NUL-containing content is rejected
  • all diff formatting owned by Rust core; JS only serializes inputs and loads the native binding

Development

npm install
npm run build
npm test
cargo test
npm run smoke:pack

The native package is currently local-build first. scripts/copy-native.mjs copies the Rust Node-API cdylib into bin/*.node and the Bun FFI cdylib into bin/*.{dylib,so,dll}, following the same platform-tag idea used by .references/fff-package/packages/fff-node/package.json.

npm run smoke:pack verifies publish shape by packing the package, installing the tarball into clean temporary consumers, then proving both:

  • Node can import the package and load the Node-API addon.
  • Bun can dlopen the packaged FFI library through bun:ffi.

The public SDK entrypoint remains generatePatch; the FFI surface is a low-level packaging/runtime artifact.

Publishing

This package uses a two-tier npm publish shape:

  • git-patch-native publishes the JS/TypeScript SDK once.
  • git-patch-native-<platform> packages publish native Node-API and Bun FFI artifacts from a GitHub Actions matrix.

Release tags are v<package.json version>, for example v0.1.0. The release workflow publishes with npm provenance:

git tag v0.1.0
git push origin v0.1.0

Before the first release, configure npm Trusted Publishing for the main package and each platform package. Use repository colelawrence/git-patch-native and workflow .github/workflows/release.yml.

After publishing, verify package signatures/provenance metadata with npm:

npm view [email protected] dist.integrity dist.signatures
mkdir /tmp/git-patch-native-verify && cd /tmp/git-patch-native-verify
npm init -y
npm install [email protected]
npm audit signatures

The npm package page should also show provenance for packages published by the release workflow.

Reference architecture

The fff repo is vendored as a submodule at .references/fff-package. The package skeleton mirrors its useful Node-package decisions:

  • ESM package with dist/src/index.js + generated declarations
  • explicit os / cpu support metadata
  • platform detection helpers
  • local dev binary lookup under bin
  • future-compatible platform package names for prebuilt artifacts

This project intentionally uses N-API instead of ffi-rs for the first native binding because N-API is the cleaner shared seam for Node and Bun.