libraryGuard
The guard keeping a codebase's libraries read-only (Store.guard): their names, and the records saying what each
is, change only through tcm lib.
import { librariesIn, libraryLabel, within } from "#codebase/tcmts/cli/libraries"; import type { Store } from "#codebase/tcmts/store"; export function libraryGuard(store: Store): (path: string) => void { return (path) => { const libraries = librariesIn(store); const lib = libraries.find((l) => within(path, l.path)); if (lib) throw new Error( `${path} is in the library ${lib.path} (${libraryLabel(lib)}), which is read-only: to change it, copy it into a namespace of your own (\`tcm alias ${path} <name>\`) and change the copy, or \`tcm lib rm ${lib.path}\``, ); if (libraries.some((l) => l.record === path)) throw new Error(`${path} records the libraries mounted beside it: \`tcm lib\` changes it`); }; }
uses
- tcmts.cli.libraries.librariesIn
- tcmts.cli.libraries.libraryLabel
- tcmts.cli.libraries.within
- tcmts.store.Store