Skip to content

Commit

Permalink
feat: bonjour options
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Apr 19, 2021
1 parent 3fb7e0b commit a669762
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
9 changes: 8 additions & 1 deletion lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@
},
"properties": {
"bonjour": {
"type": "boolean",
"anyOf": [
{
"type": "boolean"
},
{
"type": "object"
}
],
"description": "Broadcasts the server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour"
},
"client": {
Expand Down
7 changes: 4 additions & 3 deletions lib/utils/runBonjour.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

function runBonjour({ port }) {
function runBonjour(options) {
const bonjour = require('bonjour')();
const os = require('os');

const { https, port } = options;
bonjour.publish({
name: `Webpack Dev Server ${os.hostname()}:${port}`,
port,
type: 'http',
type: https ? 'https' : 'http',
subtypes: ['webpack'],
...(typeof options.bonjour === 'object' && options.bonjour),
});

process.on('exit', () => {
Expand Down
9 changes: 7 additions & 2 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

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

exports[`options validate should throw an error on the "client" option with '{"host":true,"path":"","port":8080}' value 1`] = `
Expand Down
9 changes: 7 additions & 2 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

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

exports[`options validate should throw an error on the "client" option with '{"host":true,"path":"","port":8080}' value 1`] = `
Expand Down
2 changes: 1 addition & 1 deletion test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const tests = {
failure: [false],
},
bonjour: {
success: [false, true],
success: [false, true, { type: 'https' }],
failure: [''],
},
client: {
Expand Down

0 comments on commit a669762

Please sign in to comment.