export class PluginIssueError extends Error {
    issue;
    pluginName;
    constructor(issue, pluginName) {
        super(issue.message);
        this.issue = issue;
        this.pluginName = pluginName;
        this.name = "PluginIssueError";
    }
}
export class PluginResult {
    notes = [];
    errors = [];
    warnings = [];
    constructor(err) {
        if (err) {
            this.errors.push(err);
        }
    }
}
export async function runPlugins(tasksToRun, config, options) {
    const warnings = [];
    const errors = [];
    const notes = [];
    const data = {};
    for await (const plugin of tasksToRun) {
        try {
            const pluginResult = await plugin(config, {
                data,
                notes,
                errors,
                warnings,
            });
            errors.push(...pluginResult.errors.map((err) => {
                if (err.pluginName === "") {
                    err.pluginName = plugin.name;
                }
                return err;
            }));
            notes.push(...pluginResult.notes);
            warnings.push(...pluginResult.warnings);
            if (pluginResult.errors.length > 0) {
                break;
            }
        }
        catch (err) {
            if (err instanceof PluginIssueError) {
                errors.push({ ...err.issue, pluginName: err.pluginName ?? "unknown" });
            }
            else {
                errors.push({
                    pluginName: plugin.name || "unknown",
                    message: err instanceof Error ? err.message : String(err),
                    severity: "error",
                });
            }
            if (options?.throwOnException) {
                throw err;
            }
            break;
        }
    }
    return { errors, warnings, data, notes };
}
//# sourceMappingURL=runner.js.map