picgo
Version:
A tool for image uploading
51 lines (50 loc) • 2.54 kB
TypeScript
import { IPluginConfig, PluginConfigAnswers } from '../types';
interface EvaluatePluginConfigOptions {
/**
* Optional logger callback invoked when a `choices` or `default` function
* throws. The runtime can wire this to `ctx.log.warn` so degraded fields
* are visible. Receives `(fieldName, kind, error)`.
*/
onError?: (fieldName: string, kind: 'choices' | 'default', error: unknown) => void;
}
/**
* Evaluate a Plugin Config Schema, resolving function-form `choices` and
* `default` against the given `answers` snapshot. Pure: never mutates the
* input schema or its field objects.
*
* Used by:
* - CLI: ideally as a no-op pass before handing the schema to inquirer
* (today the CLI relies on inquirer to evaluate the functions itself,
* so calling this without `answers` is safe and equivalent).
* - GUI: called twice — once at schema serialization (no `answers`) and
* again on reactive refresh (with the current form's value snapshot).
*
* @param schema the raw schema returned by `plugin.config(ctx)`
* @param answers field-value snapshot to pass to function-form choices/default
* (defaults to `{}` so functions that don't read answers are
* still safe to call)
* @param options optional error reporter
* @returns a new array of resolved IPluginConfig items
*/
export declare function evaluatePluginConfig(schema: IPluginConfig[], answers?: PluginConfigAnswers, options?: EvaluatePluginConfigOptions): IPluginConfig[];
interface WrapPluginConfigForCliOptions {
/**
* Optional logger callback invoked when a `choices` or `default` function
* throws during inquirer evaluation. Receives `(fieldName, kind, error)`.
*/
onError?: (fieldName: string, kind: 'choices' | 'default', error: unknown) => void;
}
/**
* Lazily wrap function-form `choices` / `default` with a try/catch so a
* single throwing field doesn't kill the entire inquirer prompt chain on
* the CLI side.
*
* Unlike `evaluatePluginConfig`, this does NOT eagerly invoke the
* functions — it preserves the function form so inquirer can still call
* them lazily with the latest accumulated `answers`. CLI cascade
* semantics are therefore unchanged. A throwing field degrades to
* `choices: []` / `default: undefined`, mirroring the GUI's field-level
* isolation guarantee provided by `evaluatePluginConfig`.
*/
export declare function wrapPluginConfigForCli(schema: IPluginConfig[], options?: WrapPluginConfigForCliOptions): IPluginConfig[];
export {};