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

gitversionjs

v1.0.8

Published

Auto-generates SemVer versions from Git tags and branches, GitFlow-style.

Readme

GitVersionJS

GitVersionJS is a tiny tool that turns your Git tags & branches into a semantic version. Use it as a global CLI or as a library.

Features

  • Infers version from Git:
    • Uses the latest tag (e.g. v1.2.3 or 1.2.3)
    • Applies branch rules (e.g. develop, feature/*, release/*, hotfix/*)
  • Configurable tag prefix & branch naming
  • Works locally and in CI
  • Zero runtime deps for consumers
  • Includes a .build number (commit count) in the version string.

Quick start (CLI – global)

# install globally
npm install -g gitversionjs

# print a version for the current repo
gitversionjs

# JSON output (machine-friendly)
gitversionjs --output json

# run against another repository directory
gitversionjs --cwd /path/to/repo --output json

Tip: you can also run without installing globally:

npx gitversionjs --output json

Library usage (Node ESM)

import { gitversion } from "gitversionjs";

const info = await gitversion(); // { version, major, minor, patch, build, ... }
console.log(info.version); // e.g. "1.2.0.5", "1.3.0.1724329999"

/// optional: target a specific repo directory
const infoFromOtherRepo = await gitversion({ cwd: "/path/to/repo" });

Configuration

Create a .gitversion.config.js in your repo root (ESM):

/** @type {import('gitversionjs').GitVersionConfig} */
export default {
  tagPrefix: "v", // e.g. "v1.2.3" → strip "v"
  branchPrefixes: {
    main: "main",
    develop: "develop",
    feature: "feature/",
    release: "release/",
    hotfix: "hotfix/",
  },
};

How versions are determined (default rules)

  • Tags: latest semver tag (prefix optional) is the base (e.g. v1.2.3 or 1.2.3)
  • main: exactly the base tag, with .build appended (e.g., 1.2.3.5).
  • develop/feature/: bump minor, reset patch → 0, append .build (commit count)
    (e.g. 1.2.31.3.0.5).
  • release/X[.Y[.Z]]: branch name is authoritative if it contains a version
    (release/22.0.0, release/2.12.1.0, release/2.1.32.1.3).
    If not encoded, bump minor and reset patch → 0 from base.
  • hotfix/X.Y.Z: branch name is authoritative; otherwise bump patch.

In all cases: bumping major resets minor & patch to 0; bumping minor resets patch to 0.


Requirements & CI tips

  • Your repo must have tags locally. In CI, make sure to fetch them:
    • GitHub Actions
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          fetch-tags: true
      - run: git fetch --tags --force --prune
  • If you’re in a workspace/monorepo, point --cwd (or pass { cwd } in code) at the repo root.

Typical workflows

Update package.json to computed version

import fs from "fs";
import path from "path";
import { gitversion } from "gitversionjs";

const info = await gitversion();
const pkgPath = path.resolve("package.json");
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
pkg.version = info.version; // or `${info.major}.${info.minor}.${info.patch}.${info.build}` if you want to include the build number
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");

Write a public version file for your app

import fs from "fs";
fs.mkdirSync("public", { recursive: true });
fs.writeFileSync(
  "public/version.json",
  JSON.stringify({ version: info.version }, null, 2)
);

Install options

  • Global CLI:
    npm i -g gitversionjs
  • Project dev dep:
    npm i -D gitversionjs
    Then:
    // package.json
    {
      "scripts": {
        "version:print": "gitversionjs --output json"
      }
    }

License

MIT © The Horrible Meadery