Skip to content

Commit eb7f93e

Browse files
satoshai-devclaude
andcommitted
fix: inline version at build time instead of createRequire
Replace runtime `createRequire` + `package.json` read with tsup's `define` option to inline the version string at build time. This removes the dependency on package.json being on disk next to dist/ and works correctly in bundled/deploy environments. Closes #10 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3afad3d commit eb7f93e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/cli.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { createRequire } from 'node:module';
21
import { defineCommand, runMain } from 'citty';
32
import { fetchCommand } from './commands/fetch.js';
43

5-
const require = createRequire(import.meta.url);
6-
const { version } = require('../package.json') as { version: string };
4+
declare const __VERSION__: string;
75

86
const main = defineCommand({
97
meta: {
108
name: 'abi-cli',
11-
version,
9+
version: __VERSION__,
1210
description: 'Fetch Stacks contract ABIs and generate TypeScript definitions',
1311
},
1412
subCommands: {

tsup.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'tsup';
2+
import pkg from './package.json';
23

34
export default defineConfig([
45
{
@@ -14,6 +15,7 @@ export default defineConfig([
1415
{
1516
entry: ['src/cli.ts'],
1617
format: ['esm'],
18+
define: { __VERSION__: JSON.stringify(pkg.version) },
1719
banner: { js: '#!/usr/bin/env node' },
1820
sourcemap: true,
1921
splitting: false,

0 commit comments

Comments
 (0)