Skip to content

Commit

Permalink
chore(client): rename clientOptions to client (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev authored Jun 24, 2020
1 parent e4761bf commit eb9c58d
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 103 deletions.
8 changes: 2 additions & 6 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,8 @@ class Server {
}
});

if (this.options.clientOptions.logging) {
this.sockWrite(
[connection],
'logging',
this.options.clientOptions.logging
);
if (this.options.client.logging) {
this.sockWrite([connection], 'logging', this.options.client.logging);
}

if (this.options.hot === true || this.options.hot === 'only') {
Expand Down
4 changes: 2 additions & 2 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"bonjour": {
"type": "boolean"
},
"clientOptions": {
"client": {
"type": "object",
"properties": {
"host": {
Expand Down Expand Up @@ -390,7 +390,7 @@
"properties": {
"allowedHosts": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserverallowedhosts)",
"bonjour": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverbonjour)",
"clientOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverclientoptions)",
"client": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverclient)",
"compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservercompress)",
"contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)",
"disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)",
Expand Down
2 changes: 1 addition & 1 deletion lib/servers/SockJSServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = class SockJSServer extends BaseServer {
});

this.socket.installHandlers(this.server.listeningApp, {
prefix: this.server.options.clientOptions.path,
prefix: this.server.options.client.path,
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/servers/WebsocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = class WebsocketServer extends BaseServer {

this.wsServer = new ws.Server({
noServer: true,
path: this.server.options.clientOptions.path,
path: this.server.options.client.path,
});

this.server.listeningApp.on('upgrade', (req, sock, head) => {
Expand Down
16 changes: 4 additions & 12 deletions lib/utils/addEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,16 @@ function addEntries(config, options, server) {
const domain = createDomain(options, app);
/** @type {string} */
const host =
options.clientOptions && options.clientOptions.host
? `&host=${options.clientOptions.host}`
: '';
options.client && options.client.host ? `&host=${options.client.host}` : '';
/** @type {string} */
let path = '';
// only add the path if it is not default
if (
options.clientOptions &&
options.clientOptions.path &&
options.clientOptions.path !== '/ws'
) {
path = `&path=${options.clientOptions.path}`;
if (options.client && options.client.path && options.client.path !== '/ws') {
path = `&path=${options.client.path}`;
}
/** @type {string} */
const port =
options.clientOptions && options.clientOptions.port
? `&port=${options.clientOptions.port}`
: '';
options.client && options.client.port ? `&port=${options.client.port}` : '';
/** @type {string} */
const clientEntry = `${require.resolve(
'../../client/default/'
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ function createConfig(config, argv, { port }) {
}

if (argv.clientLogging) {
if (options.clientOptions) {
options.clientOptions.logging = argv.clientLogging;
if (options.client) {
options.client.logging = argv.clientLogging;
} else {
options.clientOptions = {
options.client = {
logging: argv.clientLogging,
};
}
Expand Down
10 changes: 4 additions & 6 deletions lib/utils/normalizeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ function normalizeOptions(compiler, options) {
}
}

if (!options.clientOptions) {
options.clientOptions = {};
if (!options.client) {
options.client = {};
}

options.clientOptions.path = `/${
options.clientOptions.path
? options.clientOptions.path.replace(/^\/|\/$/g, '')
: 'ws'
options.client.path = `/${
options.client.path ? options.client.path.replace(/^\/|\/$/g, '') : 'ws'
}`;
}

Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/Validation.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ exports[`Validation validation should fail validation for invalid \`writeToDisk\
exports[`Validation validation should fail validation for no additional properties 1`] = `
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration has an unknown property 'additional'. These properties are valid:
object { allowedHosts?, bonjour?, clientOptions?, compress?, contentBasePublicPath?, contentBase?, disableHostCheck?, fs?, headers?, historyApiFallback?, host?, hot?, http2?, https?, index?, injectClient?, injectHot?, liveReload?, mimeTypes?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, openPage?, overlay?, port?, profile?, progress?, proxy?, public?, publicPath?, requestCert?, serveIndex?, serverSideRender?, socket?, staticOptions?, stats?, transportMode?, useLocalIp?, watchContentBase?, watchOptions?, writeToDisk? }"
object { allowedHosts?, bonjour?, client?, compress?, contentBasePublicPath?, contentBase?, disableHostCheck?, fs?, headers?, historyApiFallback?, host?, hot?, http2?, https?, index?, injectClient?, injectHot?, liveReload?, mimeTypes?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, openPage?, overlay?, port?, profile?, progress?, proxy?, public?, publicPath?, requestCert?, serveIndex?, serverSideRender?, socket?, staticOptions?, stats?, transportMode?, useLocalIp?, watchContentBase?, watchOptions?, writeToDisk? }"
`;
12 changes: 6 additions & 6 deletions test/e2e/ClientOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('sockjs public and client path', () => {
poll: true,
},
public: 'myhost.test',
clientOptions: {
client: {
path: '/foo/test/bar/',
},
};
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('sockjs client path and port', () => {
watchOptions: {
poll: true,
},
clientOptions: {
client: {
path: '/foo/test/bar/',
port: port3,
},
Expand Down Expand Up @@ -249,7 +249,7 @@ describe('sockjs client port, no path', () => {
watchOptions: {
poll: true,
},
clientOptions: {
client: {
port: port3,
},
};
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('sockjs client host', () => {
watchOptions: {
poll: true,
},
clientOptions: {
client: {
host: 'myhost.test',
},
};
Expand Down Expand Up @@ -327,7 +327,7 @@ describe('ws client host, port, and path', () => {
watchOptions: {
poll: true,
},
clientOptions: {
client: {
host: 'myhost',
port: port3,
path: '/foo/test/bar/',
Expand Down Expand Up @@ -407,7 +407,7 @@ describe('Client console.log', () => {
{
title: 'client logging is none',
options: {
clientOptions: {
client: {
logging: 'none',
},
},
Expand Down
36 changes: 18 additions & 18 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,73 +130,73 @@ describe('options', () => {
success: [false],
failure: [''],
},
clientOptions: {
client: {
success: [
{
clientOptions: {},
client: {},
},
{
clientOptions: {
client: {
host: '',
},
},
{
clientOptions: {
client: {
path: '',
},
},
{
clientOptions: {
client: {
port: '',
},
},
{
clientOptions: {
client: {
logging: 'none',
},
},
{
clientOptions: {
client: {
logging: 'error',
},
},
{
clientOptions: {
client: {
logging: 'warn',
},
},
{
clientOptions: {
client: {
logging: 'info',
},
},
{
clientOptions: {
client: {
logging: 'log',
},
},
{
clientOptions: {
client: {
logging: 'verbose',
},
},
{
clientOptions: {
client: {
host: '',
path: '',
port: 8080,
logging: 'none',
},
},
{
clientOptions: {
client: {
host: '',
path: '',
port: '',
},
},
{
clientOptions: {
client: {
host: '',
path: '',
port: null,
Expand All @@ -206,24 +206,24 @@ describe('options', () => {
failure: [
'whoops!',
{
clientOptions: {
client: {
unknownOption: true,
},
},
{
clientOptions: {
client: {
host: true,
path: '',
port: 8080,
},
},
{
clientOptions: {
client: {
logging: 'whoops!',
},
},
{
clientOptions: {
client: {
logging: 'silent',
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/ports-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const portsList = {
'port-option': 1,
'proxy-option': 4,
'transportMode-option': 1,
'clientOptions-option': 1,
'client-option': 1,
'stats-option': 1,
ProvidePlugin: 1,
WebsocketClient: 1,
Expand Down
10 changes: 5 additions & 5 deletions test/server/clientOptions-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const request = require('supertest');
const config = require('../fixtures/simple-config/webpack.config');
const testServer = require('../helpers/test-server');
const port = require('../ports-map')['clientOptions-option'];
const port = require('../ports-map')['client-option'];

describe('clientOptions option', () => {
describe('client option', () => {
let server;
let req;

Expand All @@ -30,7 +30,7 @@ describe('clientOptions option', () => {

it('defaults to a path', () => {
expect(
server.options.clientOptions.path.match(/\/[a-z0-9\-/]+[^/]$/)
server.options.client.path.match(/\/[a-z0-9\-/]+[^/]$/)
).toBeTruthy();
});

Expand All @@ -47,7 +47,7 @@ describe('clientOptions option', () => {
config,
{
transportMode: 'sockjs',
clientOptions: {
client: {
path: '/foo/test/bar/',
},
port,
Expand All @@ -58,7 +58,7 @@ describe('clientOptions option', () => {
});

it('sets the sock path correctly and strips leading and trailing /s', () => {
expect(server.options.clientOptions.path).toEqual(path);
expect(server.options.client.path).toEqual(path);
});

it('responds with a 200 second', (done) => {
Expand Down
2 changes: 1 addition & 1 deletion test/server/servers/SockJSServer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('SockJSServer', () => {
debug: () => {},
},
options: {
clientOptions: {
client: {
path: '/ws',
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/server/servers/WebsocketServer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('WebsocketServer', () => {
listeningApp.listen(port, 'localhost', () => {
server = {
options: {
clientOptions: {
client: {
path: '/ws-server',
},
},
Expand Down
4 changes: 2 additions & 2 deletions test/server/transportMode-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe('transportMode', () => {
});

this.socket.installHandlers(this.server.listeningApp, {
prefix: this.server.options.clientOptions.path,
prefix: this.server.options.client.path,
});
}

Expand Down Expand Up @@ -378,7 +378,7 @@ describe('transportMode', () => {
});

this.socket.installHandlers(this.server.listeningApp, {
prefix: this.server.options.clientOptions.path,
prefix: this.server.options.client.path,
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/server/utils/__snapshots__/createConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Object {

exports[`createConfig clientLogging option 1`] = `
Object {
"clientOptions": Object {
"client": Object {
"logging": "none",
},
"hot": true,
Expand All @@ -90,7 +90,7 @@ Object {

exports[`createConfig clientLogging option overrides devServer config 1`] = `
Object {
"clientOptions": Object {
"client": Object {
"logging": "none",
},
"hot": true,
Expand Down
Loading

0 comments on commit eb9c58d

Please sign in to comment.