Function: loadOptionalPackage()
loadOptionalPackage<
T>(detail,load):Promise<T>
The same graceful-degradation path as loadOptional, keyed on a package name rather than a CosyteFormat, with the diagnostic supplied by the caller.
Two of the packages the CLI lazy-loads are not wire-format parsers and so cannot go through
loadOptional: @cosyte/transform (a conversion library, not one of the eight formats, so
calling it a "parser" in the diagnostic would be wrong) and @cosyte/fhir (a format, but absent for
a reason no reinstall fixes, which the message has to say). Both are reachable from a published
install only if the user already has them, so both must degrade to a value-free
CLI_PARSER_UNAVAILABLE (exit 69) instead of surfacing a raw resolver error and a stack frame.
Type Parameters
T
T
The imported module's type.
Parameters
detail
string
The value-free diagnostic detail shown when the package is absent.
load
() => Promise<T>
A thunk performing the dynamic import.
Returns
Promise<T>
The imported module.
Throws
CLI_PARSER_UNAVAILABLE (exit 69) when the package is absent; any other error
propagates unchanged.
Example
import { loadOptionalPackage } from "@cosyte/cli";
await loadOptionalPackage("the conversion library is not installed", () =>
import("@cosyte/transform"),
);