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

npm-needs-publish

v1.0.0

Published

Smart publish detection for npm packages - semantic package.json comparison with semver-aware dependency analysis

Readme

npm-needs-publish

Smart publish detection for npm packages - semantic package.json comparison with semver-aware dependency analysis.

Problem

Traditional publish detection methods have limitations:

  • Hash comparison: Any package.json change triggers publish (even irrelevant ones like devDependencies)
  • Version-only check: Doesn't detect content changes when version stays the same
  • Git-based: Requires tags, CI needs fetch-depth: 0

Solution

npm-needs-publish provides intelligent publish detection by:

  1. Semantic package.json comparison - Ignores irrelevant fields (devDependencies, scripts, metadata)
  2. Semver-aware dependency analysis - Understands that ^1.2.3^1.2.4 may be equivalent
  3. Dependency type awareness - Only dependencies and peerDependencies affect consumers
  4. File-level comparison - Detects actual code changes, not just metadata

Installation

npm install npm-needs-publish

CLI Usage

# Check if current directory needs publishing
npm-needs-publish

# Check with JSON output
npm-needs-publish --json

# Check specific directory with verbose output
npm-needs-publish --cwd ./packages/my-package --verbose

Options

| Option | Description | |--------|-------------| | --cwd <path> | Working directory (default: current directory) | | --registry <url> | Registry URL override | | --json | Output result as JSON | | --verbose, -v | Show detailed change breakdown | | --package-json-only | Only compare package.json, skip file comparison | | --no-optional-deps | Exclude optionalDependencies from comparison |

Exit Codes

  • 0 - Package does NOT need publishing
  • 1 - Package NEEDS publishing
  • 2 - Error occurred

Programmatic Usage

import { needsPublish } from 'npm-needs-publish';

const result = await needsPublish({ cwd: process.cwd() });

if (result.needsPublish) {
  console.log('Publish needed:', result.reason);
  // Proceed with npm publish
} else {
  console.log('No publish needed:', result.reason);
}

Options

interface NeedsPublishOptions {
  cwd?: string;                        // Working directory
  package?: PackageJson;               // Pre-loaded package.json
  registry?: string;                   // Registry URL override
  includeOptionalDeps?: boolean;       // Include optionalDependencies (default: true)
  additionalSignificantFields?: string[]; // Extra fields to consider significant
  ignoreFields?: string[];             // Fields to ignore
  packageJsonOnly?: boolean;           // Skip file comparison
  treatNarrowingAsEquivalent?: boolean; // Treat narrowed ranges as equivalent (default: true)
}

Result

interface NeedsPublishResult {
  needsPublish: boolean;
  reason: string;
  changes?: ChangeDetail[];
}

Algorithm

  1. Fetch registry packument → if E404, return needsPublish=true (first publish)
  2. Version check → if different, return needsPublish=true (intentional bump)
  3. Fast hash check → if identical, return needsPublish=false (no changes)
  4. Extract both tarballs, compare file-by-file (excluding package.json)
  5. If non-package.json files differ → return needsPublish=true
  6. If only package.json differs → do semantic comparison:
    • Compare significant fields only (main, exports, bin, types, etc.)
    • Compare dependencies with semver-aware logic
    • Ignore devDependencies, scripts, metadata fields
    • Return based on whether changes affect consumers

For a detailed explanation with flow diagrams, see ALGORITHM.md.

Significant vs Non-Significant Fields

Significant (affect consumers)

  • name, version, main, module, browser, exports, types, typings, type
  • bin, files, engines, os, cpu, peerDependenciesMeta, packageManager
  • dependencies, peerDependencies, optionalDependencies (configurable), bundledDependencies

Not Significant (metadata only)

  • devDependencies, scripts
  • repository, homepage, bugs, author, contributors
  • license, keywords, description

Semver Range Comparison

The tool understands semver range equivalence and is optimized for npm update / ncu -u workflows:

| Change | Triggers Publish? | Reason | |--------|:-----------------:|--------| | ^1.2.3^1.2.3 | No | Identical | | ^1.2.3^1.2.4 | No | Same major (caret) | | ^1.2.3^1.5.0 | No | Same major (caret) | | ^1.2.3^2.0.0 | Yes | Different major | | ~1.2.3~1.2.4 | No | Same minor (tilde) | | ~1.2.3~1.3.0 | Yes | Different minor | | *^4.17.0 | No* | Narrowed (optimistic default) | | ^4.17.0* | Yes | Widened |

*Set treatNarrowingAsEquivalent: false for conservative behavior where narrowing triggers publish.

License

MIT