gitmyhub

np

JavaScript ★ 7.7k updated 11d ago

A better `npm publish`

Command-line tool that automates publishing npm packages, runs tests, bumps version, creates a git tag, and publishes to npm so you don't have to run a dozen commands manually each release.

JavaScriptNode.jsnpmYarnpnpmBunsetup: easycomplexity 2/5

np Explanation

Publishing a new version of your JavaScript package to npm involves a lot of manual steps: checking that you're on the right branch, running tests, updating the version number, creating a git tag, pushing to GitHub, and finally publishing to npm. If anything goes wrong partway through, you might end up with a half-published package or an inconsistent state. This tool automates and safeguards that entire workflow, making it much harder to mess up.

When you run np, it walks you through a guided checklist. It verifies you're publishing from the correct branch (usually main or master), confirms your git repository is clean with no unpushed changes, reinstalls your dependencies to catch any problems, runs your tests, and then handles all the version bumping, tagging, and publishing for you. If something fails during publishing, it automatically rolls back so you're not left with a broken state. The tool also prevents common gotchas like accidentally publishing a pre-release version as the latest, and it can enable two-factor authentication on your npm account for added security.

You'd use this if you're a maintainer of an open-source npm package or any JavaScript library you publish regularly. Instead of following a checklist and running a dozen commands by hand each time you release a new version, you just type np patch (for a small bugfix), np minor (for new features), or np major (for breaking changes), and the tool handles the rest. You can even use --dry-run to see exactly what would happen without actually pushing or publishing anything.

The tool supports modern JavaScript package managers—npm, Yarn, pnpm, and Bun—and it's designed to be used interactively on your local machine rather than in automated CI systems. The README notes it doesn't work with monorepos (projects with multiple packages in one repository), but for single-package projects it removes a lot of mental overhead and human error from the release process.

Where it fits