Repository: webpack-contrib/copy-webpack-plugin
Pull request #625 (2021-08-23 02:05:20)

fix: output helpful descriptions and links on errors
<!--
  HOLY CRAP a Pull Request. We ❤️ those!

  If you remove or skip this template, you'll make the 🐼 sad and the mighty god
  of Github will appear and pile-drive the close button from a great height
  while making animal noises.

  Please place an x (no spaces!) in all [ ] that apply
-->

This PR contains a:

- [x] **bugfix**
- [ ] new **feature**
- [ ] **code refactor**
- [x] **test update** <!-- if bug or feature is checked, this should be too -->
- [ ] **typo fix**
- [ ] **metadata update**

### Motivation / Use-Case

output helpful descriptions and links on errors.

<!--
  Please explain the motivation or use-case for your change.
  What existing problem does the PR solve?
  If this PR addresses an issue, please link to the issue.
-->

### Breaking Changes
None
<!--
  If this PR introduces a breaking change, please describe the impact and a
  migration path for existing applications.
-->

### Additional Info
No

codecov[bot]: # [Codecov](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/625?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib) Report
> Merging [#625](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/625?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib) (1389979) into [master](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/commit/b8c08da103b364695d00c33869945a16a1d3012b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib) (b8c08da) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/625/graphs/tree.svg?width=650&height=150&src=pr&token=fEoU9iBFGL&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib)](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/625?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib)

```diff
@@           Coverage Diff           @@
##           master     #625   +/-   ##
=======================================
  Coverage   93.75%   93.75%           
=======================================
  Files           3        3           
  Lines         336      336           
  Branches       91       91           
=======================================
  Hits          315      315           
  Misses         21       21           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/625?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/625?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib). Last update [b8c08da...1389979](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/625?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webpack-contrib).


Patch:
diff --git a/README.md b/README.md
index f162ae5..7f50c9c 100644
--- a/README.md
+++ b/README.md
@@ -378,11 +378,11 @@ Sometimes it is hard to say what is `to`, example `path/to/dir-with.ext`.
 If you want to copy files in directory you need use `dir` option.
 We try to automatically determine the `type` so you most likely do not need this option.
 
-|       Name       |    Type    |   Default   | Description                                                                                          |
-| :--------------: | :--------: | :---------: | :--------------------------------------------------------------------------------------------------- |
-|   **`'dir'`**    | `{String}` | `undefined` | If `to` has no extension or ends on `'/'`                                                            |
-|   **`'file'`**   | `{String}` | `undefined` | If `to` is not a directory and is not a template                                                     |
-| **`'template'`** | `{String}` | `undefined` | If `to` contains [a template pattern](https://webpack.js.org/configuration/output/#template-strings) |
+|             Name              |    Type    |   Default   | Description                                                                                          |
+| :---------------------------: | :--------: | :---------: | :--------------------------------------------------------------------------------------------------- |
+|      **[`'dir'`](#dir)**      | `{String}` | `undefined` | If `to` has no extension or ends on `'/'`                                                            |
+|     **[`'file'`](#file)**     | `{String}` | `undefined` | If `to` is not a directory and is not a template                                                     |
+| **[`'template'`](#template)** | `{String}` | `undefined` | If `to` contains [a template pattern](https://webpack.js.org/configuration/output/#template-strings) |
 
 ##### `'dir'`
 
@@ -780,7 +780,7 @@ module.exports = {
 Type: `Boolean`
 Default: `false`
 
-Doesn't generate an error on missing file(s);
+Doesn't generate an error on missing file(s).
 
 ```js
 module.exports = {
diff --git a/src/options.json b/src/options.json
index e93ee01..ae9f96d 100644
--- a/src/options.json
+++ b/src/options.json
@@ -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": {
@@ -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": [
@@ -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"
@@ -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"
@@ -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"]
@@ -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"
         }
       }
     }


Test patch:
diff --git a/test/__snapshots__/validate-options.test.js.snap b/test/__snapshots__/validate-options.test.js.snap
index 5bd30d5..f56b7e4 100644
--- a/test/__snapshots__/validate-options.test.js.snap
+++ b/test/__snapshots__/validate-options.test.js.snap
@@ -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`] = `
@@ -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`] = `
@@ -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 { … }
@@ -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 { … }
@@ -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`] = `
@@ -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:
@@ -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`] = `
@@ -130,6 +158,8 @@ 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."
@@ -137,18 +167,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":{"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`] = `