Programmatic API
Besides the command line, @neosjs/release can be used as a Node.js / TypeScript library directly in scripts, build tools, or internal platforms.
Functional API: release()
release(options?, dependencyInjection?) is the simplest entry point and returns Promise<ReleaseResult>:
import { release } from '@neosjs/release'
const result = await release({
'ci': true,
'dry-run': true,
'git': {
push: true
},
'npm': {
publish: false
}
})
// result: { name, latestVersion, version, changelog }
console.log(`${result.name}: ${result.latestVersion} -> ${result.version}`)Class-based API: ReleaseManager
Use ReleaseManager when you need to access the internal container, the final merged config object, or the logger after the release has finished:
import { ReleaseManager } from '@neosjs/release'
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(`Released: ${name} ${latestVersion} -> ${version}`)
logger.info(`Tag name: ${config.getContext('tagName')}`)
} catch (error: any) {
if (error?.cancelled) {
// The user cancelled with Ctrl+C / Esc (error.cancelled === true; error.code is 0 when stdin is a terminal, 130 otherwise)
console.log('Release cancelled')
} else {
console.error('Release failed:', error)
process.exitCode = Number.isInteger(error?.code) ? error.code : 1
}
}
manager.getContainer(),manager.getConfig(), andmanager.getLogger()must be used aftermanager.release()has initialized the container.
Behavior When Used as a Library
Compared with the command line, release() / manager.release() behaves as follows when used as a library:
- It never terminates the process:
process.exit()is never called. An early exit (for example, nothing to release, or no new commits while failure is not required) rejects with an error whoseerror.code === 0; a real failure haserror.codeof1; the exit code is up to the caller. - It does not take over the host process's global errors: it installs no
uncaughtException/unhandledRejectionhandlers, so uncaught errors are handed to the host environment as usual. - Results are returned: with
'release-version': true/'only-changelog': true, it no longer writes tostdoutand then exits; it returnsReleaseResultas usual (take itsversion/changelogfield) and likewise only calculates, without performing the release. Ctrl+C:release()rejects with an error whoseerror.cancelled === true(error.codeis0when stdin is a terminal,130otherwise), the host process keeps running, and hooks after the cancellation are no longer executed.- Rollback timing: on the command line the process exits when the release ends, and the rollback runs when the process exits; when used as a library the process does not exit, so the rollback runs immediately when
release()ends (with a failure or a cancellation) instead of waiting to modify the repository until the host process exits.
After each call finishes, the process-level listeners registered by the release flow (the SIGINT handler, the rollback hooked into exit, etc.) are cleaned up: release() can be called multiple times in the same process, and it can coexist with the host's own SIGINT handling.
Programmatic-only Options
When passed in through configOptions, the following c12 loading control options are supported in addition to the regular configuration options:
| Option | Description |
|---|---|
config | Set to false to disable reading local config files, or pass a custom config file path |
configDir | The directory in which to look for local config files (default process.cwd()) |
extend | Extra config sources to extend from, passed to c12 |
defaultConfig | An additional default config object passed to c12 |
Dependency Injection (dependencyInjection)
Dependency injection is useful for customizing log output, intercepting the opening of the browser, or writing unit tests. The following internal components can be replaced:
config: a customConfiginstancelog: a custom logger (it must implementlog,info,success,warn,error,verbose,exec,preview, and the other methods)shell: a custom shell executorspinner: a custom progress indicatorprompt: a custom interactive prompterinquirer: replaces the underlyinginquirerinstanceopenUrl: a custom browser-opening function(url, options) => Promise<any>for Release-via-PR
Example (silently capturing all logs):
import { ReleaseManager } from '@neosjs/release'
const logs: string[] = []
const customLog = {
log: (...args: any[]) => logs.push(args.join(' ')),
info: (...args: any[]) => logs.push(`[INFO] ${args.join(' ')}`),
success: (...args: any[]) => logs.push(`[OK] ${args.join(' ')}`),
warn: (...args: any[]) => logs.push(`[WARN] ${args.join(' ')}`),
error: (...args: any[]) => logs.push(`[ERR] ${args.join(' ')}`),
verbose: () => {},
debug: () => {},
exec: () => {},
obtrusive: (...args: any[]) => logs.push(args.join(' ')),
preview: () => {},
boxenLog: () => {}
}
const manager = new ReleaseManager({
configOptions: {
'config': false,
'ci': true,
'dry-run': true
},
dependencyInjection: {
log: customLog
}
})
const result = await manager.release()
console.log({ result, logs })