libraryNamed
The library which names: its mount (tcmts.lib.geo), or its own name if only one library has it (geo).
import { librariesIn } from "#codebase/tcmts/cli/libraries"; import type { Library } from "#codebase/tcmts/cli/libraries"; import { UsageError } from "#codebase/tcmts/cli/ui"; import type { Store } from "#codebase/tcmts/store"; export function libraryNamed(store: Store, which: string): Library { const libraries = librariesIn(store); const exact = libraries.find((l) => l.path === which); if (exact) return exact; const byName = libraries.filter((l) => l.path.slice(l.path.lastIndexOf(".") + 1) === which); if (byName.length === 1) return byName[0]!; throw new UsageError( byName.length ? `'${which}' is several libraries: ${byName.map((l) => l.path).join(", ")}` : `no library '${which}'${libraries.length ? ` (there's ${libraries.map((l) => l.path).join(", ")})` : ""}`, ); }