Skip to content

Commit c01635e

Browse files
committed
chore: sync constants version with lit-client
1 parent 3384a3c commit c01635e

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"version": "0.0.1",
44
"license": "MIT",
55
"scripts": {
6+
"sync-version": "node ./scripts/sync-version.mjs",
67
"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",
78
"go": "bun run build && bun link-all",
8-
"build": "bun unlink-all && nx run-many --parallel=false --target=build --all --exclude=wrapped-keys,wrapped-keys-lit-actions && bun run prettier",
9+
"build": "bun run sync-version && nx run-many --parallel=false --target=build --all --exclude=wrapped-keys,wrapped-keys-lit-actions && bun run prettier",
910
"build:affected": "nx affected --target=build --exclude=wrapped-keys,wrapped-keys-lit-actions",
1011
"check-deps": "npx nx run-many --target=check-deps --exclude=wrapped-keys,wrapped-keys-lit-actions",
1112
"validate": "npm run check-deps && npm run build",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export const version = '8.0.0-alpha.4';
1+
// This value is kept in sync with @lit-protocol/lit-client via scripts/sync-version.mjs, run by the build command.
2+
export const version = '8.0.0';

scripts/sync-version.mjs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env node
2+
3+
import { readFile, writeFile } from 'node:fs/promises';
4+
import { dirname, resolve } from 'node:path';
5+
import { fileURLToPath } from 'node:url';
6+
7+
// Anchor paths relative to repo root so the script works from any cwd.
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = dirname(__filename);
10+
const repoRoot = resolve(__dirname, '..');
11+
12+
// Matches the exported version constant in packages/constants/src/lib/version.ts.
13+
const VERSION_EXPORT_PATTERN = /export const version = ['"]([^'\"]+)['"];?/;
14+
15+
async function main() {
16+
const litClientPackageJsonPath = resolve(
17+
repoRoot,
18+
'packages',
19+
'lit-client',
20+
'package.json'
21+
);
22+
const versionFilePath = resolve(
23+
repoRoot,
24+
'packages',
25+
'constants',
26+
'src',
27+
'lib',
28+
'version.ts'
29+
);
30+
31+
const litClientPackageJson = JSON.parse(
32+
await readFile(litClientPackageJsonPath, 'utf8')
33+
);
34+
const litClientVersion = litClientPackageJson.version;
35+
36+
if (!litClientVersion) {
37+
throw new Error(`Version not found in ${litClientPackageJsonPath}`);
38+
}
39+
40+
const versionFileContents = await readFile(versionFilePath, 'utf8');
41+
const match = versionFileContents.match(VERSION_EXPORT_PATTERN);
42+
43+
if (!match) {
44+
throw new Error(
45+
`Could not find exported version constant in ${versionFilePath}`
46+
);
47+
}
48+
49+
const currentVersion = match[1];
50+
51+
if (currentVersion === litClientVersion) {
52+
console.log(`version.ts already in sync (${currentVersion})`);
53+
return;
54+
}
55+
56+
// Rewrite the version export so it mirrors the lit-client package version.
57+
const updatedContents = versionFileContents.replace(
58+
VERSION_EXPORT_PATTERN,
59+
`export const version = '${litClientVersion}';`
60+
);
61+
62+
await writeFile(versionFilePath, updatedContents);
63+
console.log(`Updated version.ts to ${litClientVersion}`);
64+
}
65+
66+
main().catch((error) => {
67+
console.error(error);
68+
process.exitCode = 1;
69+
});

0 commit comments

Comments
 (0)