Files
Gabriel20xx 0ff94f9b10
Lint / Lint (push) Successful in 32s
Docker / Docker Build & Push (push) Failing after 2m22s
Tests / Go backend (push) Failing after 1m2s
Tests / Dashboard checks (push) Failing after 35s
ci: expand shared package validation and test coverage
- Add lint, formatting, vet, and publish workflow checks
- Run Go database tests with PostgreSQL and add Java tests
- Make consumer sync opt-in; update docs and Go dependency
2026-10-19 21:46:52 +00:00

141 lines
4.2 KiB
JavaScript

#!/usr/bin/env node
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const repoRoot = path.resolve(__dirname, '..', '..');
const registryBase = 'https://registry.npmjs.org';
const sections = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'];
function shouldSkipSpec(spec) {
if (!spec) return true;
const lower = spec.toLowerCase();
return (
lower.startsWith('file:') ||
lower.startsWith('workspace:') ||
lower.startsWith('link:') ||
lower.startsWith('github:') ||
lower.startsWith('git+') ||
lower.startsWith('http://') ||
lower.startsWith('https://') ||
lower.startsWith('npm:')
);
}
function isSimpleRange(spec) {
if (!spec) return false;
if (spec === '*' || spec === 'latest') return true;
if (spec.includes(' ') || spec.includes('||')) return false;
return /^[~^]?\d+(\.\d+){0,2}([-.][0-9A-Za-z-.]+)?$/.test(spec);
}
function buildNextSpec(currentSpec, latest) {
if (currentSpec === '*' || currentSpec === 'latest') {
return `^${latest}`;
}
if (currentSpec.startsWith('~')) return `~${latest}`;
if (currentSpec.startsWith('^')) return `^${latest}`;
return `^${latest}`;
}
async function fetchLatestVersion(pkgName) {
const encoded = encodeURIComponent(pkgName);
const res = await fetch(`${registryBase}/${encoded}`);
if (!res.ok) {
throw new Error(`Failed to fetch ${pkgName}: ${res.status} ${res.statusText}`);
}
const data = await res.json();
const latest = data?.['dist-tags']?.latest;
if (!latest) {
throw new Error(`Missing dist-tags.latest for ${pkgName}`);
}
return latest;
}
async function loadJson(filePath) {
const raw = await fs.readFile(filePath, 'utf8');
return JSON.parse(raw);
}
async function saveJson(filePath, data) {
const next = JSON.stringify(data, null, 2) + '\n';
await fs.writeFile(filePath, next, 'utf8');
}
async function updatePackageJson(packageJsonPath) {
const pkg = await loadJson(packageJsonPath);
let changed = false;
const changes = [];
for (const section of sections) {
const deps = pkg[section];
if (!deps) continue;
const entries = Object.entries(deps);
for (const [name, spec] of entries) {
if (shouldSkipSpec(spec) || !isSimpleRange(spec)) continue;
let latest;
try {
latest = await fetchLatestVersion(name);
} catch (err) {
console.warn(`[skip] ${name}: ${err.message}`);
continue;
}
const nextSpec = buildNextSpec(spec, latest);
if (nextSpec !== spec) {
deps[name] = nextSpec;
changed = true;
changes.push({ name, from: spec, to: nextSpec, section });
}
}
}
if (changed) {
await saveJson(packageJsonPath, pkg);
}
return { changed, changes };
}
// The root package.json declares npm workspaces (packages/*). The local packages whose dependency
// versions this repo owns and bumps directly are listed here. Vendored copies of this library in
// other repositories are not listed: any local edit to them would be overwritten by the next sync,
// so bumps for them belong upstream.
const LOCAL_PACKAGE_DIRS = ['packages/web-ui', 'packages/node-backend'];
async function main() {
const packageJsonPaths = LOCAL_PACKAGE_DIRS.map(dir => path.join(repoRoot, dir, 'package.json'));
const results = [];
for (const pkgPath of packageJsonPaths) {
try {
const result = await updatePackageJson(pkgPath);
results.push({ pkgPath, ...result });
} catch (err) {
console.error(`[error] ${pkgPath}: ${err.message}`);
}
}
const updated = results.filter(r => r.changed);
const totalChanges = updated.reduce((sum, r) => sum + r.changes.length, 0);
console.log(`Updated ${updated.length} package.json file(s).`);
console.log(`Total dependency updates: ${totalChanges}`);
for (const { pkgPath, changes } of updated) {
const rel = path.relative(repoRoot, pkgPath);
console.log(`\n${rel}`);
for (const change of changes) {
console.log(` ${change.section}: ${change.name} ${change.from} -> ${change.to}`);
}
}
}
main().catch(err => {
console.error(err);
process.exitCode = 1;
});