Custom Version Files and Non-npm Projects
@neosjs/release does not depend on package.json: when the directory has no package.json (or the npm plugin is disabled with npm: false), the built-in git, changelog, github, gitlab, pr, and version plugins still work on their own.
The two most common custom version management approaches are shown below.
Approach 1: Write a Local Plugin That Takes Over a Standalone Version File (such as VERSION / pyproject.toml / Cargo.toml)
When a project has no package.json and stores its version in a standalone file instead (for example, a VERSION file in the root directory), all you need is a local plugin of about a dozen lines.
1. Create ./scripts/version-file-plugin.mjs
import fs from 'node:fs'
import { Plugin } from '@neosjs/release'
export default class VersionFilePlugin extends Plugin {
static disablePlugin() {
// Disable the built-in npm plugin (it would not be enabled anyway without a package.json)
return ['npm']
}
get filePath() {
return this.options.file || 'VERSION'
}
getLatestVersion() {
if (!fs.existsSync(this.filePath)) return null
return fs.readFileSync(this.filePath, 'utf8').trim()
}
bump(version) {
if (this.config.isDryRun) return
fs.writeFileSync(this.filePath, `${version}\n`, 'utf8')
}
}2. Enable It in release.config.ts
import { defineConfig } from '@neosjs/release'
export default defineConfig({
plugins: {
'./scripts/version-file-plugin.mjs': {
file: 'VERSION'
}
},
git: {
commitMessage: 'chore: release v${version}',
tagName: 'v${version}',
push: true
},
github: {
release: true
}
})Because getLatestVersion() and bump() of an external plugin both run before the built-in plugins:
getLatestVersion()reads the version fromVERSIONfirst;- after
bump(version)writes the new version, the built-ingitplugin automatically stages the file inbeforeReleaseand commits it together withCHANGELOG.md(this requiresVERSIONto be tracked by Git; for a newly created file, enablegit.addUntrackedFiles: trueor callawait this.exec(['git', 'add', this.filePath])in the plugin).
Approach 2: Use the after:bump Hook to Sync the Version to Multiple Files
If the project still uses package.json as its primary version source but you want the version to be written to additional files at release time (for example src/version.ts, manifest.json, or a sub-package manifest), the after:bump hook is all you need:
scripts/sync-version.mjs:
import fs from 'node:fs'
const version = process.argv[2]
if (!version) {
console.error('Missing version argument')
process.exit(1)
}
fs.writeFileSync('src/version.ts', `export const VERSION = '${version}'\n`, 'utf8')release.config.ts:
import { defineConfig } from '@neosjs/release'
export default defineConfig({
hooks: {
// Runs before git stages and commits, so changes to tracked files are included in the release commit automatically
'after:bump': 'node ./scripts/sync-version.mjs ${version}'
}
})If the sync script also modifies new untracked files, remember to enable git.addUntrackedFiles: true in the configuration, or run git add yourself at the end of the script.