Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function validateWithSchema(
projectRoot: string,
exp: any,
schema: any,
configName: string,
sdkVersion: string,
validateAssets: boolean
): Promise<{ schemaErrorMessage: string | undefined; assetsErrorMessage: string | undefined }> {
let schemaErrorMessage;
let assetsErrorMessage;
let validator = new Schemer(schema, { rootDir: projectRoot });
// Validate the schema itself
try {
await validator.validateSchemaAsync(exp);
} catch (e) {
if (e instanceof SchemerError) {
schemaErrorMessage = `Error: Problem${
e.errors.length > 1 ? 's' : ''
} validating fields in ${configName}. See https://docs.expo.io/versions/v${sdkVersion}/workflow/configuration/`;
schemaErrorMessage += e.errors.map(formatValidationError).join('');
}
}
if (validateAssets) {
try {
await validator.validateAssetsAsync(exp);
export async function validatorFromProjectRoot(projectRoot: string): Promise {
const { exp } = await ConfigUtils.readConfigJsonAsync(projectRoot);
if (!exp.sdkVersion) throw new Error(`Couldn't read local manifest`);
const schema = await getSchemaAsync(exp.sdkVersion);
const validator = new Schemer(schema);
return validator;
}
export async function validatorFromProjectRoot(projectRoot: string): Schemer {
const { exp } = await ProjectUtils.readConfigJsonAsync(projectRoot);
if (!exp) throw new Error(`Couldn't read local manifest`);
const schema = await getSchemaAsync(exp.sdkVersion);
const validator = new Schemer(schema);
return validator;
}