Generic CLI tool to automate versioning and package publishing-related tasks.
—
The npm plugin provides comprehensive npm package publishing functionality including registry validation, authentication checks, collaborator verification, and publishing with 2FA support.
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>;
}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;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>;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>;
}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;
}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
}
});The npm plugin performs several validation checks during initialization:
npm whoami)These checks can be skipped with skipChecks: true for faster execution or offline scenarios.
The npm plugin provides comprehensive Two-Factor Authentication support:
The npm plugin intelligently handles pre-release versions:
Private packages are automatically detected and handled:
{
"name": "@company/private-package",
"private": true,
"publishConfig": {
"registry": "https://npm.internal.company.com"
}
}The plugin will:
private: true is setpublishConfigThe npm plugin includes robust error handling for:
Install with Tessl CLI
npx tessl i tessl/npm-release-it