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

pr-coverage

v1.0.1

Published

CLI that measures coverage of changed lines in pull requests using Vitest reports

Readme

pr-coverage

CLI that measures coverage of changed lines in a pull request using an existing Vitest coverage report.

For a deeper walkthrough of the code paths, parsing rules, and report flow, see ARCHITECTURE.md.

Installation

npm install -g pr-coverage

Usage

pr-coverage
pr-coverage --base main
pr-coverage --coverage coverage/coverage-final.json
pr-coverage --min 90
pr-coverage --min-branches 85 --min-functions 90
pr-coverage --debug

If your project has an npm script named coverage, pr-coverage will run it first to generate fresh coverage data before analyzing the report. Use --debug to print stage-by-stage logs while the CLI runs.

Options

| Flag | Description | Default | |------|-------------|---------| | --base | Base branch to compare against | main (falls back to master if main is missing) | | --coverage | Path to coverage-final.json | coverage/coverage-final.json | | --debug | Print stage-by-stage debug logs while the CLI runs | false | | --min | Minimum required coverage percentage | 80 | | --min-branches | Minimum required branch coverage percentage when branch data exists | Uses --min | | --min-functions | Minimum required function coverage percentage when function data exists | Uses --min |

How It Works

pr-coverage follows this runtime sequence:

  1. Parse the CLI flags
  2. If --debug is set, print a log line before and after each major step
  3. Run npm run coverage when a coverage script exists in package.json
  4. Resolve the base branch and generate git diff <base>...HEAD --unified=0
  5. Parse changed source lines from the diff
  6. Read coverage/coverage-final.json or the path passed with --coverage
  7. Normalize file paths so diff paths and coverage paths line up
  8. Compare changed lines against coverage data
  9. Print the final report
  10. Exit 0 or 1 based on the configured thresholds

Output

Changed files: 3
Changed lines: 28
Covered lines: 25

PR Coverage (Lines): 89%

PR Coverage (Branches): 92% (46/50)
PR Coverage (Functions): 95% (38/40)

Uncovered Lines/Branches:
src/services/user.ts:44
src/services/user.ts:57
src/api/auth.ts:19 (Missing branch coverage)

Exit codes

| Code | Meaning | |------|---------| | 0 | PR coverage meets the threshold | | 1 | Coverage below threshold, missing coverage report, or git failure |

Requirements

  • Vitest with @vitest/coverage-v8 or another Istanbul-compatible reporter
  • Coverage reporter configured to produce coverage-final.json
  • Git repository with the base branch available

Architecture

See ARCHITECTURE.md for a detailed view of:

  • command flow
  • diff parsing
  • coverage parsing
  • analyzer logic
  • report generation

CI Example (GitHub Actions)

name: PR Coverage
on: [pull_request]

jobs:
  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx pr-coverage --min 80

Vitest configuration

Add the JSON reporter to your Vitest config so coverage-final.json is generated:

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    coverage: {
      provider: "v8",
      reporter: ["json"],
      reportsDirectory: "./coverage",
    },
  },
});