Per owner decision: MediaEngine (the Media product family's Go backend and SvelteKit frontend, previously its own repo referenced by 7 thin service repos via git submodule) is folded directly into shared/ as media-backend/ and media-webui/, rather than staying separate. media-backend/go.mod's replace directive now points at ../backend (a true sibling within this repo) instead of a vendored ../shared/backend copy, since there's no more nested vendoring - it's the real thing. Also moved MediaEngine's own CI (media-backend-lint.yml, media-backend-tests.yml) and dev tooling scripts (scripts/media/*, audit/lint/enforce scripts for the media-backend+media-webui content), fixing their path assumptions for the new layout, and dropped scripts/media/sync-shared.mjs (confirmed dead code, and now doubly obsolete since there's no more vendored shared/ subfolder for it to check). Added media:* script aliases to package.json for the moved tooling, namespaced to avoid colliding with this repo's own scripts. Also fixed sync-consumers.ps1's workspace-root resolution to walk up until it finds a directory containing both Original/ and Forks/, instead of assuming shared/ is always a direct child of the workspace root - it broke when shared/ moved from Web/shared to Web/Central/shared earlier in this same restructuring. Removed the now-obsolete Original/MediaEngine entry from its consumer list. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
143 lines
4.6 KiB
JavaScript
143 lines
4.6 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 };
|
|
}
|
|
|
|
// MediaEngine has no root package.json / npm workspaces (unlike the monorepo this was extracted
|
|
// from), so there's no "workspaces" array to discover packages from. webui/ is the only local npm
|
|
// package whose dependency versions this repo owns and should bump directly. shared/package.json
|
|
// is intentionally excluded: it's a vendored, byte-for-byte copy synced in from the separate
|
|
// shared repo (see scripts/sync-shared.mjs) and any local edit to it would just be overwritten by
|
|
// the next sync — dependency bumps for shared/ belong upstream in that repo instead.
|
|
const LOCAL_PACKAGE_DIRS = ['media-webui'];
|
|
|
|
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;
|
|
});
|