Skip to content

Commit 5b333e2

Browse files
refactor: 从 package.json 动态读取版本号,避免版本漂移
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5e215bb commit 5b333e2

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

scripts/defines.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
import { readFileSync } from 'node:fs'
2+
import { resolve, dirname } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
5+
const __dirname = dirname(fileURLToPath(import.meta.url))
6+
const pkgPath = resolve(__dirname, '..', 'package.json')
7+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
8+
19
/**
210
* Shared MACRO define map used by both dev.ts (runtime -d flags)
311
* and build.ts (Bun.build define option).
412
*
513
* Each value is a JSON-stringified expression that replaces the
614
* corresponding MACRO.* identifier at transpile / bundle time.
15+
*
16+
* VERSION is read from package.json to avoid version drift.
717
*/
818
export function getMacroDefines(): Record<string, string> {
919
return {
10-
'MACRO.VERSION': JSON.stringify('2.1.888'),
20+
'MACRO.VERSION': JSON.stringify(pkg.version),
1121
'MACRO.BUILD_TIME': JSON.stringify(new Date().toISOString()),
1222
'MACRO.FEEDBACK_CHANNEL': JSON.stringify(''),
1323
'MACRO.ISSUES_EXPLAINER': JSON.stringify(''),

0 commit comments

Comments
 (0)