Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -35,10 +35,21 @@ const getSchemaPartText = (schemaPart, additionalPath) => {
while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart);
if(schemaPart.description)
schemaText += `\n${schemaPart.description}`;
schemaText += `\n-> ${schemaPart.description}`;
return schemaText;
};
const getSchemaPartDescription = schemaPart => {
while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
if(schemaPart.description)
return `\n-> ${schemaPart.description}`;
return "";
};
const filterChildren = children => {
return children.filter(err => err.keyword !== "anyOf" && err.keyword !== "allOf" && err.keyword !== "oneOf");
};
const indent = (str, prefix, firstLine) => {
if(firstLine) {
return prefix + str.replace(/\n(?!$)/g, "\n" + prefix);
@@ -143,8 +154,16 @@ class WebpackOptionsValidationError extends WebpackError {
return baseMessage;
} else if(err.keyword === "oneOf" || err.keyword === "anyOf") {
if(err.children && err.children.length > 0) {
if(err.schema.length === 1) {
const lastChild = err.children[err.children.length - 1];
const remainingChildren = err.children.slice(0, err.children.length - 1);
return WebpackOptionsValidationError.formatValidationError(Object.assign({}, lastChild, {
children: remainingChildren,
parentSchema: Object.assign({}, err.parentSchema, lastChild.parentSchema)
}));
}
return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}\n` +
`Details:\n${err.children.map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`;
`Details:\n${filterChildren(err.children).map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`;
}
return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`;
@@ -158,29 +177,33 @@ class WebpackOptionsValidationError extends WebpackError {
} else if(err.keyword === "type") {
switch(err.params.type) {
case "object":
return `${dataPath} should be an object.`;
return `${dataPath} should be an object.${getSchemaPartDescription(err.parentSchema)}`;
case "string":
return `${dataPath} should be a string.`;
return `${dataPath} should be a string.${getSchemaPartDescription(err.parentSchema)}`;
case "boolean":
return `${dataPath} should be a boolean.`;
return `${dataPath} should be a boolean.${getSchemaPartDescription(err.parentSchema)}`;
case "number":
return `${dataPath} should be a number.`;
return `${dataPath} should be a number.${getSchemaPartDescription(err.parentSchema)}`;
case "array":
return `${dataPath} should be an array:\n${getSchemaPartText(err.parentSchema)}`;
}
return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(err.parentSchema)}`;
} else if(err.keyword === "instanceof") {
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}.`;
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}`;
} else if(err.keyword === "required") {
const missingProperty = err.params.missingProperty.replace(/^\./, "");
return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(err.parentSchema, ["properties", missingProperty])}`;
} else if(err.keyword === "minLength" || err.keyword === "minItems") {
} else if(err.keyword === "minimum") {
return `${dataPath} ${err.message}.${getSchemaPartDescription(err.parentSchema)}`;
} else if(err.keyword === "uniqueItems") {
return `${dataPath} should not contain the item '${err.data[err.params.i]}' twice.${getSchemaPartDescription(err.parentSchema)}`;
} else if(err.keyword === "minLength" || err.keyword === "minItems" || err.keyword === "minProperties") {
if(err.params.limit === 1)
return `${dataPath} should not be empty.`;
return `${dataPath} should not be empty.${getSchemaPartDescription(err.parentSchema)}`;
else
return `${dataPath} ${err.message}`;
return `${dataPath} ${err.message}${getSchemaPartDescription(err.parentSchema)}`;
} else if(err.keyword === "absolutePath") {
const baseMessage = `${dataPath}: ${err.message}`;
const baseMessage = `${dataPath}: ${err.message}${getSchemaPartDescription(err.parentSchema)}`;
if(dataPath === "configuration.output.filename") {
return `${baseMessage}\n` +
"Please use output.path to specify absolute path and output.filename for the file name.";