Skip to content

Commit ef2ec29

Browse files
theoephraimclaude
andcommitted
Add --version flag with build-time version injection via tsdown
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b73d2c0 commit ef2ec29

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

packages/bumpy/src/cli.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { findRoot } from './core/config.ts';
44
import { log, colorize } from './utils/logger.ts';
5+
import { getVersion } from './version-info.ts';
56

67
const args = process.argv.slice(2);
78
const command = args[0];
@@ -143,6 +144,11 @@ async function main() {
143144
break;
144145
}
145146

147+
case '--version':
148+
case '-v':
149+
console.log(`bumpy ${getVersion()}`);
150+
break;
151+
146152
case 'help':
147153
case '--help':
148154
case '-h':
@@ -163,7 +169,7 @@ async function main() {
163169

164170
function printHelp() {
165171
console.log(`
166-
${colorize('🐸 bumpy', 'bold')} - Modern monorepo versioning
172+
${colorize(`🐸 bumpy v${getVersion()}`, 'bold')} - Modern monorepo versioning
167173
168174
Usage: bumpy <command> [options]
169175

packages/bumpy/src/version-info.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare const __BUMPY_VERSION__: string | undefined;
2+
3+
/** Get the bumpy version. Injected at build time by tsdown, falls back to "dev" when running from source. */
4+
export function getVersion(): string {
5+
return typeof __BUMPY_VERSION__ !== 'undefined' ? __BUMPY_VERSION__ : 'dev';
6+
}

packages/bumpy/tsdown.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { defineConfig } from 'tsdown';
2+
import { readFileSync } from 'node:fs';
3+
4+
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
25

36
export default defineConfig({
47
entry: {
@@ -8,4 +11,7 @@ export default defineConfig({
811
format: 'esm',
912
dts: true,
1013
clean: true,
14+
define: {
15+
__BUMPY_VERSION__: JSON.stringify(pkg.version),
16+
},
1117
});

0 commit comments

Comments
 (0)