import { readFile } from "node:fs/promises"; import path from "node:path"; import { discoverAllMigrations } from "../migrations/index.js"; import type { ModuleMigrationAggregate } from "../modules/index.js"; interface PackageVersion { readonly version?: unknown; } async function readPackageVersion(packagePath: string): Promise { const packageData = JSON.parse(await readFile(packagePath, "utf8")) as PackageVersion; if (typeof packageData.version !== "string") { throw new TypeError("A required workspace package does not declare a version."); } return packageData.version; } export async function discoverRepositoryMigrations( repositoryRoot = process.cwd(), ): Promise { const [platformVersion, moduleSdkVersion] = await Promise.all([ readPackageVersion(path.join(repositoryRoot, "package.json")), readPackageVersion(path.join(repositoryRoot, "packages/module-sdk/package.json")), ]); return discoverAllMigrations({ coreMigrationsDirectory: path.join(repositoryRoot, "core", "drizzle"), moduleDiscovery: { moduleSdkVersion, modulesDirectory: path.join(repositoryRoot, "modules"), platformVersion, }, }); }