Skip to content

fix: schema for the host option #3549

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
Jul 21, 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
9 changes: 8 additions & 1 deletion bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,17 @@ module.exports = {
host: {
configs: [
{
type: "string",
description: "Allows to specify a hostname to use.",
multiple: false,
path: "host",
type: "enum",
values: ["local-ip", "local-ipv4", "local-ipv6"],
},
{
description: "Allows to specify a hostname to use.",
multiple: false,
path: "host",
type: "string",
},
],
description: "Allows to specify a hostname to use.",
Expand Down
13 changes: 10 additions & 3 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,17 @@
"link": "https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback"
},
"Host": {
"type": "string",
"minLength": 1,
"description": "Allows to specify a hostname to use.",
"link": "https://webpack.js.org/configuration/dev-server/#devserverhost"
"link": "https://webpack.js.org/configuration/dev-server/#devserverhost",
"anyOf": [
{
"enum": ["local-ip", "local-ipv4", "local-ipv6"]
},
{
"type": "string",
"minLength": 1
}
]
Comment on lines +288 to +296
Copy link
Member

@snitin315 snitin315 Jul 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema-utils should respect parentSchema.link/description, if we don't have link/description for children.

},
"Hot": {
"anyOf": [
Expand Down
22 changes: 15 additions & 7 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,31 @@ exports[`options validate should throw an error on the "historyApiFallback" opti

exports[`options validate should throw an error on the "host" option with '' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.host should be a non-empty string.
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
- options.host should be a non-empty string."
`;
Comment on lines -261 to 262
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the link is not showing only happening with non-empty error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it should be fixed in schema-utils

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge it as is and update snapshots after fixing it in schema utils


exports[`options validate should throw an error on the "host" option with 'false' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.host should be a non-empty string.
- options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\"
* options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "host" option with 'null' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.host should be a non-empty string.
- options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\"
* options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "hot" option with '' value 1`] = `
Expand Down
22 changes: 15 additions & 7 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,31 @@ exports[`options validate should throw an error on the "historyApiFallback" opti

exports[`options validate should throw an error on the "host" option with '' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.host should be a non-empty string.
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
- options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "host" option with 'false' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.host should be a non-empty string.
- options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\"
* options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "host" option with 'null' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.host should be a non-empty string.
- options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\"
* options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "hot" option with '' value 1`] = `
Expand Down