feat(dependencies): implement syncDependencies to update dependency versions from manifest

This commit is contained in:
Sam Chau
2025-12-28 18:59:06 +10:30
parent 8066df5f92
commit 66095f6be1
2 changed files with 58 additions and 1 deletions

View File

@@ -82,6 +82,60 @@ export async function processDependencies(pcdPath: string): Promise<void> {
}
}
/**
* Get the installed version of a dependency from its manifest
*/
async function getInstalledVersion(pcdPath: string, repoName: string): Promise<string | null> {
const depManifestPath = `${pcdPath}/deps/${repoName}/pcd.json`;
try {
const content = await Deno.readTextFile(depManifestPath);
const manifest = JSON.parse(content);
return manifest.version ?? null;
} catch {
return null;
}
}
/**
* Sync dependencies - update any that have changed versions in the manifest
* Called after pulling updates to ensure dependencies match manifest requirements
*/
export async function syncDependencies(pcdPath: string): Promise<void> {
const manifest = await loadManifest(pcdPath);
if (!manifest.dependencies || Object.keys(manifest.dependencies).length === 0) {
return;
}
// Ensure deps directory exists
const depsDir = `${pcdPath}/deps`;
await Deno.mkdir(depsDir, { recursive: true });
for (const [repoUrl, requiredVersion] of Object.entries(manifest.dependencies)) {
const repoName = getRepoName(repoUrl);
const depPath = getDependencyPath(pcdPath, repoName);
const installedVersion = await getInstalledVersion(pcdPath, repoName);
if (installedVersion === requiredVersion) {
// Already at correct version, skip
continue;
}
// Version changed or not installed - remove old and clone new
try {
await Deno.remove(depPath, { recursive: true });
} catch {
// Didn't exist, that's fine
}
// Clone and checkout the new version
await cloneDependency(pcdPath, repoUrl, requiredVersion);
// Validate the dependency's manifest
await loadManifest(depPath);
}
}
/**
* Check if all dependencies are present and valid
*/

View File

@@ -7,7 +7,7 @@ import { databaseInstancesQueries } from '$db/queries/databaseInstances.ts';
import type { DatabaseInstance } from '$db/queries/databaseInstances.ts';
import { loadManifest, type Manifest } from './manifest.ts';
import { getPCDPath } from './paths.ts';
import { processDependencies } from './deps.ts';
import { processDependencies, syncDependencies } from './deps.ts';
import { notificationManager } from '$notifications/NotificationManager.ts';
import { compile, invalidate, startWatch, getCache } from './cache.ts';
import { logger } from '$logger/logger.ts';
@@ -178,6 +178,9 @@ class PCDManager {
// Pull updates
await git.pull(instance.local_path);
// Sync dependencies (schema, etc.) if versions changed
await syncDependencies(instance.local_path);
// Update last_synced_at
databaseInstancesQueries.updateSyncedAt(id);