diff --git a/src/version.spec.ts b/src/version.spec.ts index 55fb674..0758d18 100644 --- a/src/version.spec.ts +++ b/src/version.spec.ts @@ -1,5 +1,9 @@ +import { createRequire } from 'node:module' import { describe, it, expect } from 'vitest' import { VERSION } from './version.js' +import { getVersion } from './get-version.js' +const require = createRequire(import.meta.url) +const pkg: { version: string } = require('../package.json') describe('VERSION', () => { it('should be defined', () => { @@ -13,4 +17,8 @@ describe('VERSION', () => { it('should be a valid semver format', () => { expect(VERSION).toMatch(/^\d+\.\d+\.\d+/) }) + + it('should equal the version in package.json', () => { + expect(getVersion()).toBe(pkg.version) + }) }) diff --git a/src/version.ts b/src/version.ts index 01c46c5..6738c64 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,4 +1,9 @@ +import { createRequire } from 'node:module' /** - * Centy version constant + * Centy version constant, read from the package's own package.json. + * Works from both src/ (tests) and dist/ (built CLI): both sit one level below the package root. */ -export const VERSION = '0.0.0' +const require = createRequire(import.meta.url) +const pkg: { version: string } = require('../package.json') + +export const VERSION: string = pkg.version