Skip to content

Commit

Permalink
feat: output helpful descriptions and links on errors (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored Aug 23, 2021
1 parent 6669609 commit 396bed6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 26 deletions.
54 changes: 42 additions & 12 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"properties": {
"from": {
"type": "string",
"description": "Glob or path from where we copy files.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#from",
"minLength": 1
},
"to": {
Expand All @@ -16,28 +18,44 @@
{
"instanceof": "Function"
}
]
],
"description": "Output path.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#to"
},
"context": {
"type": "string"
"type": "string",
"description": "A path that determines how to interpret the 'from' path.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#context"
},
"globOptions": {
"type": "object"
"type": "object",
"description": "Allows to configute the glob pattern matching library used by the plugin.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#globoptions"
},
"filter": {
"instanceof": "Function"
"instanceof": "Function",
"description": "Allows to filter copied assets.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#filter"
},
"transformAll": {
"instanceof": "Function"
"instanceof": "Function",
"description": "Allows you to modify the contents of multiple files and save the result to one file.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#transformall"
},
"toType": {
"enum": ["dir", "file", "template"]
"enum": ["dir", "file", "template"],
"description": "Determinate what is to option - directory, file or template.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#totype"
},
"force": {
"type": "boolean"
"type": "boolean",
"description": "Overwrites files already in 'compilation.assets' (usually added by other plugins/loaders).",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#force"
},
"priority": {
"type": "number"
"type": "number",
"description": "Allows to specify the priority of copying files with the same destination name.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#priority"
},
"info": {
"anyOf": [
Expand All @@ -47,9 +65,13 @@
{
"instanceof": "Function"
}
]
],
"description": "Allows to add assets info.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#info"
},
"transform": {
"description": "Allows to modify the file contents.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#transform",
"anyOf": [
{
"instanceof": "Function"
Expand All @@ -59,9 +81,13 @@
"additionalProperties": false,
"properties": {
"transformer": {
"instanceof": "Function"
"instanceof": "Function",
"description": "Allows to modify the file contents.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#transformer"
},
"cache": {
"description": "Enables/disables and configure caching.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#cache",
"anyOf": [
{
"type": "boolean"
Expand Down Expand Up @@ -93,7 +119,9 @@
"instanceof": "Function"
},
"noErrorOnMissing": {
"type": "boolean"
"type": "boolean",
"description": "Doesn't generate an error on missing file(s).",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#noerroronmissing"
}
},
"required": ["from"]
Expand Down Expand Up @@ -125,7 +153,9 @@
"additionalProperties": false,
"properties": {
"concurrency": {
"type": "number"
"type": "number",
"description": "Limits the number of simultaneous requests to fs.",
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#concurrency"
}
}
}
Expand Down
64 changes: 50 additions & 14 deletions test/__snapshots__/validate-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

exports[`validate options should throw an error on the "options" option with "{"concurrency":true}" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.options.concurrency should be a number."
- options.options.concurrency should be a number.
-> Limits the number of simultaneous requests to fs.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#concurrency"
`;

exports[`validate options should throw an error on the "options" option with "{"unknown":true}" value 1`] = `
Expand All @@ -29,12 +31,16 @@ exports[`validate options should throw an error on the "patterns" option with "[
exports[`validate options should throw an error on the "patterns" option with "[{"from":"","to":"dir","context":"context","noErrorOnMissing":"true"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].noErrorOnMissing should be a boolean."
- options.patterns[0].noErrorOnMissing should be a boolean.
-> Doesn't generate an error on missing file(s).
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#noerroronmissing"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"","to":"dir","context":"context"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].from should be a non-empty string."
- options.patterns[0].from should be a non-empty string.
-> Glob or path from where we copy files.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#from"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"dir","info":"string"}]" value 1`] = `
Expand All @@ -44,6 +50,8 @@ exports[`validate options should throw an error on the "patterns" option with "[
Details:
* options.patterns[0].info should be one of these:
object { … } | function
-> Allows to add assets info.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#info
Details:
* options.patterns[0].info should be an object:
object { … }
Expand All @@ -57,6 +65,8 @@ exports[`validate options should throw an error on the "patterns" option with "[
Details:
* options.patterns[0].info should be one of these:
object { … } | function
-> Allows to add assets info.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#info
Details:
* options.patterns[0].info should be an object:
object { … }
Expand All @@ -65,18 +75,24 @@ exports[`validate options should throw an error on the "patterns" option with "[
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","filter":"test"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].filter should be an instance of function."
- options.patterns[0].filter should be an instance of function.
-> Allows to filter copied assets.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#filter"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","force":"true"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].force should be a boolean."
- options.patterns[0].force should be a boolean.
-> Overwrites files already in 'compilation.assets' (usually added by other plugins/loaders).
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#force"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","toType":"foo"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].toType should be one of these:
\\"dir\\" | \\"file\\" | \\"template\\""
\\"dir\\" | \\"file\\" | \\"template\\"
-> Determinate what is to option - directory, file or template.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#totype"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","transform":{"foo":"bar"}}]" value 1`] = `
Expand All @@ -92,6 +108,8 @@ exports[`validate options should throw an error on the "patterns" option with "[
Details:
* options.patterns[0].transform should be one of these:
function | object { transformer?, cache? }
-> Allows to modify the file contents.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#transform
Details:
* options.patterns[0].transform should be an instance of function.
* options.patterns[0].transform should be an object:
Expand All @@ -100,27 +118,37 @@ exports[`validate options should throw an error on the "patterns" option with "[
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","transformAll":true}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].transformAll should be an instance of function."
- options.patterns[0].transformAll should be an instance of function.
-> Allows you to modify the contents of multiple files and save the result to one file.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#transformall"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":true}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].context should be a string."
- options.patterns[0].context should be a string.
-> A path that determines how to interpret the 'from' path.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#context"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","priority":"5"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].priority should be a number."
- options.patterns[0].priority should be a number.
-> Allows to specify the priority of copying files with the same destination name.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#priority"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","priority":true}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].priority should be a number."
- options.patterns[0].priority should be a number.
-> Allows to specify the priority of copying files with the same destination name.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#priority"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].priority should be a number."
- options.patterns[0].priority should be a number.
-> Allows to specify the priority of copying files with the same destination name.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#priority"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":true,"context":"context"}]" value 1`] = `
Expand All @@ -130,25 +158,33 @@ exports[`validate options should throw an error on the "patterns" option with "[
Details:
* options.patterns[0].to should be one of these:
string | function
-> Output path.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#to
Details:
* options.patterns[0].to should be a string.
* options.patterns[0].to should be an instance of function."
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":{"glob":"**/*","dot":false},"to":"dir","context":"context"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].from should be a non-empty string."
- options.patterns[0].from should be a non-empty string.
-> Glob or path from where we copy files.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#from"
`;
exports[`validate options should throw an error on the "patterns" option with "[{"from":true,"to":"dir","context":"context"}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0].from should be a non-empty string."
- options.patterns[0].from should be a non-empty string.
-> Glob or path from where we copy files.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#from"
`;
exports[`validate options should throw an error on the "patterns" option with "[{}]" value 1`] = `
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options.patterns[0] misses the property 'from'. Should be:
non-empty string"
non-empty string
-> Glob or path from where we copy files.
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#from"
`;
exports[`validate options should throw an error on the "patterns" option with "{}" value 1`] = `
Expand Down

0 comments on commit 396bed6

Please sign in to comment.