From 396bed6a8ad12cea344e988fefb9a554bb9c7b1a Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 23 Aug 2021 18:02:19 +0530 Subject: [PATCH] feat: output helpful descriptions and links on errors (#625) --- src/options.json | 54 ++++++++++++---- .../validate-options.test.js.snap | 64 +++++++++++++++---- 2 files changed, 92 insertions(+), 26 deletions(-) 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" } } } 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`] = `