import type { ConstraintValidator } from '@/types' export const maxNum: ConstraintValidator = (num) => async ({ pluginConfig, mode, type: moduleType }) => { const existedModuleTypes = (pluginConfig.modules || []).map((module) => module.moduleType) const targetModuleTypeNums = existedModuleTypes.filter((item) => moduleType === item).length const maxNum = mode === 'add' ? num : num + 1 if (targetModuleTypeNums >= maxNum) { throw `A maximum of ${num} ${moduleType} ${num > 1 ? 'are' : 'is'} allowed in a plugin` } }