diff --git a/scripts/defines.ts b/scripts/defines.ts index 6098d1733..3249e6809 100644 --- a/scripts/defines.ts +++ b/scripts/defines.ts @@ -1,13 +1,23 @@ +import { readFileSync } from 'node:fs' +import { resolve, dirname } from 'node:path' +import { fileURLToPath } from 'node:url' + +const __dirname = dirname(fileURLToPath(import.meta.url)) +const pkgPath = resolve(__dirname, '..', 'package.json') +const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) + /** * Shared MACRO define map used by both dev.ts (runtime -d flags) * and build.ts (Bun.build define option). * * Each value is a JSON-stringified expression that replaces the * corresponding MACRO.* identifier at transpile / bundle time. + * + * VERSION is read from package.json to avoid version drift. */ export function getMacroDefines(): Record { return { - 'MACRO.VERSION': JSON.stringify('2.1.888'), + 'MACRO.VERSION': JSON.stringify(pkg.version), 'MACRO.BUILD_TIME': JSON.stringify(new Date().toISOString()), 'MACRO.FEEDBACK_CHANNEL': JSON.stringify(''), 'MACRO.ISSUES_EXPLAINER': JSON.stringify(''),