diff --git a/src/lib/server/pcd/deps.ts b/src/lib/server/pcd/deps.ts index f7c180b..ea03682 100644 --- a/src/lib/server/pcd/deps.ts +++ b/src/lib/server/pcd/deps.ts @@ -82,6 +82,60 @@ export async function processDependencies(pcdPath: string): Promise { } } +/** + * Get the installed version of a dependency from its manifest + */ +async function getInstalledVersion(pcdPath: string, repoName: string): Promise { + 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 { + 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 */ diff --git a/src/lib/server/pcd/pcd.ts b/src/lib/server/pcd/pcd.ts index 6d306ae..e452e3a 100644 --- a/src/lib/server/pcd/pcd.ts +++ b/src/lib/server/pcd/pcd.ts @@ -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);