-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Encapsulate sockjs, introduce ws and build base for users to make own server implementation #1904
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1904 +/- ##
==========================================
- Coverage 88% 86.77% -1.23%
==========================================
Files 16 20 +4
Lines 817 862 +45
Branches 260 265 +5
==========================================
+ Hits 719 748 +29
- Misses 84 99 +15
- Partials 14 15 +1
Continue to review full report at Codecov.
|
lib/Server.js
Outdated
@@ -32,6 +31,7 @@ const createDomain = require('./utils/createDomain'); | |||
const runBonjour = require('./utils/runBonjour'); | |||
const routes = require('./utils/routes'); | |||
const schema = require('./options.json'); | |||
const SockjsServer = require('./utils/server/sockjsServer'); | |||
|
|||
// Workaround for sockjs@~0.3.19 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move workaround to sockjsServer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean this workaround? https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
lib/Server.js
Outdated
|
||
socket.on('connection', (connection) => { | ||
socket.onConnection((connection) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use this.sockerServer
everywhere
lib/utils/server/sockjsServer.js
Outdated
onConnection(f) { | ||
this.socket.on('connection', f); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to lib/servers/sockjsServer.js
, it is not util
package.json
Outdated
@@ -62,6 +62,7 @@ | |||
"url": "^0.11.0", | |||
"webpack-dev-middleware": "^3.7.0", | |||
"webpack-log": "^2.0.0", | |||
"ws": "^6.2.1", | |||
"yargs": "12.0.5" | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need this right now, it is increase package size
lib/Server.js
Outdated
@@ -32,6 +31,7 @@ const createDomain = require('./utils/createDomain'); | |||
const runBonjour = require('./utils/runBonjour'); | |||
const routes = require('./utils/routes'); | |||
const schema = require('./options.json'); | |||
const SockjsServer = require('./utils/server/sockjsServer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename sockjsServer
to SockJSServer
because it is class
lib/Server.js
Outdated
error: this.log.error.bind(this), | ||
debug: this.log.debug.bind(this), | ||
server: this.listeningApp, | ||
path: this.sockPath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better always pass all options (this.options)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evilebottnawi Are you suggesting, in addition to what is already there, options: this.options
? Because this.listeningApp
is not part of the options, along with the error
, debug
callbacks.
Users may be creating server implementations of their own, so they would be interacting with the options passed in. Do you think it's a good idea to expose all the options to the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's a good idea to expose all the options to the user?
Yes, we because behavior can be changed based on options (not only) in theory.
Let's do it like:
new SockJSServer(this);
Custom implementation should have access to compiler, application, server, options and devServer.
Also it is not available for developers right now, so we can change this in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes, anyway good idea and good solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One note
/cc @hiroppy |
@@ -0,0 +1,64 @@ | |||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file name should be changed from sockjsServer.js
to SockJSServer
.
lib/servers/wsServer.js
Outdated
@@ -0,0 +1,8 @@ | |||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file name should be changed from wsServer.js
to WsServer
.
@@ -0,0 +1,5 @@ | |||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file name should be changed from baseServer.js
to BaseServer
.
lib/servers/wsServer.js
Outdated
|
||
// ws server implementation under construction | ||
// will need changes in the client as well to function | ||
module.exports = class WSServer extends BaseServer {}; | ||
module.exports = class WsServer extends BaseServer {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @hiroppy What do you think is better:
- WebsocketServer
- WSServer
- WsServer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like WebsocketServer. For example, the plugin name of wasm(WebAssemblyPlugin) which webpack has is not omitted. But this example is webpack, not webpack-dev-server. In any case, I think that it is easier to understand if it is not omitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 let's use WebsocketServer
/cc @Loonride
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, one questions
/cc @hiroppy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @hiroppy
@evilebottnawi, @hulkish says just to continue work in this pr, are you fine with that or do you want to get the base changes merged first? |
Please don't continue to work in this pr. Because don't give PR more than one content, as it will be difficult to review. |
I disagree, this is all part of the same gsoc effort. What things do u think deviate enough to be considered separate? |
@Loonride please add tests which validate support for |
We have |
If you want to need |
@hiroppy How about:
|
I like the idea of having |
@Loonride i think that may be beside the point - your code will be merged once stable (with tests) then, the |
I agree with this idea. I think it is a good idea to put them into one branch so that you can easily visualize the results. I like the idea of creating |
Should I add tests on the new files to pass codecov? |
For Bugs and Features; did you add new tests?
No
Motivation / Use-Case
Refactored to encapsulate
sockjs
better so that it is easier to implementws
or other user defined server implementations.Issue: #1860
Breaking Changes
I am unsure if moving
sockjs
out breaks this: https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L41Otherwise there should be no breaking changes.
Additional Info
Tests were failing locally, I think it is related to a snapshots though: #1889