UNPKG

@alova/wormhole

Version:

More modern openAPI generating solution for alova.js

40 lines (39 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extendsConfig = extendsConfig; exports.prepareConfig = prepareConfig; const lodash_1 = require("lodash"); function extendsConfig(config, newConfig) { const mergedConfig = (0, lodash_1.cloneDeep)(config); return (0, lodash_1.mergeWith)(mergedConfig, newConfig, (newValue, srcValue, key) => { if (key !== 'handleApi') { return newValue ?? srcValue; // fallback to default merge behavior } // handleApi is a special case, we need to merge the functions if (typeof newValue === 'function' && typeof srcValue === 'function') { // chain the functions return (...args) => { const result = srcValue(...args); // null or undefined return is a valid value for filtering // if plugin return undefined or null, we should break the chain if (result === undefined || result === null) { return result; } return newValue(result); }; } return newValue ?? srcValue; // fallback to default merge behavior }); } function prepareConfig(config) { let newConfig = (0, lodash_1.cloneDeep)(config); const plugins = newConfig.plugins || []; for (const plugin of plugins) { if (plugin.extends) { const pluginExtendsConfig = typeof plugin.extends === 'function' ? plugin.extends(newConfig) : plugin.extends; newConfig = extendsConfig(newConfig, pluginExtendsConfig); } } return newConfig; } exports.default = prepareConfig;