import Ajv from 'ajv' ; import { routesSchema , cleanUrlsSchema , headersSchema , redirectsSchema , rewritesSchema , trailingSlashSchema , } from '@vercel/routing-utils' ; import { VercelConfig } from './types' ; import { functionsSchema , buildsSchema , NowBuildError , getPrettyError , } from '@vercel/build-utils' ; import { fileNameSymbol } from '@vercel/client' ; const vercelConfigSchema = { type : 'object' , additionalProperties : true , properties : { builds : buildsSchema , routes : routesSchema , cleanUrls : cleanUrlsSchema , headers : headersSchema , redirects : redirectsSchema , rewrites : rewritesSchema , trailingSlash : trailingSlashSchema , functions : functionsSchema , } , } ; const ajv = new Ajv ( ) ; const validate = ajv . compile ( vercelConfigSchema ) ; export function validateConfig ( config ) { if ( ! validate ( config ) ) { if ( validate . errors && validate . errors [ 0 ] ) { const error = validate . errors [ 0 ] ; const fileName = config [ fileNameSymbol ] || 'vercel.json' ; const niceError = getPrettyError ( error ) ; niceError . message = `Invalid ${ fileName } - ${ niceError . message }` ; return niceError ; } } if ( config . functions && config . builds ) { return new NowBuildError ( { code : 'FUNCTIONS_AND_BUILDS' , message : 'The `functions` property cannot be used in conjunction with the `builds` property. Please remove one of them.' , link : 'https://vercel.link/functions-and-builds' , } ) ; } return null ; }