-
-
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
feat(server): add serverMode option #1937
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1937 +/- ##
=========================================
- Coverage 91.8% 91.8% -0.01%
=========================================
Files 22 23 +1
Lines 879 903 +24
Branches 276 283 +7
=========================================
+ Hits 807 829 +22
- Misses 69 71 +2
Partials 3 3
Continue to review full report at Codecov.
|
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.
Good job, need some fixes
lib/Server.js
Outdated
'via require.resolve(...), or the class itself which extends BaseServer' | ||
); | ||
} | ||
this.ServerImplementation = ServerImplementation; |
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 util
getSocketServerImplementation
- Don't think we need
function
- Let's rewrite this on
switch
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 function
option is good if the user wants to supply an implementation, but their file is exporting multiple things, for example. So like if they want to do:
serverMode: require('./my-implementation').Server
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 think better use require.resolve('./my-implementation/Server')
/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.
I'm fine either way:) Currently, it was fixed as require.resolve
.
test/options.test.js
Outdated
@@ -340,6 +341,15 @@ describe('options', () => { | |||
success: [true], | |||
failure: [''], | |||
}, | |||
serverMode: { | |||
success: [ | |||
'', |
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.
'' should be failure
config, | ||
{ | ||
sockPath: '/foo/test/bar/', | ||
serverMode: class MySockJSServer 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.
@evilebottnawi being able to pass in class also makes testing easier
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.
Good job, wait @hiroppy review
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.
LGTM with nits. And need to create documentation to webpack.js.org repo.
|
||
if (!serverImplFound) { | ||
throw new Error( | ||
"serverMode must be a string denoting a default implementation (eg. 'sockjs'), a full path to " + |
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.
nit
- eg
+ e.g.
lib/Server.js
Outdated
); | ||
} | ||
|
||
this.ServerImplementation = getSocketServerImplementation(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.
I think we should rename variable to this.socketServerImplementation
to avoid misleading, we already store value in this.socketServer
so let's use socket
prefix too
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'm going to capitalize first letter to clarify that it is a class.
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 too
lib/Server.js
Outdated
} | ||
|
||
// this.SocketServerImplementation is a class, so it must be instantiated before use | ||
this.SocketServerImplementation = getSocketServerImplementation( |
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.
this.SocketServerImplementation
-> this.socketServerImplementation
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.
nit pick 😄
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
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.
💯
For Bugs and Features; did you add new tests?
Yes
Motivation / Use-Case
The goal of this option is to allow the user to choose the current server implementation, or provide their own implementation as a path/class.
It is a GSoC Refactor goal: #1860
Breaking Changes
None
Additional Info