"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeBuilderConfig = void 0;
const lodash_1 = __importDefault(require("@modern-js/utils/lodash"));
const mergeBuilderConfig = (...configs) => lodash_1.default.mergeWith({}, ...configs, (target, source, key) => {
    const pair = [target, source];
    if (pair.some(lodash_1.default.isUndefined)) {
        // fallback to lodash default merge behavior
        return undefined;
    }
    // always use source override target, if target defined.
    if (['cssModules', 'removeConsole'].includes(key)) {
        return source !== null && source !== void 0 ? source : target;
    }
    // allow using `htmlPlugin: false` to disable HTML
    if (key === 'htmlPlugin' && source === false) {
        return false;
    }
    if (pair.some(lodash_1.default.isArray)) {
        return [...lodash_1.default.castArray(target), ...lodash_1.default.castArray(source)];
    }
    // convert function to chained function
    if (pair.some(lodash_1.default.isFunction)) {
        return [target, source];
    }
    // fallback to lodash default merge behavior
    return undefined;
});
exports.mergeBuilderConfig = mergeBuilderConfig;
