2026-09-04 15:02:16 +02:00
|
|
|
#!/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 };
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 21:14:31 +00:00
|
|
|
// 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'];
|
2026-09-04 15:02:16 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
});
|