// Readers over a parsed `pnpm-workspace.yaml` document that BOTH the live // assembler (`WorkspaceCatalogs`) and the at-ref reader (`WorkspaceSnapshots`) // need to feed the config-dependency hook replay: the `configDependencies` // map and the inline `peerDependencyRules` seed. One implementation, so the // two sides of a diff cannot disagree about what a ref declared. import { PeerDependencyRules } from "@effected/pnpm"; import { Predicate } from "effect"; import { stringsOf } from "./patterns.js"; /** The `configDependencies` map (name → version+integrity) of a parsed pnpm-workspace document. */ export const configDependenciesOf = (document: unknown): Record => { if (!Predicate.isObject(document) || !Predicate.isObject(document.configDependencies)) return {}; const out: Record = {}; for (const [name, spec] of Object.entries(document.configDependencies)) { if (typeof spec === "string") out[name] = spec; } return out; }; /** * The `peerDependencyRules` a `pnpm-workspace.yaml` declares inline — the half * `pnpm:export` materializes into the file, as opposed to the half a config * dependency injects at replay time. * * @remarks * **Tolerant, unlike the catalog blocks**, and the asymmetry is deliberate: a * malformed catalog block must hard-fail because a silently-empty catalog makes * every dependency look newly added, whereas a malformed rules block costs only * suppression — the failure mode is reporting a peer pnpm would have hidden, * which is visible and safe. Failing the whole assembly over it would take the * catalogs down with it. * * Every axis is read independently, so a malformed `ignoreMissing` does not * discard a well-formed `allowedVersions`. */ export const inlinePeerDependencyRules = (document: unknown): PeerDependencyRules => { if (!Predicate.isObject(document) || !Predicate.isObject(document.peerDependencyRules)) return PeerDependencyRules.empty; const block = document.peerDependencyRules; const allowedVersions: Record = {}; if (Predicate.isObject(block.allowedVersions)) { for (const [key, value] of Object.entries(block.allowedVersions)) { if (typeof value === "string") allowedVersions[key] = value; } } return PeerDependencyRules.make({ allowedVersions, ignoreMissing: stringsOf(block.ignoreMissing) ?? [], allowAny: stringsOf(block.allowAny) ?? [], }); };