From 06c7b26ab0f94796d263a9aa17500e4a53c62671 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:49:51 +0800 Subject: [PATCH] Import packages/plugin/scripts/verify-version-sync.mjs --- .../plugin/scripts/verify-version-sync.mjs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 packages/plugin/scripts/verify-version-sync.mjs diff --git a/packages/plugin/scripts/verify-version-sync.mjs b/packages/plugin/scripts/verify-version-sync.mjs new file mode 100644 index 0000000..b2f0f86 --- /dev/null +++ b/packages/plugin/scripts/verify-version-sync.mjs @@ -0,0 +1,29 @@ +import { readFileSync } from 'node:fs' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' + +const root = join(dirname(fileURLToPath(import.meta.url)), '..') +const packageJsonPath = join(root, 'package.json') +const versionPath = join(root, 'src', 'version.ts') + +const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) +const packageVersion = packageJson.version +if (typeof packageVersion !== 'string') { + throw new Error('package.json must contain a string "version".') +} + +const source = readFileSync(versionPath, 'utf8') +const match = source.match(/export const PLUGIN_VERSION\s*=\s*['"]([^'"]+)['"]/) +if (!match) { + throw new Error('Cannot find PLUGIN_VERSION declaration in src/version.ts.') +} + +const pluginVersion = match[1] +if (packageVersion !== pluginVersion) { + throw new Error( + `Version mismatch: package.json version is ${packageVersion}, but PLUGIN_VERSION is ${pluginVersion}. ` + + 'Keep these two versions in sync.' + ) +} + +console.log(`Version sync verified: ${packageVersion}`)