diff --git a/package.json b/package.json index 542b86dea..862c033c5 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,10 @@ "version": "0.0.1", "license": "MIT", "scripts": { + "sync-version": "node ./scripts/sync-version.mjs", "reset": "bun unlink-all && rimraf dist node_modules doc tmp yarn-error.log yarn.lock package-lock.json bun.lockb learn-debug.log tmp .nx lit-auth-storage pkp-tokens lit-auth-local ./e2e/dist ./e2e/node_modules", "go": "bun run build && bun link-all", - "build": "bun unlink-all && nx run-many --parallel=false --target=build --all --exclude=wrapped-keys,wrapped-keys-lit-actions && bun run prettier", + "build": "bun run sync-version && nx run-many --parallel=false --target=build --all --exclude=wrapped-keys,wrapped-keys-lit-actions && bun run prettier", "build:affected": "nx affected --target=build --exclude=wrapped-keys,wrapped-keys-lit-actions", "check-deps": "npx nx run-many --target=check-deps --exclude=wrapped-keys,wrapped-keys-lit-actions", "validate": "npm run check-deps && npm run build", diff --git a/packages/constants/src/lib/version.ts b/packages/constants/src/lib/version.ts index d8c01196c..4a0e26633 100644 --- a/packages/constants/src/lib/version.ts +++ b/packages/constants/src/lib/version.ts @@ -1 +1,2 @@ -export const version = '8.0.0-alpha.4'; +// This value is kept in sync with @lit-protocol/lit-client via scripts/sync-version.mjs, run by the build command. +export const version = '8.0.0'; diff --git a/scripts/sync-version.mjs b/scripts/sync-version.mjs new file mode 100644 index 000000000..f1175ca22 --- /dev/null +++ b/scripts/sync-version.mjs @@ -0,0 +1,83 @@ +#!/usr/bin/env node + +import { readFile, writeFile } from 'node:fs/promises'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// Anchor paths relative to repo root so the script works from any cwd. +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const repoRoot = resolve(__dirname, '..'); + +// Matches the exported version constant in packages/constants/src/lib/version.ts. +const VERSION_EXPORT_PATTERN = /export const version = ['"]([^'\"]+)['"];?/; + +async function main() { + const litClientPackageJsonPath = resolve( + repoRoot, + 'packages', + 'lit-client', + 'package.json' + ); + const versionFilePath = resolve( + repoRoot, + 'packages', + 'constants', + 'src', + 'lib', + 'version.ts' + ); + + let litClientPackageJson; + try { + litClientPackageJson = JSON.parse( + await readFile(litClientPackageJsonPath, 'utf8') + ); + } catch (err) { + throw new Error( + `Failed to read or parse package.json at ${litClientPackageJsonPath}: ${err.message}` + ); + } + const litClientVersion = litClientPackageJson.version; + + if (!litClientVersion) { + throw new Error(`Version not found in ${litClientPackageJsonPath}`); + } + + let versionFileContents; + try { + versionFileContents = await readFile(versionFilePath, 'utf8'); + } catch (err) { + throw new Error( + `Failed to read version file at ${versionFilePath}: ${err.message}` + ); + } + const match = versionFileContents.match(VERSION_EXPORT_PATTERN); + + if (!match) { + throw new Error( + `Could not find exported version constant in ${versionFilePath}` + ); + } + + const currentVersion = match[1]; + + if (currentVersion === litClientVersion) { + console.log(`version.ts already in sync (${currentVersion})`); + return; + } + + // Rewrite the version export so it mirrors the lit-client package version. + const updatedContents = versionFileContents.replace( + VERSION_EXPORT_PATTERN, + `export const version = '${litClientVersion}';` + ); + + await writeFile(versionFilePath, updatedContents); + console.log(`Updated version.ts to ${litClientVersion}`); +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +});