"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateBuilderConfig = exports.formatZodError = void 0;
const zod_1 = require("../zod");
const chalk_1 = __importDefault(require("@modern-js/utils/chalk"));
__exportStar(require("./source"), exports);
__exportStar(require("./dev"), exports);
__exportStar(require("./html"), exports);
__exportStar(require("./output"), exports);
__exportStar(require("./experiments"), exports);
__exportStar(require("./performance"), exports);
__exportStar(require("./security"), exports);
__exportStar(require("./tools"), exports);
const formatZodError = (error) => {
    return (0, zod_1.fromZodError)(error, {
        issueSeparator: '\n* ',
        prefix: `${chalk_1.default.red('Builder config validation error')}:`,
        prefixSeparator: '\n* ',
    });
};
exports.formatZodError = formatZodError;
const validateBuilderConfig = async (configSchema, data) => {
    const parsed = await configSchema.safeParseAsync(data);
    if (!parsed.success) {
        const err = (0, exports.formatZodError)(parsed.error);
        // only print message & details, error stack is useless
        const message = `${err.message}\nError detail:\n${JSON.stringify(err.details, null, 2)}`;
        throw new Error(message);
    }
    return parsed.data;
};
exports.validateBuilderConfig = validateBuilderConfig;
