Skip to content

fix: output more information on errors #1024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"memfs": "^3.2.2",
"mime-types": "^2.1.31",
"range-parser": "^1.2.1",
"schema-utils": "^3.0.0"
"schema-utils": "^3.1.0"
},
"devDependencies": {
"@babel/cli": "^7.14.5",
Expand Down
12 changes: 11 additions & 1 deletion src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"properties": {
"mimeTypes": {
"description": "Allows a user to register custom mime types or extension mappings.",
"link": "https://github.com/webpack/webpack-dev-middleware#mimetypes",
"type": "object"
},
"writeToDisk": {
"description": "Allows to write generated files on disk.",
"link": "https://github.com/webpack/webpack-dev-middleware#writetodisk",
"anyOf": [
{
"type": "boolean"
Expand All @@ -18,6 +20,7 @@
},
"methods": {
"description": "Allows to pass the list of HTTP request methods accepted by the middleware.",
"link": "https://github.com/webpack/webpack-dev-middleware#methods",
"type": "array",
"items": {
"type": "string",
Expand All @@ -32,10 +35,13 @@
{
"instanceof": "Function"
}
]
],
"description": "Allows to pass custom HTTP headers on each request",
"link": "https://github.com/webpack/webpack-dev-middleware#headers"
},
"publicPath": {
"description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.",
"link": "https://github.com/webpack/webpack-dev-middleware#publicpath",
"anyOf": [
{
"enum": ["auto"]
Expand All @@ -50,6 +56,7 @@
},
"stats": {
"description": "Stats options object or preset name.",
"link": "https://github.com/webpack/webpack-dev-middleware#stats",
"anyOf": [
{
"enum": [
Expand All @@ -74,14 +81,17 @@
},
"serverSideRender": {
"description": "Instructs the module to enable or disable the server-side rendering mode.",
"link": "https://github.com/webpack/webpack-dev-middleware#serversiderender",
"type": "boolean"
},
"outputFileSystem": {
"description": "Set the default file system which will be used by webpack as primary destination of generated files.",
"link": "https://github.com/webpack/webpack-dev-middleware#outputfilesystem",
"type": "object"
},
"index": {
"description": "Allows to serve an index of the directory.",
"link": "https://github.com/webpack/webpack-dev-middleware#index",
"anyOf": [
{
"type": "boolean"
Expand Down
27 changes: 21 additions & 6 deletions test/__snapshots__/validation-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`validation should throw an error on the "headers" option with "1" value
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.headers should be one of these:
object { … } | function
-> Allows to pass custom HTTP headers on each request
-> Read more at https://github.com/webpack/webpack-dev-middleware#headers
Details:
* options.headers should be an object:
object { … }
Expand All @@ -14,6 +16,8 @@ exports[`validation should throw an error on the "headers" option with "true" va
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.headers should be one of these:
object { … } | function
-> Allows to pass custom HTTP headers on each request
-> Read more at https://github.com/webpack/webpack-dev-middleware#headers
Details:
* options.headers should be an object:
object { … }
Expand All @@ -25,6 +29,7 @@ exports[`validation should throw an error on the "index" option with "{}" value
- options.index should be one of these:
boolean | string
-> Allows to serve an index of the directory.
-> Read more at https://github.com/webpack/webpack-dev-middleware#index
Details:
* options.index should be a boolean.
* options.index should be a string."
Expand All @@ -35,6 +40,7 @@ exports[`validation should throw an error on the "index" option with "0" value 1
- options.index should be one of these:
boolean | string
-> Allows to serve an index of the directory.
-> Read more at https://github.com/webpack/webpack-dev-middleware#index
Details:
* options.index should be a boolean.
* options.index should be a string."
Expand All @@ -44,35 +50,40 @@ exports[`validation should throw an error on the "methods" option with "{}" valu
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.methods should be an array:
[string, ...]
-> Allows to pass the list of HTTP request methods accepted by the middleware."
-> Allows to pass the list of HTTP request methods accepted by the middleware.
-> Read more at https://github.com/webpack/webpack-dev-middleware#methods"
`;

exports[`validation should throw an error on the "methods" option with "true" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.methods should be an array:
[string, ...]
-> Allows to pass the list of HTTP request methods accepted by the middleware."
-> Allows to pass the list of HTTP request methods accepted by the middleware.
-> Read more at https://github.com/webpack/webpack-dev-middleware#methods"
`;

exports[`validation should throw an error on the "mimeTypes" option with "foo" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.mimeTypes should be an object:
object { … }
-> Allows a user to register custom mime types or extension mappings."
-> Allows a user to register custom mime types or extension mappings.
-> Read more at https://github.com/webpack/webpack-dev-middleware#mimetypes"
`;

exports[`validation should throw an error on the "outputFileSystem" option with "false" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.outputFileSystem should be an object:
object { … }
-> Set the default file system which will be used by webpack as primary destination of generated files."
-> Set the default file system which will be used by webpack as primary destination of generated files.
-> Read more at https://github.com/webpack/webpack-dev-middleware#outputfilesystem"
`;

exports[`validation should throw an error on the "publicPath" option with "false" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.publicPath should be one of these:
\\"auto\\" | string | function
-> The \`publicPath\` specifies the public URL address of the output files when referenced in a browser.
-> Read more at https://github.com/webpack/webpack-dev-middleware#publicpath
Details:
* options.publicPath should be \\"auto\\".
* options.publicPath should be a string.
Expand All @@ -82,20 +93,23 @@ exports[`validation should throw an error on the "publicPath" option with "false
exports[`validation should throw an error on the "serverSideRender" option with "0" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.serverSideRender should be a boolean.
-> Instructs the module to enable or disable the server-side rendering mode."
-> Instructs the module to enable or disable the server-side rendering mode.
-> Read more at https://github.com/webpack/webpack-dev-middleware#serversiderender"
`;

exports[`validation should throw an error on the "serverSideRender" option with "foo" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.serverSideRender should be a boolean.
-> Instructs the module to enable or disable the server-side rendering mode."
-> Instructs the module to enable or disable the server-side rendering mode.
-> Read more at https://github.com/webpack/webpack-dev-middleware#serversiderender"
`;

exports[`validation should throw an error on the "stats" option with "0" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.stats should be one of these:
\\"none\\" | \\"summary\\" | \\"errors-only\\" | \\"errors-warnings\\" | \\"minimal\\" | \\"normal\\" | \\"detailed\\" | \\"verbose\\" | boolean | object { … }
-> Stats options object or preset name.
-> Read more at https://github.com/webpack/webpack-dev-middleware#stats
Details:
* options.stats should be one of these:
\\"none\\" | \\"summary\\" | \\"errors-only\\" | \\"errors-warnings\\" | \\"minimal\\" | \\"normal\\" | \\"detailed\\" | \\"verbose\\"
Expand All @@ -109,6 +123,7 @@ exports[`validation should throw an error on the "writeToDisk" option with "{}"
- options.writeToDisk should be one of these:
boolean | function
-> Allows to write generated files on disk.
-> Read more at https://github.com/webpack/webpack-dev-middleware#writetodisk
Details:
* options.writeToDisk should be a boolean.
* options.writeToDisk should be an instance of function."
Expand Down
27 changes: 21 additions & 6 deletions test/__snapshots__/validation-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`validation should throw an error on the "headers" option with "1" value
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.headers should be one of these:
object { … } | function
-> Allows to pass custom HTTP headers on each request
-> Read more at https://github.com/webpack/webpack-dev-middleware#headers
Details:
* options.headers should be an object:
object { … }
Expand All @@ -14,6 +16,8 @@ exports[`validation should throw an error on the "headers" option with "true" va
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.headers should be one of these:
object { … } | function
-> Allows to pass custom HTTP headers on each request
-> Read more at https://github.com/webpack/webpack-dev-middleware#headers
Details:
* options.headers should be an object:
object { … }
Expand All @@ -25,6 +29,7 @@ exports[`validation should throw an error on the "index" option with "{}" value
- options.index should be one of these:
boolean | string
-> Allows to serve an index of the directory.
-> Read more at https://github.com/webpack/webpack-dev-middleware#index
Details:
* options.index should be a boolean.
* options.index should be a string."
Expand All @@ -35,6 +40,7 @@ exports[`validation should throw an error on the "index" option with "0" value 1
- options.index should be one of these:
boolean | string
-> Allows to serve an index of the directory.
-> Read more at https://github.com/webpack/webpack-dev-middleware#index
Details:
* options.index should be a boolean.
* options.index should be a string."
Expand All @@ -44,35 +50,40 @@ exports[`validation should throw an error on the "methods" option with "{}" valu
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.methods should be an array:
[string, ...]
-> Allows to pass the list of HTTP request methods accepted by the middleware."
-> Allows to pass the list of HTTP request methods accepted by the middleware.
-> Read more at https://github.com/webpack/webpack-dev-middleware#methods"
`;

exports[`validation should throw an error on the "methods" option with "true" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.methods should be an array:
[string, ...]
-> Allows to pass the list of HTTP request methods accepted by the middleware."
-> Allows to pass the list of HTTP request methods accepted by the middleware.
-> Read more at https://github.com/webpack/webpack-dev-middleware#methods"
`;

exports[`validation should throw an error on the "mimeTypes" option with "foo" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.mimeTypes should be an object:
object { … }
-> Allows a user to register custom mime types or extension mappings."
-> Allows a user to register custom mime types or extension mappings.
-> Read more at https://github.com/webpack/webpack-dev-middleware#mimetypes"
`;

exports[`validation should throw an error on the "outputFileSystem" option with "false" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.outputFileSystem should be an object:
object { … }
-> Set the default file system which will be used by webpack as primary destination of generated files."
-> Set the default file system which will be used by webpack as primary destination of generated files.
-> Read more at https://github.com/webpack/webpack-dev-middleware#outputfilesystem"
`;

exports[`validation should throw an error on the "publicPath" option with "false" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.publicPath should be one of these:
\\"auto\\" | string | function
-> The \`publicPath\` specifies the public URL address of the output files when referenced in a browser.
-> Read more at https://github.com/webpack/webpack-dev-middleware#publicpath
Details:
* options.publicPath should be \\"auto\\".
* options.publicPath should be a string.
Expand All @@ -82,20 +93,23 @@ exports[`validation should throw an error on the "publicPath" option with "false
exports[`validation should throw an error on the "serverSideRender" option with "0" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.serverSideRender should be a boolean.
-> Instructs the module to enable or disable the server-side rendering mode."
-> Instructs the module to enable or disable the server-side rendering mode.
-> Read more at https://github.com/webpack/webpack-dev-middleware#serversiderender"
`;

exports[`validation should throw an error on the "serverSideRender" option with "foo" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.serverSideRender should be a boolean.
-> Instructs the module to enable or disable the server-side rendering mode."
-> Instructs the module to enable or disable the server-side rendering mode.
-> Read more at https://github.com/webpack/webpack-dev-middleware#serversiderender"
`;

exports[`validation should throw an error on the "stats" option with "0" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.stats should be one of these:
\\"none\\" | \\"summary\\" | \\"errors-only\\" | \\"errors-warnings\\" | \\"minimal\\" | \\"normal\\" | \\"detailed\\" | \\"verbose\\" | boolean | object { … }
-> Stats options object or preset name.
-> Read more at https://github.com/webpack/webpack-dev-middleware#stats
Details:
* options.stats should be one of these:
\\"none\\" | \\"summary\\" | \\"errors-only\\" | \\"errors-warnings\\" | \\"minimal\\" | \\"normal\\" | \\"detailed\\" | \\"verbose\\"
Expand All @@ -109,6 +123,7 @@ exports[`validation should throw an error on the "writeToDisk" option with "{}"
- options.writeToDisk should be one of these:
boolean | function
-> Allows to write generated files on disk.
-> Read more at https://github.com/webpack/webpack-dev-middleware#writetodisk
Details:
* options.writeToDisk should be a boolean.
* options.writeToDisk should be an instance of function."
Expand Down