import semver from "semver"; import { ERP_KIT_PACKAGE_NAME } from "../../../../util"; import { isNonSemverSpecifier, passthroughResolver, readDeclaredVersion, type SpecifierResolver, type VersionFinding, type WorkspacePackage, } from "./shared"; export function checkErpKitVersion( packages: WorkspacePackage[], installedVersion: string, resolve: SpecifierResolver = passthroughResolver, ): VersionFinding[] { const findings: VersionFinding[] = []; for (const pkg of packages) { const raw = readDeclaredVersion(pkg.manifest, ERP_KIT_PACKAGE_NAME); if (raw === undefined) continue; if (raw.startsWith("workspace:")) { findings.push({ severity: "info", check: "erp-kit-version", subject: pkg.relativePath, message: `${ERP_KIT_PACKAGE_NAME}@${raw} uses the workspace protocol (expected only in the erp-kit dev repo).`, }); continue; } const { spec, display, unresolvedCatalog } = resolve(raw, ERP_KIT_PACKAGE_NAME); if (unresolvedCatalog) { findings.push({ severity: "warning", check: "erp-kit-version", subject: pkg.relativePath, message: `${ERP_KIT_PACKAGE_NAME}@${raw} references a pnpm catalog entry that couldn't be resolved; ensure dependencies are installed and the catalog pins it to the installed version (${installedVersion}).`, }); continue; } if (isNonSemverSpecifier(spec)) { findings.push({ severity: "warning", check: "erp-kit-version", subject: pkg.relativePath, message: `${ERP_KIT_PACKAGE_NAME}@${display} uses a non-semver specifier; cannot compare against installed ${installedVersion}. Pin it to the exact installed version.`, }); continue; } if (!semver.valid(spec)) { findings.push({ severity: "error", check: "erp-kit-version", subject: pkg.relativePath, message: `${ERP_KIT_PACKAGE_NAME}@${display} must be pinned to the exact installed version (${installedVersion}).`, }); continue; } if (spec !== installedVersion) { findings.push({ severity: "error", check: "erp-kit-version", subject: pkg.relativePath, message: `${ERP_KIT_PACKAGE_NAME}@${display} differs from the installed version ${installedVersion}; pin it to match.`, }); } } return findings; }