Something went wrong. Try again.
more up to date at codeberg https://codeberg.org/cowie/tau.git
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124#!/usr/bin/env node
/** * Syncs all workspace package dependency versions to match their current versions. * This ensures lockstep versioning across the monorepo. */
import { readFileSync, writeFileSync, readdirSync } from 'fs';import { join } from 'path';
const root = process.cwd();const rootPkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));const workspaces = rootPkg.workspaces || [];
// Expand workspace entries: "packages/*" -> all subdirs, literal paths as-isfunction expandWorkspace(pattern) { if (pattern.endsWith('/*')) { const dir = pattern.slice(0, -2); try { return readdirSync(join(root, dir), { withFileTypes: true }) .filter(d => d.isDirectory()) .map(d => join(root, dir, d.name)); } catch { return []; } } return [join(root, pattern)];}
const allWorkspaceDirs = workspaces.flatMap(expandWorkspace);
// Core packages are direct children of packages/ — these get version-bumped and lockstep-checked.// Extension/example packages only get their cross-deps updated.const packagesDir = join(root, 'packages');const coreWorkspaceDirs = allWorkspaceDirs.filter(d => { const rel = d.replace(packagesDir + '/', ''); return !rel.includes('/');});
// Read all package.json files and build version mapconst packages = {};const versionMap = {};
for (const dir of allWorkspaceDirs) { const pkgPath = join(dir, 'package.json'); try { const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); packages[dir] = { path: pkgPath, data: pkg, isCore: coreWorkspaceDirs.includes(dir) }; 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(` ${name}: ${version}`);}
// Verify core packages are all at the same version (lockstep)const coreVersions = new Set( Object.entries(packages) .filter(([, p]) => p.isCore) .map(([, p]) => p.data.version));const versions = coreVersions;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'); process.exit(1);}
console.log('\n✅ All packages at same version (lockstep)');
// Update all inter-package dependencieslet totalUpdates = 0;for (const [dir, pkg] of Object.entries(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++; } } } } // 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'); }}
if (totalUpdates === 0) { console.log('\nAll inter-package dependencies already in sync.');} else { console.log(`\n✅ Updated ${totalUpdates} dependency version(s)`);}