Skip to main content
Version: v0.0.3

Function: loadOptional()

loadOptional<T>(format, load): Promise<T>

Lazy-import an optional parser package, mapping an absent package to a value-free CLI_PARSER_UNAVAILABLE (exit 69): the graceful-degradation path for the optionalDependencies breadth parsers. A genuine import that succeeds passes straight through; any error whose shape is "module not found" becomes the value-free CLI error. Other errors propagate unchanged.

Type Parameters

T

T

The imported module's type.

Parameters

format

CosyteFormat

The format whose optional parser is being loaded (named in the diagnostic).

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 { loadOptional } from "@cosyte/cli";

// a present parser resolves; an absent one throws CLI_PARSER_UNAVAILABLE
await loadOptional("x12", () => import("@cosyte/x12"));