Introduction
np wraps the entire npm publish workflow into a single interactive command. It runs your tests, bumps the version, creates a git tag, pushes to the remote, publishes to the npm registry, and creates a GitHub release draft. Each step includes safety checks to prevent common publishing mistakes like dirty working trees or skipped tests.
What np Does
- Runs the full test suite before allowing a publish to proceed
- Verifies the working directory is clean with no uncommitted changes
- Bumps the version in package.json using SemVer (patch, minor, major, or custom)
- Creates an annotated git tag and pushes it to the remote repository
- Publishes the package to npm with optional two-factor authentication prompts
Architecture Overview
np orchestrates a sequential pipeline of checks and actions. It starts with prerequisite validation (clean git state, correct branch, npm auth), then runs the test script from package.json. After tests pass, it prompts for the version bump type, updates package.json and lockfiles, commits, tags, pushes to git, and finally runs npm publish. Each step is guarded by error handling that aborts the pipeline cleanly if anything fails, preventing partial publishes.
Self-Hosting & Configuration
- Install globally with
npm install -g npor run vianpx np - Configure in package.json under the
npkey or in a.np-config.jsfile - Set
"tests": falseto skip test runs for projects without a test suite - Use
"yarn": trueto run Yarn instead of npm for installs and publishing - Set
"branch": "main"to enforce publishing only from a specific branch
Key Features
- Interactive version selection: choose patch, minor, major, prepatch, or custom
- Prerequisite checks: clean git state, correct branch, valid npm auth, up-to-date dependencies
- Two-factor auth: prompts for OTP when your npm account requires it
- GitHub releases: optionally opens a pre-filled GitHub release draft after publishing
- Monorepo support: works with workspaces when run from a package directory
Comparison with Similar Tools
- npm publish — Raw publish command with no safety checks; np adds validation and automation around it
- release-it — More configurable release pipeline; np is opinionated and requires less setup
- semantic-release — Fully automated based on commit messages; np is interactive and developer-driven
- Changesets — Designed for monorepo versioning workflows; np targets single-package publishing
FAQ
Q: Does np work with Yarn?
A: Yes. Set "yarn": true in your np config and it will use Yarn for install and publish steps.
Q: Can I do a dry run?
A: Yes. Run np --preview to see what version would be published and which steps would execute without actually running them.
Q: Does it support scoped packages?
A: Yes. Scoped packages publish normally. For public scoped packages, ensure publishConfig.access is set to "public" in package.json.
Q: What happens if tests fail? A: np aborts the entire pipeline and no version bump, tag, or publish occurs.