Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

resolve-catalog.ts

31 lines1.0 KB

1/**
2 * Resolve `catalog:` dependency specs using the workspace catalog.
3 *
4 * Pure function: returns a new record with every `catalog:…` value replaced by
5 * the concrete version string found in `catalog`. Throws on missing entries.
6 */
7export function resolveCatalogDependencies(
8 dependencies: Record<string, unknown>,
9 catalog: Record<string, unknown>,
10 label: string,
11): Record<string, unknown> {
12 return Object.fromEntries(
13 Object.entries(dependencies).map(([name, spec]) => {
14 if (typeof spec !== "string" || !spec.startsWith("catalog:")) {
15 return [name, spec];
16 }
17​
18 const catalogKey = spec.slice("catalog:".length).trim();
19 const lookupKey = catalogKey.length > 0 ? catalogKey : name;
20 const resolved = catalog[lookupKey];
21​
22 if (typeof resolved !== "string" || resolved.length === 0) {
23 throw new Error(
24 `Unable to resolve '${spec}' for ${label} dependency '${name}'. Expected key '${lookupKey}' in root workspace catalog.`,
25 );
26 }
27​
28 return [name, resolved];
29 }),
30 );