Skip to content

Commit 396bed6

Browse files
authoredAug 23, 2021
feat: output helpful descriptions and links on errors (#625)
1 parent 6669609 commit 396bed6

File tree

2 files changed

+92
-26
lines changed

2 files changed

+92
-26
lines changed
 

‎src/options.json

+42-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"properties": {
77
"from": {
88
"type": "string",
9+
"description": "Glob or path from where we copy files.",
10+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#from",
911
"minLength": 1
1012
},
1113
"to": {
@@ -16,28 +18,44 @@
1618
{
1719
"instanceof": "Function"
1820
}
19-
]
21+
],
22+
"description": "Output path.",
23+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#to"
2024
},
2125
"context": {
22-
"type": "string"
26+
"type": "string",
27+
"description": "A path that determines how to interpret the 'from' path.",
28+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#context"
2329
},
2430
"globOptions": {
25-
"type": "object"
31+
"type": "object",
32+
"description": "Allows to configute the glob pattern matching library used by the plugin.",
33+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#globoptions"
2634
},
2735
"filter": {
28-
"instanceof": "Function"
36+
"instanceof": "Function",
37+
"description": "Allows to filter copied assets.",
38+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#filter"
2939
},
3040
"transformAll": {
31-
"instanceof": "Function"
41+
"instanceof": "Function",
42+
"description": "Allows you to modify the contents of multiple files and save the result to one file.",
43+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#transformall"
3244
},
3345
"toType": {
34-
"enum": ["dir", "file", "template"]
46+
"enum": ["dir", "file", "template"],
47+
"description": "Determinate what is to option - directory, file or template.",
48+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#totype"
3549
},
3650
"force": {
37-
"type": "boolean"
51+
"type": "boolean",
52+
"description": "Overwrites files already in 'compilation.assets' (usually added by other plugins/loaders).",
53+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#force"
3854
},
3955
"priority": {
40-
"type": "number"
56+
"type": "number",
57+
"description": "Allows to specify the priority of copying files with the same destination name.",
58+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#priority"
4159
},
4260
"info": {
4361
"anyOf": [
@@ -47,9 +65,13 @@
4765
{
4866
"instanceof": "Function"
4967
}
50-
]
68+
],
69+
"description": "Allows to add assets info.",
70+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#info"
5171
},
5272
"transform": {
73+
"description": "Allows to modify the file contents.",
74+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#transform",
5375
"anyOf": [
5476
{
5577
"instanceof": "Function"
@@ -59,9 +81,13 @@
5981
"additionalProperties": false,
6082
"properties": {
6183
"transformer": {
62-
"instanceof": "Function"
84+
"instanceof": "Function",
85+
"description": "Allows to modify the file contents.",
86+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#transformer"
6387
},
6488
"cache": {
89+
"description": "Enables/disables and configure caching.",
90+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#cache",
6591
"anyOf": [
6692
{
6793
"type": "boolean"
@@ -93,7 +119,9 @@
93119
"instanceof": "Function"
94120
},
95121
"noErrorOnMissing": {
96-
"type": "boolean"
122+
"type": "boolean",
123+
"description": "Doesn't generate an error on missing file(s).",
124+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#noerroronmissing"
97125
}
98126
},
99127
"required": ["from"]
@@ -125,7 +153,9 @@
125153
"additionalProperties": false,
126154
"properties": {
127155
"concurrency": {
128-
"type": "number"
156+
"type": "number",
157+
"description": "Limits the number of simultaneous requests to fs.",
158+
"link": "https://github.com/webpack-contrib/copy-webpack-plugin#concurrency"
129159
}
130160
}
131161
}

‎test/__snapshots__/validate-options.test.js.snap

+50-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

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

810
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 "[
2931
3032
exports[`validate options should throw an error on the "patterns" option with "[{"from":"","to":"dir","context":"context","noErrorOnMissing":"true"}]" value 1`] = `
3133
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
32-
- options.patterns[0].noErrorOnMissing should be a boolean."
34+
- options.patterns[0].noErrorOnMissing should be a boolean.
35+
-> Doesn't generate an error on missing file(s).
36+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#noerroronmissing"
3337
`;
3438
3539
exports[`validate options should throw an error on the "patterns" option with "[{"from":"","to":"dir","context":"context"}]" value 1`] = `
3640
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
37-
- options.patterns[0].from should be a non-empty string."
41+
- options.patterns[0].from should be a non-empty string.
42+
-> Glob or path from where we copy files.
43+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#from"
3844
`;
3945
4046
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 "[
4450
Details:
4551
* options.patterns[0].info should be one of these:
4652
object { … } | function
53+
-> Allows to add assets info.
54+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#info
4755
Details:
4856
* options.patterns[0].info should be an object:
4957
object { … }
@@ -57,6 +65,8 @@ exports[`validate options should throw an error on the "patterns" option with "[
5765
Details:
5866
* options.patterns[0].info should be one of these:
5967
object { … } | function
68+
-> Allows to add assets info.
69+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#info
6070
Details:
6171
* options.patterns[0].info should be an object:
6272
object { … }
@@ -65,18 +75,24 @@ exports[`validate options should throw an error on the "patterns" option with "[
6575
6676
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","filter":"test"}]" value 1`] = `
6777
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
68-
- options.patterns[0].filter should be an instance of function."
78+
- options.patterns[0].filter should be an instance of function.
79+
-> Allows to filter copied assets.
80+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#filter"
6981
`;
7082
7183
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","force":"true"}]" value 1`] = `
7284
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
73-
- options.patterns[0].force should be a boolean."
85+
- options.patterns[0].force should be a boolean.
86+
-> Overwrites files already in 'compilation.assets' (usually added by other plugins/loaders).
87+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#force"
7488
`;
7589
7690
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","toType":"foo"}]" value 1`] = `
7791
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
7892
- options.patterns[0].toType should be one of these:
79-
\\"dir\\" | \\"file\\" | \\"template\\""
93+
\\"dir\\" | \\"file\\" | \\"template\\"
94+
-> Determinate what is to option - directory, file or template.
95+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#totype"
8096
`;
8197
8298
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 "[
92108
Details:
93109
* options.patterns[0].transform should be one of these:
94110
function | object { transformer?, cache? }
111+
-> Allows to modify the file contents.
112+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#transform
95113
Details:
96114
* options.patterns[0].transform should be an instance of function.
97115
* options.patterns[0].transform should be an object:
@@ -100,27 +118,37 @@ exports[`validate options should throw an error on the "patterns" option with "[
100118
101119
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","transformAll":true}]" value 1`] = `
102120
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
103-
- options.patterns[0].transformAll should be an instance of function."
121+
- options.patterns[0].transformAll should be an instance of function.
122+
-> Allows you to modify the contents of multiple files and save the result to one file.
123+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#transformall"
104124
`;
105125
106126
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":true}]" value 1`] = `
107127
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
108-
- options.patterns[0].context should be a string."
128+
- options.patterns[0].context should be a string.
129+
-> A path that determines how to interpret the 'from' path.
130+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#context"
109131
`;
110132
111133
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","priority":"5"}]" value 1`] = `
112134
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
113-
- options.patterns[0].priority should be a number."
135+
- options.patterns[0].priority should be a number.
136+
-> Allows to specify the priority of copying files with the same destination name.
137+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#priority"
114138
`;
115139
116140
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","priority":true}]" value 1`] = `
117141
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
118-
- options.patterns[0].priority should be a number."
142+
- options.patterns[0].priority should be a number.
143+
-> Allows to specify the priority of copying files with the same destination name.
144+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#priority"
119145
`;
120146
121147
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir"}]" value 1`] = `
122148
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
123-
- options.patterns[0].priority should be a number."
149+
- options.patterns[0].priority should be a number.
150+
-> Allows to specify the priority of copying files with the same destination name.
151+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#priority"
124152
`;
125153
126154
exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":true,"context":"context"}]" value 1`] = `
@@ -130,25 +158,33 @@ exports[`validate options should throw an error on the "patterns" option with "[
130158
Details:
131159
* options.patterns[0].to should be one of these:
132160
string | function
161+
-> Output path.
162+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#to
133163
Details:
134164
* options.patterns[0].to should be a string.
135165
* options.patterns[0].to should be an instance of function."
136166
`;
137167
138168
exports[`validate options should throw an error on the "patterns" option with "[{"from":{"glob":"**/*","dot":false},"to":"dir","context":"context"}]" value 1`] = `
139169
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
140-
- options.patterns[0].from should be a non-empty string."
170+
- options.patterns[0].from should be a non-empty string.
171+
-> Glob or path from where we copy files.
172+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#from"
141173
`;
142174
143175
exports[`validate options should throw an error on the "patterns" option with "[{"from":true,"to":"dir","context":"context"}]" value 1`] = `
144176
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
145-
- options.patterns[0].from should be a non-empty string."
177+
- options.patterns[0].from should be a non-empty string.
178+
-> Glob or path from where we copy files.
179+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#from"
146180
`;
147181
148182
exports[`validate options should throw an error on the "patterns" option with "[{}]" value 1`] = `
149183
"Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
150184
- options.patterns[0] misses the property 'from'. Should be:
151-
non-empty string"
185+
non-empty string
186+
-> Glob or path from where we copy files.
187+
-> Read more at https://github.com/webpack-contrib/copy-webpack-plugin#from"
152188
`;
153189
154190
exports[`validate options should throw an error on the "patterns" option with "{}" value 1`] = `

0 commit comments

Comments
 (0)
Please sign in to comment.