Skip to content

Commit 80f9b88

Browse files
authored
mono - feat: adding in version sync across all packages (#1839)
* mono - feat: adding in version sync across all packages * Update version-sync.ts * moving to using yaml
1 parent da2a5a1 commit 80f9b88

20 files changed

Lines changed: 129 additions & 28 deletions

File tree

compression/compress-brotli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@keyv/compress-brotli",
3-
"version": "2.0.5",
3+
"version": "6.0.0-alpha.1",
44
"description": "brotli compression for keyv",
55
"type": "module",
66
"main": "./dist/index.js",

compression/compress-gzip/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@keyv/compress-gzip",
3-
"version": "2.0.3",
3+
"version": "6.0.0-alpha.1",
44
"description": "gzip compression for keyv",
55
"type": "module",
66
"main": "./dist/index.js",

compression/compress-lz4/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@keyv/compress-lz4",
3-
"version": "1.0.1",
3+
"version": "6.0.0-alpha.1",
44
"description": "lz4 compression for Keyv",
55
"type": "module",
66
"main": "./dist/index.js",

core/keyv/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "keyv",
3-
"version": "5.6.0",
3+
"version": "6.0.0-alpha.1",
44
"description": "Simple key-value storage with support for multiple backends",
55
"type": "module",
66
"main": "dist/index.js",

core/test-suite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@keyv/test-suite",
3-
"version": "2.1.2",
3+
"version": "6.0.0-alpha.1",
44
"description": "Test suite for Keyv API compliancy",
55
"type": "module",
66
"main": "./dist/index.js",

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@keyv/mono-repo",
3-
"version": "1.0.0",
3+
"version": "6.0.0-alpha.1",
44
"type": "module",
55
"description": "Keyv Mono Repo",
66
"repository": "https://github.com/jaredwray/keyv.git",
@@ -16,14 +16,18 @@
1616
"test:services:stop": "chmod +x ./scripts/test-services-stop.sh && ./scripts/test-services-stop.sh",
1717
"website:build": "pnpm recursive --filter @keyv/website run website:build",
1818
"website:serve": "pnpm recursive --filter @keyv/website run website:serve",
19-
"clean": "rimraf node_modules pnpm-lock.yaml && pnpm recursive run clean"
19+
"clean": "rimraf node_modules pnpm-lock.yaml && pnpm recursive run clean",
20+
"version:sync": "pnpm tsx scripts/version-sync.ts"
2021
},
2122
"devDependencies": {
2223
"@biomejs/biome": "^2.3.13",
24+
"@types/js-yaml": "^4.0.9",
2325
"@types/node": "^24.10.1",
2426
"@vitest/coverage-v8": "^4.0.18",
27+
"js-yaml": "^4.1.1",
2528
"rimraf": "^6.1.2",
2629
"tsup": "^8.5.1",
30+
"tsx": "^4.21.0",
2731
"typescript": "^5.9.3",
2832
"vitest": "^4.0.18"
2933
},

pnpm-lock.yaml

Lines changed: 23 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/version-sync.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import yaml from "js-yaml";
4+
5+
const rootDir = path.resolve(import.meta.dirname, "..");
6+
7+
// Read the root package.json version
8+
const rootPackagePath = path.join(rootDir, "package.json");
9+
const rootPackage = JSON.parse(fs.readFileSync(rootPackagePath, "utf-8")) as { version: string };
10+
const { version } = rootPackage;
11+
12+
console.log(`Syncing version: ${version}`);
13+
14+
// Parse pnpm-workspace.yaml to get workspace globs
15+
const workspaceYamlPath = path.join(rootDir, "pnpm-workspace.yaml");
16+
const workspaceConfig = yaml.load(fs.readFileSync(workspaceYamlPath, "utf-8")) as { packages?: string[] };
17+
const globs: string[] = workspaceConfig.packages ?? [];
18+
19+
// Ensure a resolved path is within the project root to prevent path traversal
20+
function safePath(unsafePath: string): string | undefined {
21+
const resolved = path.resolve(rootDir, unsafePath);
22+
if (!resolved.startsWith(rootDir + path.sep) && resolved !== rootDir) {
23+
console.warn(` Skipping path outside project root: ${unsafePath}`);
24+
return undefined;
25+
}
26+
27+
return resolved;
28+
}
29+
30+
// Resolve globs to actual package directories
31+
const packageDirs: string[] = [];
32+
for (const glob of globs) {
33+
if (glob.endsWith("/*")) {
34+
// Wildcard glob — enumerate subdirectories
35+
const parentDir = safePath(glob.replace("/*", ""));
36+
if (parentDir && fs.existsSync(parentDir)) {
37+
for (const entry of fs.readdirSync(parentDir, { withFileTypes: true })) {
38+
if (entry.isDirectory()) {
39+
const dir = path.join(parentDir, entry.name);
40+
if (safePath(path.relative(rootDir, dir))) {
41+
packageDirs.push(dir);
42+
}
43+
}
44+
}
45+
}
46+
} else {
47+
// Exact path
48+
const dir = safePath(glob);
49+
if (dir && fs.existsSync(dir)) {
50+
packageDirs.push(dir);
51+
}
52+
}
53+
}
54+
55+
// Update each package.json
56+
let updated = 0;
57+
let skipped = 0;
58+
for (const dir of packageDirs) {
59+
const pkgPath = path.join(dir, "package.json");
60+
if (!fs.existsSync(pkgPath)) {
61+
continue;
62+
}
63+
64+
const raw = fs.readFileSync(pkgPath, "utf-8");
65+
const pkg = JSON.parse(raw) as { name: string; version: string };
66+
67+
if (pkg.version === version) {
68+
skipped++;
69+
continue;
70+
}
71+
72+
const oldVersion = pkg.version;
73+
pkg.version = version;
74+
75+
// Preserve original formatting (detect indent)
76+
const indent = raw.match(/^(\s+)"/m)?.[1] ?? "\t";
77+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, indent) + "\n");
78+
79+
console.log(` ${pkg.name}: ${oldVersion}${version}`);
80+
updated++;
81+
}
82+
83+
console.log(`\nDone: ${updated} updated, ${skipped} skipped (version ${version})`);

serialization/serialize/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@keyv/serialize",
3-
"version": "1.1.1",
3+
"version": "6.0.0-alpha.1",
44
"description": "Serialization for Keyv",
55
"type": "module",
66
"main": "./dist/index.js",

storage/bigmap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@keyv/bigmap",
3-
"version": "1.3.1",
3+
"version": "6.0.0-alpha.1",
44
"description": "Bigmap for Keyv",
55
"type": "module",
66
"main": "dist/index.js",

0 commit comments

Comments
 (0)