Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/version.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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)
})
})
9 changes: 7 additions & 2 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -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
Loading