The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import * as Schema from "effect/Schema"; |
| 2 | |
| 3 | class CatalogDependencyResolutionError extends Schema.TaggedError<CatalogDependencyResolutionError>()( |
| 4 | "CatalogDependencyResolutionError", |
| 5 | { |
| 6 | workspacePackage: Schema.String, |
| 7 | dependencyName: Schema.String, |
| 8 | catalogSpec: Schema.String, |
| 9 | catalogKey: Schema.String, |
| 10 | }, |
| 11 | ) { |
| 12 | override get message(): string { |
| 13 | return `Unable to resolve '${this.catalogSpec}' for ${this.workspacePackage} dependency '${this.dependencyName}'. Expected key '${this.catalogKey}' in root workspace catalog.`; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | export function resolveCatalogDependencies( |
| 18 | dependencies: Record<string, string>, |
| 19 | catalog: Record<string, string>, |
| 20 | workspacePackage: string, |
| 21 | ): Record<string, string> { |
| 22 | return Object.fromEntries( |
| 23 | Object.entries(dependencies).map(([name, spec]) => { |
| 24 | if (typeof spec !== "string" || !spec.startsWith("catalog:")) { |
| 25 | return [name, spec]; |
| 26 | } |
| 27 | |
| 28 | const catalogKey = spec.slice("catalog:".length).trim(); |
| 29 | const selector = name.split(">").at(-1) ?? name; |
| 30 | const versionIndex = selector.indexOf("@", 1); |
| 31 | const packageName = versionIndex === -1 ? selector : selector.slice(0, versionIndex); |
| 32 | const lookupKey = catalogKey.length > 0 ? catalogKey : packageName; |
| 33 | const resolved = catalog[lookupKey]; |
| 34 | |
| 35 | if (typeof resolved !== "string" || resolved.length === 0) { |
| 36 | throw new CatalogDependencyResolutionError({ |
| 37 | workspacePackage, |
| 38 | dependencyName: name, |
| 39 | catalogSpec: spec, |
| 40 | catalogKey: lookupKey, |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | return [name, resolved]; |
| 45 | }), |
| 46 | ); |
| 47 | } |