CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-release-it

Generic CLI tool to automate versioning and package publishing-related tasks.

Pending
Overview
Eval results
Files

npm-publishing.mddocs/

npm Publishing

The npm plugin provides comprehensive npm package publishing functionality including registry validation, authentication checks, collaborator verification, and publishing with 2FA support.

Capabilities

npm Plugin Class

Main npm publishing plugin for package registry operations.

/**
 * npm publishing plugin for package registry operations
 * Handles authentication, validation, and publishing to npm registry
 */
class npm extends Plugin {
  /**
   * Check if npm plugin should be enabled
   * @param options - npm plugin options
   * @returns Boolean indicating if package.json exists and npm is not disabled
   */
  static isEnabled(options: any): boolean;
  
  /** Initialize npm plugin with registry validation and authentication */
  init(): Promise<void>;
  
  /** Get package name from package.json */
  getName(): string;
  
  /** Get latest version from package.json (unless ignoreVersion is true) */
  getLatestVersion(): string | null;
  
  /**
   * Bump package version using npm version command
   * @param version - New version to bump to
   * @returns Promise resolving to boolean indicating success
   */
  bump(version: string): Promise<boolean>;
  
  /**
   * Publish package to npm registry
   * @returns Promise resolving to boolean indicating success
   */
  release(): Promise<boolean>;
  
  /** Log package URL after successful release */
  afterRelease(): void;
  
  /** Registry connectivity and authentication */
  isRegistryUp(): Promise<boolean>;
  isAuthenticated(): Promise<boolean>;
  isCollaborator(): Promise<boolean>;
  
  /** Version and registry information */
  getLatestRegistryVersion(): Promise<string | null>;
  getRegistryPreReleaseTags(): Promise<string[]>;
  resolveTag(version: string): Promise<string>;
  guessPreReleaseTag(): Promise<string>;
  
  /** Registry and package information */
  getRegistry(): string | undefined;
  getPublicPath(): string;
  getPackageUrl(): string;
  
  /** Publishing operations */
  publish(options?: PublishOptions): Promise<boolean | void>;
}

Registry Operations

Methods for interacting with npm registry and validating connectivity.

/**
 * Check if npm registry is accessible
 * @returns Promise resolving to boolean indicating registry availability
 */
isRegistryUp(): Promise<boolean>;

/**
 * Check if user is authenticated with npm registry
 * @returns Promise resolving to boolean indicating authentication status
 */
isAuthenticated(): Promise<boolean>;

/**
 * Check if authenticated user is a collaborator for the package
 * @returns Promise resolving to boolean indicating collaborator status
 */
isCollaborator(): Promise<boolean>;

/**
 * Get latest version of package from npm registry
 * @returns Promise resolving to version string or null if not found
 */
getLatestRegistryVersion(): Promise<string | null>;

/**
 * Get pre-release tags from npm registry
 * @returns Promise resolving to array of pre-release tag names
 */
getRegistryPreReleaseTags(): Promise<string[]>;

/**
 * Get npm registry URL for this package
 * @returns Registry URL string
 */
getRegistry(): string;

/**
 * Get public path for package URL
 * @returns Public path string
 */
getPublicPath(): string;

/**
 * Get full package URL on npm registry
 * @returns Complete package URL
 */
getPackageUrl(): string;

Version and Tag Management

Methods for handling version bumping and npm tag resolution.

/**
 * Resolve npm tag for given version
 * @param version - Version string to resolve tag for
 * @returns Promise resolving to npm tag (latest, next, etc.)
 */
resolveTag(version: string): Promise<string>;

/**
 * Guess pre-release tag from registry or use default
 * @returns Promise resolving to pre-release tag name
 */
guessPreReleaseTag(): Promise<string>;

Publishing Operations

Methods for publishing packages to npm registry with 2FA support.

/**
 * Publish package to npm registry
 * @param options - Publishing options
 * @returns Promise that resolves when publishing completes
 */
publish(options?: PublishOptions): Promise<void>;

interface PublishOptions {
  /** One-time password for 2FA authentication */
  otp?: string;
  /** Callback function for OTP prompt when 2FA is required */
  otpCallback?: (callback: (otp: string) => Promise<void>) => Promise<void>;
}

npm Configuration Options

Complete configuration options for the npm plugin.

interface NpmOptions {
  /** Enable/disable npm plugin entirely */
  disabled?: boolean;
  
