A better npm publish tool with automated workflows, version bumping, testing, and git integration
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The core publishing functionality that orchestrates the complete npm publishing pipeline with automated version bumping, testing, git operations, and registry publishing.
The primary entry point for all publishing operations, handling the complete workflow from validation to publication.
/**
* Main publishing function that handles the complete npm publishing workflow
* @param input - Version increment ('patch'|'minor'|'major'|'prerelease'|'prepatch'|'preminor'|'premajor') or specific version string (default: 'patch')
* @param options - Publishing configuration options
* @param context - Package metadata and root directory context
* @returns Promise resolving to updated package.json data
*/
function np(
input?: string,
options?: Options,
context?: {
package_: NormalizedPackageJson;
rootDirectory: string;
}
): Promise<NormalizedPackageJson>;Usage Examples:
import np from "np";
// Basic patch release
const result = await np("patch", {
cleanup: true,
tests: true,
publish: true
}, {
package_: require('./package.json'),
rootDirectory: process.cwd()
});
// Prerelease with custom tag
const prerelease = await np("prerelease", {
tag: "beta",
message: "Beta release v%s",
releaseDraft: false
}, context);
// Preview mode (dry run)
const preview = await np("minor", {
preview: true,
packageManager: "pnpm"
}, context);
// Skip tests and cleanup (YOLO mode)
const quick = await np("patch", {
yolo: true,
publish: true
}, context);CLI implementation with argument parsing and interactive prompts.
/**
* Get parsed CLI options and configuration
* @returns Promise resolving to options, package context, and root directory
*/
function getOptions(): Promise<{
options: Options;
rootDirectory: string;
package_: NormalizedPackageJson;
}>;The publishing workflow consists of sequential tasks executed using Listr:
Automatic rollback functionality in case of publishing failures.
/**
* Rollback function that reverts changes on publish failure
* Removes the latest git tag and commit if version was bumped
*/
const rollback: () => Promise<void>;Rollback Process:
Dry-run functionality that shows what commands would be executed without making changes.
interface PreviewOptions extends Options {
preview: true;
}Preview Features:
Mode for creating GitHub release drafts for already published versions.
interface ReleaseDraftOptions extends Options {
releaseDraftOnly: true;
}The input parameter accepts:
patch, minor, major, prepatch, preminor, premajor, prerelease1.2.3, 2.0.0-beta.1, 1.0.0-alpha.2patch if no input providedThe context parameter must provide:
interface PublishContext {
package_: NormalizedPackageJson; // Parsed package.json
rootDirectory: string; // Absolute path to project root
}Options are merged from multiple sources in priority order:
.np-config.json, .np-config.js, etc.)Private packages (with "private": true in package.json) are handled specially:
Limited support for external npm registries:
Common error scenarios and their handling:
Install with Tessl CLI
npx tessl i tessl/npm-np