Skip to content
rocket

@neosjs/release ​

🚀 A universal CLI tool for version control that automates versioning and package publishing tasks

@neosjs/release is a universal CLI tool for version control and releasing. It automates version management, recommends the next version from releasable commits, generates a CHANGELOG.md with a contributors section, commits / tags / pushes with Git, runs safety preflight checks, publishes to npm, creates GitHub / GitLab Releases, handles Canary preview releases and Release-via-PR, backfills Releases from an existing changelog, and switches automatically between its English and Chinese interface.

Highlights ​

  • Version management (package.json)
  • Automatic version recommendation from releasable Conventional Commits (skipped automatically in CI when only non-releasable commits exist)
  • Git operations: commit, tag (with GPG / SSH signature verification), push, and rollback on failure
  • Run any test, build, or notification command with Hooks
  • Changelog generation (CHANGELOG.md) with a built-in contributors section (Contributors) and single-link PR entries
  • Publish to NPM (supports pnpm / bun, 2FA, and staged publishing via npm.stage)
  • Create Releases on GitHub (supports environment-variable tokens, local gh CLI credentials, and browser fallback) or GitLab
  • Manage pre-releases, snapshots, and Canary preview releases (--canary)
  • Release-via-PR mode (--pr) for repositories with a protected default branch
  • Safety preflight checks before releasing (upstream sync check, package contents scan, and warnings about potential breaking changes)
  • Sync or backfill GitHub / GitLab Releases from CHANGELOG.md (--sync-releases)
  • English & Chinese interface that switches automatically (follows the system language, overridable via --lang / NEOS_RELEASE_LANG)
  • Extensible via plugins, and ready for any CI/CD environment

Documentation ​

Installation ​

Although @neosjs/release is a universal release tool, it is most commonly used in projects with an npm package.

@neosjs/release requires Node.js >= 22.13.

The recommended way is to install it globally with npm and add some configuration to your project:

bash
npm install @neosjs/release -g

Or install it in your project and add a release script to package.json:

bash
npm install @neosjs/release -D
bash
pnpm add @neosjs/release -D
json
{
  "name": "package",
  "version": "1.0.0",
  "scripts": {
    "release": "release"
  },
  "devDependencies": {
    "@neosjs/release": "latest"
  }
}

Usage ​

Run @neosjs/release from your project root using npm run or npx:

bash
npm run release
npx @neosjs/release

If @neosjs/release is installed globally, you can run it directly from your project root:

sh
release

# or
neos-release

You will be prompted to select the next version, followed by further prompts based on your configuration.

Interface Language ​

The interface follows your system language by default (it detects LC_ALL / LC_MESSAGES / LANG and the system locale: Chinese is shown in Chinese environments, English everywhere else). You can override it explicitly (highest precedence first):

sh
release --lang en              # CLI flag (zh-CN / en / auto)
NEOS_RELEASE_LANG=en release   # Environment variable

You can also set lang: 'zh-CN' | 'en' | 'auto' at the top level of your config file.

Reading the Version or Changelog in a Script ​

When you only need the version or the changelog, the two commands below print only the result to standard output (all other output goes to standard error), so they can be used directly in scripts:

sh
VERSION=$(release --release-version)
release --only-changelog > notes.md

Cancelling a Release ​

Pressing Ctrl+C during a release cancels it cleanly instead of treating it as a failure. With the default configuration (git.requireCleanWorkingDir enabled), the version bump, any commit already created, and any tag already created are rolled back; anything already pushed to a remote is not rolled back.

When cancelled from a terminal, the process exits with code 0: package managers treat a non-zero exit code as a failed script, for example pnpm reports ELIFECYCLE Command failed with exit code 1.. Accordingly, chained shell commands such as release && \<command\> still continue after a cancellation. Without a terminal on stdin (CI, a pipe, or a runner sending SIGINT), the exit code is 130 instead, so an interrupted run is not reported as a success by the pipeline.

For more configuration and usage options, run:

sh
release --help

Programmatic Usage ​

Besides the command line, you can also import the release function or the ReleaseManager class directly in a Node.js script:

ts
import { ReleaseManager, release } from '@neosjs/release'

// Option 1: functional helper
const result = await release({
  'ci': true,
  'dry-run': true,
  'git': { push: true }
})
// result: { name, latestVersion, version, changelog }

// Option 2: the ReleaseManager class
const manager = new ReleaseManager({
  configOptions: {
    ci: true,
    git: { requireCleanWorkingDir: true, push: true }
  }
})

try {
  const { name, latestVersion, version, changelog } = await manager.release()
  const config = manager.getConfig()
  const logger = manager.getLogger()
  logger.info(`${name}: ${latestVersion} -> ${version}`)
} catch (error: any) {
  if (error?.cancelled) {
    // The user cancelled the release (error.cancelled === true; error.code is 0 when stdin is a terminal, 130 otherwise)
  } else {
    console.error(error)
  }
}
  • new ReleaseManager({ configOptions, dependencyInjection }):
    • configOptions: release options with higher priority than local config files, with the same structure as the CLI options.
    • dependencyInjection: optional overrides for internal services (supports config, log, shell, spinner, prompt, and inquirer), commonly used for custom logging or for writing tests.
  • manager.getContainer(), manager.getConfig(), manager.getLogger(): return the container, config, and logger instances; use them only after manager.release() has initialized the container.
  • The functional helper release(options, dependencyInjection) is a convenience wrapper around ReleaseManager, and always returns Promise<{ name, latestVersion, version, changelog }>.
  • Used as a library, release() never terminates the host process: it resolves with the result on success, rejects with error.code === 0 on an early exit (for example, when there is nothing to release), and rejects with error.code === 1 on a failed release; the exit code is up to the caller.

See Programmatic API for more usage and dependency injection examples.