Skip to content

Commit a669762

Browse files
committed
feat: bonjour options
1 parent 3fb7e0b commit a669762

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

lib/options.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,14 @@
140140
},
141141
"properties": {
142142
"bonjour": {
143-
"type": "boolean",
143+
"anyOf": [
144+
{
145+
"type": "boolean"
146+
},
147+
{
148+
"type": "object"
149+
}
150+
],
144151
"description": "Broadcasts the server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour"
145152
},
146153
"client": {

lib/utils/runBonjour.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
'use strict';
22

3-
function runBonjour({ port }) {
3+
function runBonjour(options) {
44
const bonjour = require('bonjour')();
55
const os = require('os');
6-
6+
const { https, port } = options;
77
bonjour.publish({
88
name: `Webpack Dev Server ${os.hostname()}:${port}`,
99
port,
10-
type: 'http',
10+
type: https ? 'https' : 'http',
1111
subtypes: ['webpack'],
12+
...(typeof options.bonjour === 'object' && options.bonjour),
1213
});
1314

1415
process.on('exit', () => {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
exports[`options validate should throw an error on the "bonjour" option with '' value 1`] = `
44
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
5-
- configuration.bonjour should be a boolean.
6-
-> Broadcasts the server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour"
5+
- configuration.bonjour should be one of these:
6+
boolean | object { … }
7+
-> Broadcasts the server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour
8+
Details:
9+
* configuration.bonjour should be a boolean.
10+
* configuration.bonjour should be an object:
11+
object { … }"
712
`;
813

914
exports[`options validate should throw an error on the "client" option with '{"host":true,"path":"","port":8080}' value 1`] = `

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
exports[`options validate should throw an error on the "bonjour" option with '' value 1`] = `
44
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
5-
- configuration.bonjour should be a boolean.
6-
-> Broadcasts the server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour"
5+
- configuration.bonjour should be one of these:
6+
boolean | object { … }
7+
-> Broadcasts the server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour
8+
Details:
9+
* configuration.bonjour should be a boolean.
10+
* configuration.bonjour should be an object:
11+
object { … }"
712
`;
813

914
exports[`options validate should throw an error on the "client" option with '{"host":true,"path":"","port":8080}' value 1`] = `

test/validate-options.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const tests = {
2323
failure: [false],
2424
},
2525
bonjour: {
26-
success: [false, true],
26+
success: [false, true, { type: 'https' }],
2727
failure: [''],
2828
},
2929
client: {

0 commit comments

Comments
 (0)