feat(agent): prepare SQLite storage package for publishing
This commit is contained in:
@@ -9,6 +9,7 @@ const packages = [
|
||||
{ directory: "packages/ai", name: "@earendil-works/pi-ai" },
|
||||
{ directory: "packages/tui", name: "@earendil-works/pi-tui" },
|
||||
{ directory: "packages/agent", name: "@earendil-works/pi-agent-core" },
|
||||
{ directory: "packages/storage/sqlite-node", name: "@earendil-works/pi-storage-sqlite-node" },
|
||||
{ directory: "packages/coding-agent", name: "@earendil-works/pi-coding-agent" },
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { existsSync, readdirSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const SKIPPED_DIRECTORIES = new Set(["dist", "node_modules"]);
|
||||
|
||||
export function findPackageDirectories(root = "packages") {
|
||||
const packageDirectories = [];
|
||||
|
||||
function visit(directory) {
|
||||
if (existsSync(join(directory, "package.json"))) {
|
||||
packageDirectories.push(directory);
|
||||
}
|
||||
|
||||
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory() || SKIPPED_DIRECTORIES.has(entry.name)) {
|
||||
continue;
|
||||
}
|
||||
visit(join(directory, entry.name));
|
||||
}
|
||||
}
|
||||
|
||||
visit(root);
|
||||
return packageDirectories.sort();
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { join } from "node:path";
|
||||
const packages = [
|
||||
{ directory: "packages/ai", name: "@earendil-works/pi-ai" },
|
||||
{ directory: "packages/agent", name: "@earendil-works/pi-agent-core" },
|
||||
{ directory: "packages/storage/sqlite-node", name: "@earendil-works/pi-storage-sqlite-node" },
|
||||
{ directory: "packages/tui", name: "@earendil-works/pi-tui" },
|
||||
{ directory: "packages/coding-agent", name: "@earendil-works/pi-coding-agent" },
|
||||
];
|
||||
|
||||
+6
-7
@@ -18,9 +18,10 @@
|
||||
* 9. Push main and the tag to trigger CI publishing
|
||||
*/
|
||||
|
||||
import { execSync } from "child_process";
|
||||
import { readFileSync, writeFileSync, readdirSync, existsSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { execSync } from "node:child_process";
|
||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { findPackageDirectories } from "./package-workspaces.mjs";
|
||||
|
||||
const RELEASE_TARGET = process.argv[2];
|
||||
const BUMP_TYPES = new Set(["major", "minor", "patch"]);
|
||||
@@ -97,10 +98,8 @@ function bumpOrSetVersion(target) {
|
||||
}
|
||||
|
||||
function getChangelogs() {
|
||||
const packagesDir = "packages";
|
||||
const packages = readdirSync(packagesDir);
|
||||
return packages
|
||||
.map((pkg) => join(packagesDir, pkg, "CHANGELOG.md"))
|
||||
return findPackageDirectories()
|
||||
.map((directory) => join(directory, "CHANGELOG.md"))
|
||||
.filter((path) => existsSync(path));
|
||||
}
|
||||
|
||||
|
||||
+48
-68
@@ -1,96 +1,76 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Syncs all workspace package dependency versions to match their current versions.
|
||||
* This ensures lockstep versioning across the monorepo.
|
||||
* Syncs all non-private workspace package dependency versions to match their current versions.
|
||||
* This ensures release packages, including unpublished packages, use lockstep versioning.
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync, readdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { findPackageDirectories } from "./package-workspaces.mjs";
|
||||
|
||||
const packagesDir = join(process.cwd(), 'packages');
|
||||
const packageDirs = readdirSync(packagesDir, { withFileTypes: true })
|
||||
.filter(dirent => dirent.isDirectory())
|
||||
.map(dirent => dirent.name);
|
||||
const packages = findPackageDirectories()
|
||||
.map((directory) => {
|
||||
const path = join(directory, "package.json");
|
||||
return { data: JSON.parse(readFileSync(path, "utf8")), path };
|
||||
})
|
||||
.filter((pkg) => pkg.data.private !== true);
|
||||
|
||||
// Read all package.json files and build version map
|
||||
const packages = {};
|
||||
const versionMap = {};
|
||||
const versionMap = new Map(packages.map((pkg) => [pkg.data.name, pkg.data.version]));
|
||||
|
||||
for (const dir of packageDirs) {
|
||||
const pkgPath = join(packagesDir, dir, 'package.json');
|
||||
try {
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
||||
packages[dir] = { path: pkgPath, data: pkg };
|
||||
versionMap[pkg.name] = pkg.version;
|
||||
} catch (e) {
|
||||
console.error(`Failed to read ${pkgPath}:`, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Current versions:');
|
||||
for (const [name, version] of Object.entries(versionMap).sort()) {
|
||||
console.log("Current versions:");
|
||||
for (const [name, version] of [...versionMap].sort(([a], [b]) => a.localeCompare(b))) {
|
||||
console.log(` ${name}: ${version}`);
|
||||
}
|
||||
|
||||
// Verify all versions are the same (lockstep)
|
||||
const versions = new Set(Object.values(versionMap));
|
||||
const versions = new Set(versionMap.values());
|
||||
if (versions.size > 1) {
|
||||
console.error('\n❌ ERROR: Not all packages have the same version!');
|
||||
console.error('Expected lockstep versioning. Run one of:');
|
||||
console.error(' npm run version:patch');
|
||||
console.error(' npm run version:minor');
|
||||
console.error(' npm run version:major');
|
||||
console.error("\nERROR: Not all non-private packages have the same version.");
|
||||
console.error("Expected lockstep versioning. Run one of:");
|
||||
console.error(" npm run version:patch");
|
||||
console.error(" npm run version:minor");
|
||||
console.error(" npm run version:major");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('\n✅ All packages at same version (lockstep)');
|
||||
console.log("\nAll non-private packages are at the same version (lockstep).");
|
||||
|
||||
// Update all inter-package dependencies
|
||||
let totalUpdates = 0;
|
||||
for (const [dir, pkg] of Object.entries(packages)) {
|
||||
for (const pkg of packages) {
|
||||
let updated = false;
|
||||
|
||||
// Check dependencies
|
||||
if (pkg.data.dependencies) {
|
||||
for (const [depName, currentVersion] of Object.entries(pkg.data.dependencies)) {
|
||||
if (versionMap[depName]) {
|
||||
const newVersion = `^${versionMap[depName]}`;
|
||||
if (currentVersion !== newVersion) {
|
||||
console.log(`\n${pkg.data.name}:`);
|
||||
console.log(` ${depName}: ${currentVersion} → ${newVersion}`);
|
||||
pkg.data.dependencies[depName] = newVersion;
|
||||
updated = true;
|
||||
totalUpdates++;
|
||||
}
|
||||
|
||||
for (const dependencyType of ["dependencies", "devDependencies"]) {
|
||||
const dependencies = pkg.data[dependencyType];
|
||||
if (!dependencies) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const [dependencyName, currentVersion] of Object.entries(dependencies)) {
|
||||
const dependencyVersion = versionMap.get(dependencyName);
|
||||
if (!dependencyVersion) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const newVersion = `^${dependencyVersion}`;
|
||||
if (currentVersion === newVersion) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`\n${pkg.data.name}:`);
|
||||
console.log(` ${dependencyName}: ${currentVersion} → ${newVersion}${dependencyType === "devDependencies" ? " (devDependencies)" : ""}`);
|
||||
dependencies[dependencyName] = newVersion;
|
||||
updated = true;
|
||||
totalUpdates++;
|
||||
}
|
||||
}
|
||||
|
||||
// Check devDependencies
|
||||
if (pkg.data.devDependencies) {
|
||||
for (const [depName, currentVersion] of Object.entries(pkg.data.devDependencies)) {
|
||||
if (versionMap[depName]) {
|
||||
const newVersion = `^${versionMap[depName]}`;
|
||||
if (currentVersion !== newVersion) {
|
||||
console.log(`\n${pkg.data.name}:`);
|
||||
console.log(` ${depName}: ${currentVersion} → ${newVersion} (devDependencies)`);
|
||||
pkg.data.devDependencies[depName] = newVersion;
|
||||
updated = true;
|
||||
totalUpdates++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write if updated
|
||||
|
||||
if (updated) {
|
||||
writeFileSync(pkg.path, JSON.stringify(pkg.data, null, '\t') + '\n');
|
||||
writeFileSync(pkg.path, `${JSON.stringify(pkg.data, null, "\t")}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
if (totalUpdates === 0) {
|
||||
console.log('\nAll inter-package dependencies already in sync.');
|
||||
console.log("\nAll inter-package dependencies are already in sync.");
|
||||
} else {
|
||||
console.log(`\n✅ Updated ${totalUpdates} dependency version(s)`);
|
||||
console.log(`\nUpdated ${totalUpdates} dependency version(s).`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user