  /** Skip registry connectivity and authentication checks */
  skipChecks?: boolean;
  
  /** Ignore version in package.json and don't update it */
  ignoreVersion?: boolean;
  
  /** Enable/disable publishing to npm registry */
  publish?: boolean;
  
  /** npm tag to use for published version (default: "latest" or "next" for prereleases) */
  tag?: string;
  
  /** One-time password for 2FA authentication */
  otp?: string;
  
  /** Registry connection timeout in seconds (default: 10) */
  timeout?: number;
  
  /** Additional arguments for npm version command */
  versionArgs?: string[];
  
  /** Allow npm version to set same version (useful for rebuilds) */
  allowSameVersion?: boolean;
  
  /** Path/directory to publish (default: current directory) */
  publishPath?: string;
  
  /** Additional arguments for npm publish command */
  publishArgs?: string[];
  
  /** Custom npm registry URL (overrides package.json publishConfig) */
  registry?: string;
}

Package Configuration Support

The npm plugin respects package.json configuration:

interface PackageJson {
  /** Package name */
  name: string;
  /** Current version */
  version: string;
  /** Private package flag (prevents publishing) */
  private?: boolean;
  /** Publishing configuration */
  publishConfig?: {
    /** Custom registry URL */
    registry?: string;
    /** Custom public path for package URL */
    publicPath?: string;
    /** Scoped registry configurations */
    [key: string]: any;
  };
}

Usage Examples:

// Basic npm publishing configuration
const result = await runTasks({
  npm: {
    publish: true,
    skipChecks: false
  }
});

// Advanced npm configuration with custom registry
const result = await runTasks({
  npm: {
    publish: true,
    registry: "https://npm.internal.company.com",
    tag: "beta",
    timeout: 30,
    publishArgs: ["--access", "public"],
    versionArgs: ["--no-git-tag-version"]
  }
});

// npm configuration for pre-release workflow
const result = await runTasks({
  increment: "prerelease",
  npm: {
    publish: true,
    tag: "next",                    // Use 'next' tag for prereleases
    allowSameVersion: true          // Allow republishing same version
  }
});

// Skip npm publishing but still bump version
const result = await runTasks({
  npm: {
    publish: false,                 // Don't publish to registry
    skipChecks: true               // Skip registry validation
  }
});

// Handle 2FA authentication programmatically
const result = await runTasks({
  npm: {
    publish: true,
    otp: "123456"                  // Provide OTP directly
  }
});

Registry Validation

The npm plugin performs several validation checks during initialization:

  1. Registry Connectivity: Verifies npm registry is accessible
  2. Authentication: Confirms user is logged in (npm whoami)
  3. Collaborator Status: Validates user has write permissions
  4. Version Consistency: Compares package.json version with registry

These checks can be skipped with skipChecks: true for faster execution or offline scenarios.

2FA Support

The npm plugin provides comprehensive Two-Factor Authentication support:

  • Automatic Detection: Recognizes 2FA requirement from publish errors
  • OTP Prompting: Interactive prompt for OTP when needed
  • Programmatic OTP: Accept OTP via configuration or callback
  • Error Recovery: Retry publishing with correct OTP

Pre-release Handling

The npm plugin intelligently handles pre-release versions:

  • Tag Resolution: Automatically uses "next" tag for prereleases
  • Registry Tags: Discovers existing pre-release tags from registry
  • Custom Tags: Supports custom pre-release tag configuration
  • Version Parsing: Extracts pre-release identifiers from version strings

Private Package Support

Private packages are automatically detected and handled:

{
  "name": "@company/private-package",
  "private": true,
  "publishConfig": {
    "registry": "https://npm.internal.company.com"
  }
}

The plugin will:

  • Skip publishing if private: true is set
  • Use custom registry from publishConfig
  • Handle scoped package authentication
  • Support organization-specific configurations

Error Handling

The npm plugin includes robust error handling for:

  • Network Issues: Timeout and retry logic for registry operations
  • Authentication Failures: Clear error messages for login issues
  • Permission Errors: Detailed feedback for collaborator access issues
  • 2FA Errors: Automatic OTP retry with user feedback
  • Version Conflicts: Detection and reporting of version mismatches

Install with Tessl CLI

npx tessl i tessl/npm-release-it

docs

cli-interface.md

configuration.md

core-orchestration.md

git-operations.md

github-integration.md

gitlab-integration.md

index.md

npm-publishing.md

plugin-system.md

tile.json